Matrix library.
This commit is contained in:
4
API.md
4
API.md
@@ -7710,7 +7710,7 @@ Get z-rotation matrix (angle in radians)
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
> result = RL.MatrixRotateXYZ( Vector3 angle )
|
> result = RL.MatrixRotateXYZ( Vector3 angles )
|
||||||
|
|
||||||
Get xyz-rotation matrix (angles in radians)
|
Get xyz-rotation matrix (angles in radians)
|
||||||
|
|
||||||
@@ -7718,7 +7718,7 @@ Get xyz-rotation matrix (angles in radians)
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
> result = RL.MatrixRotateZYX( Vector3 angle )
|
> result = RL.MatrixRotateZYX( Vector3 angles )
|
||||||
|
|
||||||
Get zyx-rotation matrix (angles in radians)
|
Get zyx-rotation matrix (angles in radians)
|
||||||
|
|
||||||
|
|||||||
@@ -4958,15 +4958,15 @@ function RL.MatrixRotateZ( angle ) end
|
|||||||
|
|
||||||
---Get xyz-rotation matrix (angles in radians)
|
---Get xyz-rotation matrix (angles in radians)
|
||||||
---- Success return Matrix
|
---- Success return Matrix
|
||||||
---@param angle table
|
---@param angles table
|
||||||
---@return any result
|
---@return any result
|
||||||
function RL.MatrixRotateXYZ( angle ) end
|
function RL.MatrixRotateXYZ( angles ) end
|
||||||
|
|
||||||
---Get zyx-rotation matrix (angles in radians)
|
---Get zyx-rotation matrix (angles in radians)
|
||||||
---- Success return Matrix
|
---- Success return Matrix
|
||||||
---@param angle table
|
---@param angles table
|
||||||
---@return any result
|
---@return any result
|
||||||
function RL.MatrixRotateZYX( angle ) end
|
function RL.MatrixRotateZYX( angles ) end
|
||||||
|
|
||||||
---Get scaling matrix
|
---Get scaling matrix
|
||||||
---- Success return Matrix
|
---- Success return Matrix
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ KEY CHANGES:
|
|||||||
- CHANGED: DrawText is now DrawTextEx like in Raylib.
|
- CHANGED: DrawText is now DrawTextEx like in Raylib.
|
||||||
- ADDED: Global variable descriptions for API.
|
- ADDED: Global variable descriptions for API.
|
||||||
- CHANGED: Organized functions by putting them in the same order as in Raylib.
|
- CHANGED: Organized functions by putting them in the same order as in Raylib.
|
||||||
|
- ADDED: Matrix library.
|
||||||
|
|
||||||
DETAILED CHANGES:
|
DETAILED CHANGES:
|
||||||
- CHANGED: GenImageColor now takes Vector2 as size.
|
- CHANGED: GenImageColor now takes Vector2 as size.
|
||||||
|
|||||||
3
devnotes
3
devnotes
@@ -15,6 +15,9 @@ Backlog {
|
|||||||
* More Textures management functions.
|
* More Textures management functions.
|
||||||
* Shader buffer storage object management (ssbo).
|
* Shader buffer storage object management (ssbo).
|
||||||
|
|
||||||
|
* Matrix class.
|
||||||
|
* Quaternion class.
|
||||||
|
|
||||||
* Examples
|
* Examples
|
||||||
* Improve Dungeon crawler example by generating custom mesh instead of drawing 3D quads.
|
* Improve Dungeon crawler example by generating custom mesh instead of drawing 3D quads.
|
||||||
* Platformer example physics process for true framerate independence.
|
* Platformer example physics process for true framerate independence.
|
||||||
|
|||||||
151
examples/resources/lib/matrix.lua
Normal file
151
examples/resources/lib/matrix.lua
Normal file
@@ -0,0 +1,151 @@
|
|||||||
|
-- For luaJit compatibility.
|
||||||
|
if table.unpack == nil then
|
||||||
|
table.unpack = unpack
|
||||||
|
end
|
||||||
|
|
||||||
|
local function deepCopy( orig )
|
||||||
|
local copy
|
||||||
|
|
||||||
|
if type( orig ) == "table" then
|
||||||
|
copy = {}
|
||||||
|
|
||||||
|
for origKey, origValue in next, orig, nil do
|
||||||
|
-- If object has clone method, use that.
|
||||||
|
copy[ deepCopy( origKey ) ] = deepCopy( origValue )
|
||||||
|
end
|
||||||
|
|
||||||
|
-- setmetatable( copy, utillib.deepCopy( getmetatable( orig ) ) )
|
||||||
|
else -- number, string, boolean, etc.
|
||||||
|
copy = orig
|
||||||
|
end
|
||||||
|
|
||||||
|
return copy
|
||||||
|
end
|
||||||
|
|
||||||
|
Matrix = {}
|
||||||
|
Matrix.meta = {
|
||||||
|
__index = Matrix,
|
||||||
|
__tostring = function( m )
|
||||||
|
return "{\n"
|
||||||
|
.." { "..m.m[1][1]..", "..m.m[1][2]..", "..m.m[1][3]..", "..m.m[1][4].." },\n"
|
||||||
|
.." { "..m.m[2][1]..", "..m.m[2][2]..", "..m.m[2][3]..", "..m.m[2][4].." },\n"
|
||||||
|
.." { "..m.m[3][1]..", "..m.m[3][2]..", "..m.m[3][3]..", "..m.m[3][4].." },\n"
|
||||||
|
.." { "..m.m[3][1]..", "..m.m[3][2]..", "..m.m[3][3]..", "..m.m[3][4].." },\n"
|
||||||
|
.."}"
|
||||||
|
end,
|
||||||
|
__add = function( m1, m2 )
|
||||||
|
return Matrix:new( RL.MatrixAdd( m1, m2 ) )
|
||||||
|
end,
|
||||||
|
__sub = function( m1, m2 )
|
||||||
|
return Matrix:new( RL.MatrixSubtract( m1, m2 ) )
|
||||||
|
end,
|
||||||
|
__mul = function( m1, m2 )
|
||||||
|
return Matrix:new( RL.MatrixMultiply( m1, m2 ) )
|
||||||
|
end
|
||||||
|
}
|
||||||
|
|
||||||
|
function Matrix:new( m )
|
||||||
|
local object = setmetatable( {}, Matrix.meta )
|
||||||
|
|
||||||
|
if type( m ) == "table" then
|
||||||
|
object.m = deepCopy( m )
|
||||||
|
else
|
||||||
|
object.m = RL.MatrixIdentity()
|
||||||
|
end
|
||||||
|
|
||||||
|
return object
|
||||||
|
end
|
||||||
|
|
||||||
|
function Matrix:set( m )
|
||||||
|
if type( m ) == "table" then
|
||||||
|
self.m = deepCopy( m )
|
||||||
|
else
|
||||||
|
self.m = RL.MatrixIdentity()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- function Matrix:arr()
|
||||||
|
-- return self.m
|
||||||
|
-- end
|
||||||
|
|
||||||
|
-- function Matrix:unpack()
|
||||||
|
-- return self.m
|
||||||
|
-- end
|
||||||
|
|
||||||
|
function Matrix:clone()
|
||||||
|
return Matrix:new( self )
|
||||||
|
end
|
||||||
|
|
||||||
|
function Matrix:determinant()
|
||||||
|
return RL.MatrixDeterminant( self )
|
||||||
|
end
|
||||||
|
|
||||||
|
function Matrix:trace()
|
||||||
|
return RL.MatrixTranspose( self )
|
||||||
|
end
|
||||||
|
|
||||||
|
function Matrix:transpose()
|
||||||
|
return Matrix:new( RL.MatrixTranspose( self ) )
|
||||||
|
end
|
||||||
|
|
||||||
|
function Matrix:multiply( m2 )
|
||||||
|
return Matrix:new( RL.MatrixMultiply( self, m2 ) )
|
||||||
|
end
|
||||||
|
|
||||||
|
function Matrix:invert()
|
||||||
|
return Matrix:new( RL.MatrixInvert( self ) )
|
||||||
|
end
|
||||||
|
|
||||||
|
function Matrix:identity()
|
||||||
|
return Matrix:new( RL.MatrixIdentity() )
|
||||||
|
end
|
||||||
|
|
||||||
|
function Matrix:translate( translate )
|
||||||
|
return Matrix:new( RL.MatrixTranslate( translate ) )
|
||||||
|
end
|
||||||
|
|
||||||
|
function Matrix:rotate( axis, angle )
|
||||||
|
return Matrix:new( RL.MatrixRotate( axis, angle ) )
|
||||||
|
end
|
||||||
|
|
||||||
|
function Matrix:rotateX( angle )
|
||||||
|
return Matrix:new( RL.MatrixRotateX( angle ) )
|
||||||
|
end
|
||||||
|
|
||||||
|
function Matrix:rotateY( angle )
|
||||||
|
return Matrix:new( RL.MatrixRotateY( angle ) )
|
||||||
|
end
|
||||||
|
|
||||||
|
function Matrix:rotateZ( angle )
|
||||||
|
return Matrix:new( RL.MatrixRotateZ( angle ) )
|
||||||
|
end
|
||||||
|
|
||||||
|
function Matrix:rotateXYZ( angles )
|
||||||
|
return Matrix:new( RL.MatrixRotateXYZ( angles ) )
|
||||||
|
end
|
||||||
|
|
||||||
|
function Matrix:rotateZYX( angles )
|
||||||
|
return Matrix:new( RL.MatrixRotateZYX( angles ) )
|
||||||
|
end
|
||||||
|
|
||||||
|
function Matrix:scale( scale )
|
||||||
|
return Matrix:new( RL.MatrixScale( scale ) )
|
||||||
|
end
|
||||||
|
|
||||||
|
function Matrix:frustrum( left, right, bottom, top, near, far )
|
||||||
|
return Matrix:new( RL.MatrixFrustum( left, right, bottom, top, near, far ) )
|
||||||
|
end
|
||||||
|
|
||||||
|
function Matrix:perspective( fovy, aspect, near, far )
|
||||||
|
return Matrix:new( RL.MatrixPerspective( fovy, aspect, near, far ) )
|
||||||
|
end
|
||||||
|
|
||||||
|
function Matrix:ortho( left, right, bottom, top, near, far )
|
||||||
|
return Matrix:new( RL.MatrixOrtho( left, right, bottom, top, near, far ) )
|
||||||
|
end
|
||||||
|
|
||||||
|
function Matrix:lookAt( eye, target, up )
|
||||||
|
return Matrix:new( RL.MatrixLookAt( eye, target, up ) )
|
||||||
|
end
|
||||||
|
|
||||||
|
return Matrix
|
||||||
@@ -2693,6 +2693,19 @@ Matrix uluaGetMatrix( lua_State *L, int index ) {
|
|||||||
if ( lua_isnumber( L, -1 ) ) {
|
if ( lua_isnumber( L, -1 ) ) {
|
||||||
m[i][j] = lua_tonumber( L, -1 );
|
m[i][j] = lua_tonumber( L, -1 );
|
||||||
}
|
}
|
||||||
|
/* Look for one depth further if Matrix given as class. */
|
||||||
|
else if ( lua_istable( L, -1 ) ) {
|
||||||
|
int t3 = lua_gettop( L ), k = 0;
|
||||||
|
lua_pushnil( L );
|
||||||
|
|
||||||
|
while ( lua_next( L, t3 ) != 0 ) {
|
||||||
|
if ( lua_isnumber( L, -1 ) ) {
|
||||||
|
m[j][k] = lua_tonumber( L, -1 );
|
||||||
|
}
|
||||||
|
k++;
|
||||||
|
lua_pop( L, 1 );
|
||||||
|
}
|
||||||
|
}
|
||||||
j++;
|
j++;
|
||||||
lua_pop( L, 1 );
|
lua_pop( L, 1 );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1308,7 +1308,7 @@ int lmathMatrixRotateZ( lua_State *L ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
> result = RL.MatrixRotateXYZ( Vector3 angle )
|
> result = RL.MatrixRotateXYZ( Vector3 angles )
|
||||||
|
|
||||||
Get xyz-rotation matrix (angles in radians)
|
Get xyz-rotation matrix (angles in radians)
|
||||||
|
|
||||||
@@ -1323,7 +1323,7 @@ int lmathMatrixRotateXYZ( lua_State *L ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
> result = RL.MatrixRotateZYX( Vector3 angle )
|
> result = RL.MatrixRotateZYX( Vector3 angles )
|
||||||
|
|
||||||
Get zyx-rotation matrix (angles in radians)
|
Get zyx-rotation matrix (angles in radians)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user