Camera2D.

This commit is contained in:
jussi
2022-05-04 17:21:49 +03:00
parent 6f4aceeb4c
commit ed4636fa81
10 changed files with 712 additions and 12 deletions

148
API.md
View File

@@ -1601,7 +1601,115 @@ Get file modification time ( Last write time )
---
## Core - Camera
## Core - Camera2D
---
> camera2D = RL_CreateCamera2D()
Return camera2D id set to default configuration
- Success return int
---
> success = RL_UnloadCamera2D( int Camera2D )
Unload Camera2D
- Failure return false
- Success return true
---
> success = RL_BeginMode2D( camera2D camera )
Begin 2D mode with custom camera ( 2D )
- Failure return false
- Success return true
---
> RL_EndMode2D()
Ends 2D mode with custom camera
---
> success = RL_SetCamera2DTarget( camera2D camera, Vector2 target )
Set camera target ( rotation and zoom origin )
- Failure return false
- Success return true
---
> success = RL_SetCamera2DOffset( camera2D camera, Vector2 offset )
Set camera offset ( displacement from target )
- Failure return false
- Success return true
---
> success = RL_SetCamera2DRotation( camera3D camera, float rotation )
Set camera rotation in degrees
- Failure return false
- Success return true
---
> success = RL_SetCamera2DZoom( camera3D camera, float zoom )
Set camera zoom ( scaling ), should be 1.0f by default
- Failure return false
- Success return true
---
> target = RL_GetCamera2DTarget( camera2D camera )
Get camera2D target
- Failure return nil
- Success return Vector2
---
> offset = RL_GetCamera2DOffset( camera2D camera )
Get camera2D offset
- Failure return nil
- Success return Vector2
---
> rotation = RL_GetCamera2DRotation( camera2D camera )
Get camera2D rotation
- Failure return nil
- Success return float
---
> zoom = RL_GetCamera2DZoom( camera2D camera )
Get camera2D zoom
- Failure return nil
- Success return float
---
## Core - Camera3D
---
@@ -1624,7 +1732,7 @@ Unload Camera3D
> success = RL_BeginMode3D( camera3D camera )
Initializes 3D mode with custom camera ( 3D )
Begin 3D mode with custom camera ( 3D )
- Failure return false
- Success return true
@@ -1767,6 +1875,15 @@ Get camera transform matrix ( view matrix )
---
> matrix = RL_GetCameraMatrix2D( Camera2D camera )
Get camera 2d transform matrix
- Failure return false
- Success return Matrix
---
> position = RL_GetWorldToScreen( Vector3 position, Camera3D camera )
Get the screen space position for a 3d world space position
@@ -1776,6 +1893,33 @@ Get the screen space position for a 3d world space position
---
> position = RL_GetWorldToScreenEx( Vector3 position, Camera3D camera, Vector2 size )
Get size position for a 3d world space position
- Failure return false
- Success return Vector2
---
> position = RL_GetWorldToScreen2D( Vector2 position, Camera2D camera )
Get the screen space position for a 2d camera world space position
- Failure return false
- Success return Vector2
---
> position = RL_GetScreenToWorld2D( Vector2 position, Camera2D camera )
Get the world space position for a 2d camera screen space position
- Failure return false
- Success return Vector2
---
## Shapes - Drawing
---

View File

@@ -16,8 +16,6 @@ List of some MISSING features that are planned to be included. For specific func
* Core
* Files drop
* Camera2d and it's functions
* Screen-space-related functions
* VR stereo config functions for VR simulator
* Textures
* Image manipulation functions

View File

