diff options
| -rw-r--r-- | API.md | 33 | ||||
| -rw-r--r-- | ReiLua_API.lua | 30 | ||||
| -rw-r--r-- | changelog | 2 | ||||
| -rw-r--r-- | devnotes | 1 | ||||
| -rw-r--r-- | examples/platformer/main.lua | 2 | ||||
| -rw-r--r-- | include/lrlgl.h | 2 | ||||
| -rw-r--r-- | include/models.h | 3 | ||||
| -rw-r--r-- | src/lua_core.c | 9 | ||||
| -rw-r--r-- | src/models.c | 136 | ||||
| -rw-r--r-- | src/rlgl.c | 17 |
10 files changed, 233 insertions, 2 deletions
@@ -921,6 +921,18 @@ LIGHT_DIRECTIONAL LIGHT_POINT +## Globals - rlGlVersion + +RL_OPENGL_11 + +RL_OPENGL_21 + +RL_OPENGL_33 + +RL_OPENGL_43 + +RL_OPENGL_ES_20 + ## Globals - OpenGL GL_COLOR_BUFFER_BIT @@ -4446,6 +4458,15 @@ Draw a billboard texture defined by source --- +> success = RL.DrawBillboardPro( Camera camera, Texture2D texture, Rectangle source, Vector3 position, Vector3 up, Vector2 size, Vector2 origin, float rotation, Color tint ) + +Draw a billboard texture defined by source and rotation + +- Failure return false +- Success return true + +--- + > success = RL.SetModelTransform( Model model, Matrix transform ) Set model transform matrix @@ -6460,6 +6481,18 @@ Get the line drawing width --- +## RLGL - Initialization functions + +--- + +> version = RL.rlGetVersion() + +Get current OpenGL version + +- Success return int + +--- + ## OpenGL - Framebuffer management --- diff --git a/ReiLua_API.lua b/ReiLua_API.lua index 285a9b6..a0b3dd0 100644 --- a/ReiLua_API.lua +++ b/ReiLua_API.lua @@ -543,6 +543,14 @@ RL.HUEBAR_SELECTOR_OVERFLOW=20 RL.LIGHT_DIRECTIONAL=0 RL.LIGHT_POINT=1 +-- Globals - rlGlVersion + +RL.RL_OPENGL_11=1 +RL.RL_OPENGL_21=2 +RL.RL_OPENGL_33=3 +RL.RL_OPENGL_43=4 +RL.RL_OPENGL_ES_20=5 + -- Globals - OpenGL RL.GL_COLOR_BUFFER_BIT=16384 @@ -3481,6 +3489,21 @@ function RL.DrawBillboard( camera, texture, position, size, tint ) end ---@return any success function RL.DrawBillboardRec( camera, texture, source, position, size, tint ) end +---Draw a billboard texture defined by source and rotation +---- Failure return false +---- Success return true +---@param camera any +---@param texture any +---@param source table +---@param position table +---@param up table +---@param size table +---@param origin table +---@param rotation number +---@param tint table +---@return any success +function RL.DrawBillboardPro( camera, texture, source, position, up, size, origin, rotation, tint ) end + ---Set model transform matrix ---- Failure return false ---- Success return true @@ -5275,6 +5298,13 @@ function RL.rlSetLineWidth( width ) end ---@return any width function RL.rlGetLineWidth() end +-- RLGL - Initialization functions + +---Get current OpenGL version +---- Success return int +---@return any version +function RL.rlGetVersion() end + -- OpenGL - Framebuffer management ---Copy a block of pixels from one framebuffer object to another. @@ -68,6 +68,8 @@ Detailed changes: - FIXED: uluaGetBoundingBoxIndex was looking for numbers instead of tables. - ADDED: IsTextureReady - FIXED: UnloadTexture did not set texture id to NULL. + - ADDED: DrawBillboardPro + - ADDED: rlglGetVersion ------------------------------------------------------------------------ Release: ReiLua version 0.4.0 Using Raylib 4.2 @@ -23,6 +23,7 @@ Backlog { * ImageBlurGaussian * Models * LoadMaterials + * DrawBillboardPro * Needs Testing * UpdateTexture * UpdateTextureRec diff --git a/examples/platformer/main.lua b/examples/platformer/main.lua index fe594ec..26dc0ee 100644 --- a/examples/platformer/main.lua +++ b/examples/platformer/main.lua @@ -259,7 +259,7 @@ local function drawPlayer() end player.curFrame = frame - end + end else if 0 < player.vel.y then player.curFrame = 6 diff --git a/include/lrlgl.h b/include/lrlgl.h index 4394f00..c307302 100644 --- a/include/lrlgl.h +++ b/include/lrlgl.h @@ -3,3 +3,5 @@ /* General render state. */ int lrlglSetLineWidth( lua_State *L ); int lrlglGetLineWidth( lua_State *L ); +/* Initialization functions */ +int lrlglGetVersion( lua_State *L );
\ No newline at end of file diff --git a/include/models.h b/include/models.h index b36d4ce..d8e3b14 100644 --- a/include/models.h +++ b/include/models.h @@ -3,6 +3,8 @@ /* Internals. */ /* Deleted from raylib. Need for freeing models. */ void UnloadModelKeepMeshes( Model model ); +void DrawBillboardProNoRatio( Camera camera, Texture2D texture, Rectangle source, Vector3 position, Vector3 up, Vector2 size, Vector2 origin, float rotation, Color tint ); +void DrawBillboardRecNoRatio( Camera camera, Texture2D texture, Rectangle source, Vector3 position, Vector2 size, Color tint ); /* Basic. */ int lmodelsDrawLine3D( lua_State *L ); @@ -61,6 +63,7 @@ int lmodelsSetModelMaterial( lua_State *L ); int lmodelsSetModelMeshMaterial( lua_State *L ); int lmodelsDrawBillboard( lua_State *L ); int lmodelsDrawBillboardRec( lua_State *L ); +int lmodelsDrawBillboardPro( lua_State *L ); int lmodelsSetModelTransform( lua_State *L ); int lmodelsGetModelTransform( lua_State *L ); /* Animations. */ diff --git a/src/lua_core.c b/src/lua_core.c index a718de5..1caf1c7 100644 --- a/src/lua_core.c +++ b/src/lua_core.c @@ -492,6 +492,12 @@ void defineGlobals() { /* LightType */ assignGlobalInt( LIGHT_DIRECTIONAL, "LIGHT_DIRECTIONAL" ); assignGlobalInt( LIGHT_POINT, "LIGHT_POINT" ); + /* rlGlVersion */ + assignGlobalInt( RL_OPENGL_11, "RL_OPENGL_11" ); + assignGlobalInt( RL_OPENGL_21, "RL_OPENGL_21" ); + assignGlobalInt( RL_OPENGL_33, "RL_OPENGL_33" ); + assignGlobalInt( RL_OPENGL_43, "RL_OPENGL_43" ); + assignGlobalInt( RL_OPENGL_ES_20, "RL_OPENGL_ES_20" ); /* OpenGL */ assignGlobalInt( GL_COLOR_BUFFER_BIT, "GL_COLOR_BUFFER_BIT" ); assignGlobalInt( GL_DEPTH_BUFFER_BIT, "GL_DEPTH_BUFFER_BIT" ); @@ -1089,6 +1095,7 @@ void luaRegister() { assingGlobalFunction( "SetModelMeshMaterial", lmodelsSetModelMeshMaterial ); assingGlobalFunction( "DrawBillboard", lmodelsDrawBillboard ); assingGlobalFunction( "DrawBillboardRec", lmodelsDrawBillboardRec ); + assingGlobalFunction( "DrawBillboardPro", lmodelsDrawBillboardPro ); assingGlobalFunction( "SetModelTransform", lmodelsSetModelTransform ); assingGlobalFunction( "GetModelTransform", lmodelsGetModelTransform ); /* Animations. */ @@ -1350,6 +1357,8 @@ void luaRegister() { /* General render state. */ assingGlobalFunction( "rlglSetLineWidth", lrlglSetLineWidth ); assingGlobalFunction( "rlglGetLineWidth", lrlglGetLineWidth ); + /* Initialization functions. */ + assingGlobalFunction( "rlglGetVersion", lrlglGetVersion ); /* OpenGL */ /* Framebuffer management. */ diff --git a/src/models.c b/src/models.c index 3f69001..26e7e72 100644 --- a/src/models.c +++ b/src/models.c @@ -182,6 +182,102 @@ void UnloadModelKeepMeshes( Model model ) { TRACELOG(LOG_INFO, "MODEL: Unloaded model (but not meshes) from RAM and VRAM"); } +void DrawBillboardProNoRatio( Camera camera, Texture2D texture, Rectangle source, Vector3 position, Vector3 up, Vector2 size, Vector2 origin, float rotation, Color tint ) { + // NOTE: Billboard size will maintain source rectangle aspect ratio, size will represent billboard width + // Vector2 sizeRatio = { size.x*(float)source.width/source.height, size.y }; + Vector2 sizeRatio = { size.x, size.y }; + + Matrix matView = MatrixLookAt(camera.position, camera.target, camera.up); + + Vector3 right = { matView.m0, matView.m4, matView.m8 }; + //Vector3 up = { matView.m1, matView.m5, matView.m9 }; + + Vector3 rightScaled = Vector3Scale(right, sizeRatio.x/2); + Vector3 upScaled = Vector3Scale(up, sizeRatio.y/2); + + Vector3 p1 = Vector3Add(rightScaled, upScaled); + Vector3 p2 = Vector3Subtract(rightScaled, upScaled); + + Vector3 topLeft = Vector3Scale(p2, -1); + Vector3 topRight = p1; + Vector3 bottomRight = p2; + Vector3 bottomLeft = Vector3Scale(p1, -1); + + if (rotation != 0.0f) + { + float sinRotation = sinf(rotation*DEG2RAD); + float cosRotation = cosf(rotation*DEG2RAD); + + // NOTE: (-1, 1) is the range where origin.x, origin.y is inside the texture + float rotateAboutX = sizeRatio.x*origin.x/2; + float rotateAboutY = sizeRatio.y*origin.y/2; + + float xtvalue, ytvalue; + float rotatedX, rotatedY; + + xtvalue = Vector3DotProduct(right, topLeft) - rotateAboutX; // Project points to x and y coordinates on the billboard plane + ytvalue = Vector3DotProduct(up, topLeft) - rotateAboutY; + rotatedX = xtvalue*cosRotation - ytvalue*sinRotation + rotateAboutX; // Rotate about the point origin + rotatedY = xtvalue*sinRotation + ytvalue*cosRotation + rotateAboutY; + topLeft = Vector3Add(Vector3Scale(up, rotatedY), Vector3Scale(right, rotatedX)); // Translate back to cartesian coordinates + + xtvalue = Vector3DotProduct(right, topRight) - rotateAboutX; + ytvalue = Vector3DotProduct(up, topRight) - rotateAboutY; + rotatedX = xtvalue*cosRotation - ytvalue*sinRotation + rotateAboutX; + rotatedY = xtvalue*sinRotation + ytvalue*cosRotation + rotateAboutY; + topRight = Vector3Add(Vector3Scale(up, rotatedY), Vector3Scale(right, rotatedX)); + + xtvalue = Vector3DotProduct(right, bottomRight) - rotateAboutX; + ytvalue = Vector3DotProduct(up, bottomRight) - rotateAboutY; + rotatedX = xtvalue*cosRotation - ytvalue*sinRotation + rotateAboutX; + rotatedY = xtvalue*sinRotation + ytvalue*cosRotation + rotateAboutY; + bottomRight = Vector3Add(Vector3Scale(up, rotatedY), Vector3Scale(right, rotatedX)); + + xtvalue = Vector3DotProduct(right, bottomLeft)-rotateAboutX; + ytvalue = Vector3DotProduct(up, bottomLeft)-rotateAboutY; + rotatedX = xtvalue*cosRotation - ytvalue*sinRotation + rotateAboutX; + rotatedY = xtvalue*sinRotation + ytvalue*cosRotation + rotateAboutY; + bottomLeft = Vector3Add(Vector3Scale(up, rotatedY), Vector3Scale(right, rotatedX)); + } + + // Translate points to the draw center (position) + topLeft = Vector3Add(topLeft, position); + topRight = Vector3Add(topRight, position); + bottomRight = Vector3Add(bottomRight, position); + bottomLeft = Vector3Add(bottomLeft, position); + + rlSetTexture(texture.id); + + rlBegin(RL_QUADS); + rlColor4ub(tint.r, tint.g, tint.b, tint.a); + + // Bottom-left corner for texture and quad + rlTexCoord2f((float)source.x/texture.width, (float)source.y/texture.height); + rlVertex3f(topLeft.x, topLeft.y, topLeft.z); + + // Top-left corner for texture and quad + rlTexCoord2f((float)source.x/texture.width, (float)(source.y + source.height)/texture.height); + rlVertex3f(bottomLeft.x, bottomLeft.y, bottomLeft.z); + + // Top-right corner for texture and quad + rlTexCoord2f((float)(source.x + source.width)/texture.width, (float)(source.y + source.height)/texture.height); + rlVertex3f(bottomRight.x, bottomRight.y, bottomRight.z); + + // Bottom-right corner for texture and quad + rlTexCoord2f((float)(source.x + source.width)/texture.width, (float)source.y/texture.height); + rlVertex3f(topRight.x, topRight.y, topRight.z); + rlEnd(); + + rlSetTexture(0); +} + +void DrawBillboardRecNoRatio( Camera camera, Texture2D texture, Rectangle source, Vector3 position, Vector2 size, Color tint ) { + // NOTE: Billboard locked on axis-Y + Vector3 up = { 0.0f, 1.0f, 0.0f }; + + DrawBillboardProNoRatio(camera, texture, source, position, up, size, Vector2Zero(), 0.0f, tint); +} + /* ## Models - Basic */ @@ -2049,7 +2145,45 @@ int lmodelsDrawBillboardRec( lua_State *L ) { lua_pushboolean( L, false ); return 1; } - DrawBillboardRec( *state->camera3Ds[ cameraId ], *texturesGetSourceTexture( texId ), source, position, size, tint ); + // DrawBillboardRec( *state->camera3Ds[ cameraId ], *texturesGetSourceTexture( texId ), source, position, size, tint ); + DrawBillboardRecNoRatio( *state->camera3Ds[ cameraId ], *texturesGetSourceTexture( texId ), source, position, size, tint ); + lua_pushboolean( L, true ); + + return 1; +} + +/* +> success = RL.DrawBillboardPro( Camera camera, Texture2D texture, Rectangle source, Vector3 position, Vector3 up, Vector2 size, Vector2 origin, float rotation, Color tint ) + +Draw a billboard texture defined by source and rotation + +- Failure return false +- Success return true +*/ +int lmodelsDrawBillboardPro( lua_State *L ) { + if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_istable( L, 3 ) + || !lua_istable( L, 4 ) || !lua_istable( L, 5 ) || !lua_istable( L, 6 ) + || !lua_istable( L, 7 ) || !lua_isnumber( L, 8 ) || !lua_istable( L, 9 ) ) { + TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.DrawBillboardPro( Camera camera, Texture2D texture, Rectangle source, Vector3 position, Vector3 up, Vector2 size, Vector2 origin, float rotation, Color tint )" ); + lua_pushboolean( L, false ); + return 1; + } + size_t cameraId = lua_tointeger( L, 1 ); + size_t texId = lua_tointeger( L, 2 ); + Rectangle source = uluaGetRectangleIndex( L, 3 ); + Vector3 position = uluaGetVector3Index( L, 4 ); + Vector3 up = uluaGetVector3Index( L, 5 ); + Vector2 size = uluaGetVector2Index( L, 6 ); + Vector2 origin = uluaGetVector2Index( L, 7 ); + float rotation = lua_tonumber( L, 8 ); + Color tint = uluaGetColorIndex( L, 9 ); + + if ( !validTexture( texId, TEXTURE_TYPE_ALL ) || !validCamera3D( cameraId ) ) { + lua_pushboolean( L, false ); + return 1; + } + // DrawBillboardPro( *state->camera3Ds[ cameraId ], *texturesGetSourceTexture( texId ), source, position, up, size, origin, rotation, tint ); + DrawBillboardProNoRatio( *state->camera3Ds[ cameraId ], *texturesGetSourceTexture( texId ), source, position, up, size, origin, rotation, tint ); lua_pushboolean( L, true ); return 1; @@ -39,3 +39,20 @@ int lrlglGetLineWidth( lua_State *L ) { return 1; } + +/* +## RLGL - Initialization functions +*/ + +/* +> version = RL.rlGetVersion() + +Get current OpenGL version + +- Success return int +*/ +int lrlglGetVersion( lua_State *L ) { + lua_pushinteger( L, rlGetVersion() ); + + return 1; +} |