@@ -6,7 +6,6 @@ Backlog {
* More and better examples
* Core
* Screen-space-related
* Files drop
* Text
* More Font loading/unloading functions

View File

@@ -0,0 +1,67 @@
local tileTexture = -1
local camera = -1
local cameraPos = { 0, 0 }
local cameraRot = 0.0
local cameraZoom = 1.0
local cameraSpeed = 100.0
local cameraRotSpeed = 100.0
local cameraZoomSpeed = 10.0
function init()
local monitor = 0
local mPos = RL_GetMonitorPosition( monitor )
local mSize = RL_GetMonitorSize( monitor )
local winSize = RL_GetWindowSize()
RL_SetWindowState( FLAG_WINDOW_RESIZABLE )
RL_SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } )
RL_SetWindowTitle( "Camera 2D" )
tileTexture = RL_LoadTexture( RL_GetBasePath().."../resources/images/tiles.png" )
camera = RL_CreateCamera2D()
RL_SetCamera2DOffset( camera, { winSize[1] / 2, winSize[2] / 2 } )
end
function process( delta )
-- Move.
if RL_IsKeyDown( KEY_RIGHT ) then
cameraPos[1] = cameraPos[1] + cameraSpeed * delta
elseif RL_IsKeyDown( KEY_LEFT ) then
cameraPos[1] = cameraPos[1] - cameraSpeed * delta
end
if RL_IsKeyDown( KEY_DOWN ) then
cameraPos[2] = cameraPos[2] + cameraSpeed * delta
elseif RL_IsKeyDown( KEY_UP ) then
cameraPos[2] = cameraPos[2] - cameraSpeed * delta
end
-- Rotate.
if RL_IsKeyDown( string.byte( "E" ) ) then
cameraRot = cameraRot + cameraRotSpeed * delta
elseif RL_IsKeyDown( string.byte( "Q" ) ) then
cameraRot = cameraRot - cameraRotSpeed * delta
end
-- Zoom.
if RL_IsKeyDown( string.byte( "R" ) ) then
cameraZoom = cameraZoom + cameraZoomSpeed * delta
elseif RL_IsKeyDown( string.byte( "F" ) ) then
cameraZoom = cameraZoom - cameraZoomSpeed * delta
end
end
function draw()
RL_ClearBackground( RAYWHITE )
RL_SetCamera2DTarget( camera, cameraPos )
RL_SetCamera2DRotation( camera, cameraRot )
RL_SetCamera2DZoom( camera, cameraZoom )
RL_BeginMode2D( camera )
-- Draw wall.
for y = 0, 4 do
for x = 0, 6 do
RL_DrawTextureRec( tileTexture, { 0, 0, 32, 32 }, { x * 32, y * 32 }, WHITE )
end
end
-- Draw hero.
RL_DrawTextureRec( tileTexture, { 3 * 32, 0, 32, 32 }, { cameraPos[1] - 16, cameraPos[2] - 16 }, WHITE )
RL_EndMode2D()
end

View File

@@ -6,9 +6,7 @@
Modified by Jussi Viitala (@nullstare) for ReiLua style.
]]
local winSize = RL_GetWindowSize()
local camera = -1
local num_blocks = 15
function init()

View File

@@ -82,7 +82,20 @@ int lcoreGetPrevDirectoryPath( lua_State *L );
int lcoreGetWorkingDirectory( lua_State *L );
int lcoreGetDirectoryFiles( lua_State *L );
int lcoreGetFileModTime( lua_State *L );
/* Camera. */
/* Camera2D. */
int lcoreCreateCamera2D( lua_State *L );
int lcoreUnloadCamera2D( lua_State *L );
int lcoreBeginMode2D( lua_State *L );
int lcoreEndMode2D( lua_State *L );
int lcoreSetCamera2DTarget( lua_State *L );
int lcoreSetCamera2DOffset( lua_State *L );
int lcoreSetCamera2DRotation( lua_State *L );
int lcoreSetCamera2DZoom( lua_State *L );
int lcoreGetCamera2DTarget( lua_State *L );
int lcoreGetCamera2DOffset( lua_State *L );
int lcoreGetCamera2DRotation( lua_State *L );
int lcoreGetCamera2DZoom( lua_State *L );
/* Camera3D. */
int lcoreCreateCamera3D( lua_State *L );
int lcoreUnloadCamera3D( lua_State *L );
int lcoreBeginMode3D( lua_State *L );
@@ -134,4 +147,8 @@ int lcoreGetGesturePinchAngle( lua_State *L );
/* Screen-space. */
int lcoreGetMouseRay( lua_State *L );
int lcoreGetCameraMatrix( lua_State *L );
int lcoreGetCameraMatrix2D( lua_State *L );
int lcoreGetWorldToScreen( lua_State *L );
int lcoreGetWorldToScreenEx( lua_State *L );
int lcoreGetWorldToScreen2D( lua_State *L );
int lcoreGetScreenToWorld2D( lua_State *L );

View File

@@ -38,6 +38,10 @@ typedef struct {
size_t soundAlloc;
/* Music. */
Music music;
/* Camera2D's. */
Camera2D **camera2Ds;
size_t camera2DCount;
size_t camera2DAlloc;
/* Camera3D's. */
Camera3D **camera3Ds;
size_t camera3DCount;

View File

@@ -4,6 +4,21 @@
#include "textures.h"
#include "lua_core.h"
static void checkCamera2DRealloc( int i ) {
if ( i == state->camera2DCount ) {
state->camera2DCount++;
}
if ( state->camera2DCount == state->camera2DAlloc ) {
state->camera2DAlloc += ALLOC_PAGE_SIZE;
state->camera2Ds = realloc( state->camera2Ds, state->camera2DAlloc * sizeof( Camera2D* ) );
for ( i = state->camera2DCount; i < state->camera2DAlloc; i++ ) {
state->camera2Ds[i] = NULL;
}
}
}
static void checkCamera3DRealloc( int i ) {
if ( i == state->camera3DCount ) {
state->camera3DCount++;
@@ -34,9 +49,19 @@ static void checkShaderRealloc( int i ) {
}
}
bool validCamera2D( size_t id ) {
if ( id < 0 || state->camera2DCount < id || state->camera2Ds[ id ] == NULL ) {
TraceLog( LOG_WARNING, "%s %d", "Invalid camera2D", id );
return false;
}
else {
return true;
}
}
bool validCamera3D( size_t id ) {
if ( id < 0 || state->camera3DCount < id || state->camera3Ds[ id ] == NULL ) {
TraceLog( LOG_WARNING, "%s %d", "Invalid camera", id );
TraceLog( LOG_WARNING, "%s %d", "Invalid camera3D", id );
return false;
}
else {
@@ -1989,7 +2014,316 @@ int lcoreGetFileModTime( lua_State *L ) {
}
/*
## Core - Camera
## Core - Camera2D
*/
/*
> camera2D = RL_CreateCamera2D()
Return camera2D id set to default configuration
- Success return int
*/
int lcoreCreateCamera2D( lua_State *L ) {
int i = 0;
for ( i = 0; i < state->camera2DCount; i++ ) {
if ( state->camera2Ds[i] == NULL ) {
break;
}
}
state->camera2Ds[i] = malloc( sizeof( Camera2D ) );
state->camera2Ds[i]->offset = (Vector2){ 0.0, 0.0 };
state->camera2Ds[i]->target = (Vector2){ 0.0, 0.0 };
state->camera2Ds[i]->rotation = 0.0;
state->camera2Ds[i]->zoom = 1.0;
lua_pushinteger( L, i );
checkCamera2DRealloc(i);
return 1;
}
/*
> success = RL_UnloadCamera2D( int Camera2D )
Unload Camera2D
- Failure return false
- Success return true
*/
int lcoreUnloadCamera2D( lua_State *L ) {
if ( !lua_isnumber( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_UnloadCamera2D( int Camera2D )" );
lua_pushboolean( L, false );
return 1;
}
size_t id = lua_tointeger( L, -1 );
if ( !validCamera2D( id ) ) {
lua_pushboolean( L, false );
return 1;
}
free( state->camera2Ds[ id ] );
state->camera2Ds[ id ] = NULL;
lua_pushboolean( L, true );
return 1;
}
/*
> success = RL_BeginMode2D( camera2D camera )
Begin 2D mode with custom camera ( 2D )
- Failure return false
- Success return true
*/
int lcoreBeginMode2D( lua_State *L ) {
if ( !lua_isnumber( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_BeginMode2D( camera2D camera )" );
lua_pushboolean( L, false );
return 1;
}
size_t id = lua_tointeger( L, -1 );
if ( !validCamera2D( id ) ) {
lua_pushboolean( L, false );
return 1;
}
BeginMode2D( *state->camera2Ds[ id ] );
lua_pushboolean( L, true );
return 1;
}
/*
> RL_EndMode2D()
Ends 2D mode with custom camera
*/
int lcoreEndMode2D( lua_State *L ) {
EndMode2D();
return 1;
}
/*
> success = RL_SetCamera2DTarget( camera2D camera, Vector2 target )
Set camera target ( rotation and zoom origin )
- Failure return false
- Success return true
*/
int lcoreSetCamera2DTarget( lua_State *L ) {
if ( !lua_isnumber( L, -2 ) || !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_SetCamera2DTarget( camera2D camera, Vector2 target )" );
lua_pushboolean( L, false );
return 1;
}
Vector2 target = uluaGetVector2( L );
size_t cameraId = lua_tointeger( L, -2 );
if ( !validCamera2D( cameraId ) ) {
lua_pushboolean( L, false );
return 1;
}
state->camera2Ds[ cameraId ]->target = target;
lua_pushboolean( L, true );
return 1;
}
/*
> success = RL_SetCamera2DOffset( camera2D camera, Vector2 offset )
Set camera offset ( displacement from target )
- Failure return false
- Success return true
*/
int lcoreSetCamera2DOffset( lua_State *L ) {
if ( !lua_isnumber( L, -2 ) || !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_SetCamera2DOffset( camera2D camera, Vector2 offset )" );
lua_pushboolean( L, false );
return 1;
}
Vector2 offset = uluaGetVector2( L );
size_t cameraId = lua_tointeger( L, -2 );
if ( !validCamera2D( cameraId ) ) {
lua_pushboolean( L, false );
return 1;
}
state->camera2Ds[ cameraId ]->offset = offset;
lua_pushboolean( L, true );
return 1;
}
/*
> success = RL_SetCamera2DRotation( camera3D camera, float rotation )
Set camera rotation in degrees
- Failure return false
- Success return true
*/
int lcoreSetCamera2DRotation( lua_State *L ) {
if ( !lua_isnumber( L, -2 ) || !lua_isnumber( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_SetCamera2DRotation( camera3D camera, float rotation )" );
lua_pushboolean( L, false );
return 1;
}
size_t cameraId = lua_tointeger( L, -2 );
if ( !validCamera2D( cameraId ) ) {
lua_pushboolean( L, false );
return 1;
}
state->camera2Ds[ cameraId ]->rotation = lua_tonumber( L, -1 );
lua_pushboolean( L, true );
return 1;
}
/*
> success = RL_SetCamera2DZoom( camera3D camera, float zoom )
Set camera zoom ( scaling ), should be 1.0f by default
- Failure return false
- Success return true
*/
int lcoreSetCamera2DZoom( lua_State *L ) {
if ( !lua_isnumber( L, -2 ) || !lua_isnumber( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_SetCamera2DZoom( camera3D camera, float zoom )" );
lua_pushboolean( L, false );
return 1;
}
size_t cameraId = lua_tointeger( L, -2 );
if ( !validCamera2D( cameraId ) ) {
lua_pushboolean( L, false );
return 1;
}
state->camera2Ds[ cameraId ]->zoom = lua_tonumber( L, -1 );
lua_pushboolean( L, true );
return 1;
}
/*
> target = RL_GetCamera2DTarget( camera2D camera )
Get camera2D target
- Failure return nil
- Success return Vector2
*/
int lcoreGetCamera2DTarget( lua_State *L ) {
if ( !lua_isnumber( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GetCamera2DTarget( camera2D camera )" );
lua_pushnil( L );
return 1;
}
size_t cameraId = lua_tointeger( L, -1 );
if ( !validCamera2D( cameraId ) ) {
lua_pushnil( L );
return 1;
}
uluaPushVector2( L, state->camera2Ds[ cameraId ]->target );
return 1;
}
/*
> offset = RL_GetCamera2DOffset( camera2D camera )
Get camera2D offset
- Failure return nil
- Success return Vector2
*/
int lcoreGetCamera2DOffset( lua_State *L ) {
if ( !lua_isnumber( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GetCamera2DOffset( camera2D camera )" );
lua_pushnil( L );
return 1;
}
size_t cameraId = lua_tointeger( L, -1 );
if ( !validCamera2D( cameraId ) ) {
lua_pushnil( L );
return 1;
}
uluaPushVector2( L, state->camera2Ds[ cameraId ]->offset );
return 1;
}
/*
> rotation = RL_GetCamera2DRotation( camera2D camera )
Get camera2D rotation
- Failure return nil
- Success return float
*/
int lcoreGetCamera2DRotation( lua_State *L ) {
if ( !lua_isnumber( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GetCamera2DRotation( camera2D camera )" );
lua_pushnil( L );
return 1;
}
size_t cameraId = lua_tointeger( L, -1 );
if ( !validCamera2D( cameraId ) ) {
lua_pushnil( L );
return 1;
}
lua_pushnumber( L, state->camera2Ds[ cameraId ]->rotation );
return 1;
}
/*
> zoom = RL_GetCamera2DZoom( camera2D camera )
Get camera2D zoom
- Failure return nil
- Success return float
*/
int lcoreGetCamera2DZoom( lua_State *L ) {
if ( !lua_isnumber( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GetCamera2DZoom( camera2D camera )" );
lua_pushnil( L );
return 1;
}
size_t cameraId = lua_tointeger( L, -1 );
if ( !validCamera2D( cameraId ) ) {
lua_pushnil( L );
return 1;
}
lua_pushnumber( L, state->camera2Ds[ cameraId ]->zoom );
return 1;
}
/*
## Core - Camera3D
*/
/*
@@ -2008,6 +2342,9 @@ int lcoreCreateCamera3D( lua_State *L ) {
}
}
state->camera3Ds[i] = malloc( sizeof( Camera3D ) );
state->camera3Ds[i]->position = (Vector3){ 0.0, 0.0, 0.0 };
state->camera3Ds[i]->target = (Vector3){ 0.0, 0.0, 0.0 };
state->camera3Ds[i]->up = (Vector3){ 0.0, 0.0, 0.0 };
state->camera3Ds[i]->fovy = 45.0f;
state->camera3Ds[i]->projection = CAMERA_PERSPECTIVE;
SetCameraMode( *state->camera3Ds[i], CAMERA_CUSTOM );
@@ -2049,7 +2386,7 @@ int lcoreUnloadCamera3D( lua_State *L ) {
/*
> success = RL_BeginMode3D( camera3D camera )
Initializes 3D mode with custom camera ( 3D )
Begin 3D mode with custom camera ( 3D )
- Failure return false
- Success return true
@@ -2462,6 +2799,31 @@ int lcoreGetCameraMatrix( lua_State *L ) {
return 1;
}
/*
> matrix = RL_GetCameraMatrix2D( Camera2D camera )
Get camera 2d transform matrix
- Failure return false
- Success return Matrix
*/
int lcoreGetCameraMatrix2D( lua_State *L ) {
if ( !lua_isnumber( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GetCameraMatrix2D( Camera2D camera )" );
lua_pushboolean( L, false );
return 1;
}
size_t cameraId = lua_tointeger( L, -1 );
if ( !validCamera2D( cameraId ) ) {
lua_pushboolean( L, false );
return 1;
}
uluaPushMatrix( L, GetCameraMatrix2D( *state->camera2Ds[ cameraId ] ) );
return 1;
}
/*
> position = RL_GetWorldToScreen( Vector3 position, Camera3D camera )
@@ -2488,3 +2850,86 @@ int lcoreGetWorldToScreen( lua_State *L ) {
return 1;
}
/*
> position = RL_GetWorldToScreenEx( Vector3 position, Camera3D camera, Vector2 size )
Get size position for a 3d world space position
- Failure return false
- Success return Vector2
*/
int lcoreGetWorldToScreenEx( lua_State *L ) {
if ( !lua_istable( L, -2 ) || !lua_isnumber( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GetWorldToScreenEx( Vector3 position, Camera3D camera, Vector2 size )" );
lua_pushboolean( L, false );
return 1;
}
Vector2 size = uluaGetVector2( L );
lua_pop( L, 1 );
size_t cameraId = lua_tointeger( L, -1 );
lua_pop( L, 1 );
Vector3 position = uluaGetVector3( L );
if ( !validCamera3D( cameraId ) ) {
lua_pushboolean( L, false );
return 1;
}
uluaPushVector2( L, GetWorldToScreenEx( position, *state->camera3Ds[ cameraId ], size.x, size.y ) );
return 1;
}
/*
> position = RL_GetWorldToScreen2D( Vector2 position, Camera2D camera )
Get the screen space position for a 2d camera world space position
- Failure return false
- Success return Vector2
*/
int lcoreGetWorldToScreen2D( lua_State *L ) {
if ( !lua_istable( L, -2 ) || !lua_isnumber( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GetWorldToScreen2D( Vector2 position, Camera2D camera )" );
lua_pushboolean( L, false );
return 1;
}
size_t cameraId = lua_tointeger( L, -1 );
lua_pop( L, 1 );
Vector2 position = uluaGetVector2( L );
if ( !validCamera2D( cameraId ) ) {
lua_pushboolean( L, false );
return 1;
}
uluaPushVector2( L, GetWorldToScreen2D( position, *state->camera2Ds[ cameraId ] ) );
return 1;
}
/*
> position = RL_GetScreenToWorld2D( Vector2 position, Camera2D camera )
Get the world space position for a 2d camera screen space position
- Failure return false
- Success return Vector2
*/
int lcoreGetScreenToWorld2D( lua_State *L ) {
if ( !lua_istable( L, -2 ) || !lua_isnumber( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GetScreenToWorld2D( Vector2 position, Camera2D camera )" );
lua_pushboolean( L, false );
return 1;
}
size_t cameraId = lua_tointeger( L, -1 );
lua_pop( L, 1 );
Vector2 position = uluaGetVector2( L );
if ( !validCamera2D( cameraId ) ) {
lua_pushboolean( L, false );
return 1;
}
uluaPushVector2( L, GetScreenToWorld2D( position, *state->camera2Ds[ cameraId ] ) );
return 1;
}

View File

@@ -553,7 +553,20 @@ void luaRegister() {
lua_register( L, "RL_GetWorkingDirectory", lcoreGetWorkingDirectory );
lua_register( L, "RL_GetDirectoryFiles", lcoreGetDirectoryFiles );
lua_register( L, "RL_GetFileModTime", lcoreGetFileModTime );
/* Camera. */
/* Camera3D. */
lua_register( L, "RL_CreateCamera2D", lcoreCreateCamera2D );
lua_register( L, "RL_UnloadCamera2D", lcoreUnloadCamera2D );
lua_register( L, "RL_BeginMode2D", lcoreBeginMode2D );
lua_register( L, "RL_EndMode2D", lcoreEndMode2D );
lua_register( L, "RL_SetCamera2DTarget", lcoreSetCamera2DTarget );
lua_register( L, "RL_SetCamera2DOffset", lcoreSetCamera2DOffset );
lua_register( L, "RL_SetCamera2DRotation", lcoreSetCamera2DRotation );
lua_register( L, "RL_SetCamera2DZoom", lcoreSetCamera2DZoom );
lua_register( L, "RL_GetCamera2DTarget", lcoreGetCamera2DTarget );
lua_register( L, "RL_GetCamera2DOffset", lcoreGetCamera2DOffset );
lua_register( L, "RL_GetCamera2DRotation", lcoreGetCamera2DRotation );
lua_register( L, "RL_GetCamera2DZoom", lcoreGetCamera2DZoom );
/* Camera3D. */
lua_register( L, "RL_CreateCamera3D", lcoreCreateCamera3D );
lua_register( L, "RL_UnloadCamera3D", lcoreUnloadCamera3D );
lua_register( L, "RL_BeginMode3D", lcoreBeginMode3D );
@@ -605,7 +618,11 @@ void luaRegister() {
/* Screen-space. */
lua_register( L, "RL_GetMouseRay", lcoreGetMouseRay );
lua_register( L, "RL_GetCameraMatrix", lcoreGetCameraMatrix );
lua_register( L, "RL_GetCameraMatrix2D", lcoreGetCameraMatrix2D );
lua_register( L, "RL_GetWorldToScreen", lcoreGetWorldToScreen );
lua_register( L, "RL_GetWorldToScreenEx", lcoreGetWorldToScreenEx );
lua_register( L, "RL_GetWorldToScreen2D", lcoreGetWorldToScreen2D );
lua_register( L, "RL_GetScreenToWorld2D", lcoreGetScreenToWorld2D );
/* Shapes. */
/* Drawing. */

View File

@@ -37,6 +37,10 @@ bool stateInit( const char *exePath ) {
state->soundAlloc = ALLOC_PAGE_SIZE;
state->soundCount = 0;
state->sounds = malloc( state->soundAlloc * sizeof( Sound* ) );
/* Camera2D's. */
state->camera2DAlloc = ALLOC_PAGE_SIZE;
state->camera2DCount = 0;
state->camera2Ds = malloc( state->camera2DAlloc * sizeof( Camera2D* ) );
/* Camera3D's. */
state->camera3DAlloc = ALLOC_PAGE_SIZE;
state->camera3DCount = 0;
@@ -71,6 +75,7 @@ bool stateInit( const char *exePath ) {
state->textures[i] = NULL;
state->renderTextures[i] = NULL;
state->sounds[i] = NULL;
state->camera2Ds[i] = NULL;
state->camera3Ds[i] = NULL;
state->meshes[i] = NULL;
state->models[i] = NULL;
@@ -137,6 +142,11 @@ void stateFree() {
free( state->sounds[i] );
}
}
for ( int i = 0; i < state->camera2DCount; ++i ) {
if ( state->camera2Ds[i] != NULL ) {
free( state->camera2Ds[i] );
}
}
for ( int i = 0; i < state->camera3DCount; ++i ) {
if ( state->camera3Ds[i] != NULL ) {
free( state->camera3Ds[i] );
@@ -197,6 +207,7 @@ void stateFree() {
free( state->renderTextures );
free( state->fonts );
free( state->sounds );
free( state->camera2Ds );
free( state->camera3Ds );
free( state->meshes );
free( state->materials );