summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjussi2023-04-10 23:52:13 +0300
committerjussi2023-04-10 23:52:13 +0300
commit3445d935d66969a7eec97e8691b68496dc51af0b (patch)
treeab9678193bd3e896c50ef80965f7e906b141cedd /src
parent6938cdbaede7eb63b9bc2adb9e0a93e243e291ee (diff)
downloadreilua-enhanced-3445d935d66969a7eec97e8691b68496dc51af0b.tar.gz
reilua-enhanced-3445d935d66969a7eec97e8691b68496dc51af0b.tar.bz2
reilua-enhanced-3445d935d66969a7eec97e8691b68496dc51af0b.zip
Camera3D lib. New camera3D functions.
Diffstat (limited to 'src')
-rw-r--r--src/core.c339
-rw-r--r--src/lua_core.c17
2 files changed, 351 insertions, 5 deletions
diff --git a/src/core.c b/src/core.c
index 84b6991..c04fb93 100644
--- a/src/core.c
+++ b/src/core.c
@@ -3171,6 +3171,345 @@ int lcoreGetCamera3DProjection( lua_State *L ) {
}
/*
+> forward = RL.GetCamera3DForward( camera3D camera )
+
+Returns the cameras forward vector ( normalized )
+
+- Failure return nil
+- Success return Vector3
+*/
+int lcoreGetCamera3DForward( lua_State *L ) {
+ if ( !lua_isnumber( L, 1 ) ) {
+ TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GetCamera3DForward( camera3D camera )" );
+ lua_pushnil( L );
+ return 1;
+ }
+ size_t cameraId = lua_tointeger( L, 1 );
+
+ if ( !validCamera3D( cameraId ) ) {
+ lua_pushnil( L );
+ return 1;
+ }
+ uluaPushVector3( L, GetCameraForward( state->camera3Ds[ cameraId ] ) );
+
+ return 1;
+}
+
+/*
+> up = RL.GetCamera3DUpNormalized( camera3D camera )
+
+Returns the cameras up vector ( normalized )
+Note: The up vector might not be perpendicular to the forward vector
+
+- Failure return nil
+- Success return Vector3
+*/
+int lcoreGetCamera3DUpNormalized( lua_State *L ) {
+ if ( !lua_isnumber( L, 1 ) ) {
+ TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GetCamera3DUpNormalized( camera3D camera )" );
+ lua_pushnil( L );
+ return 1;
+ }
+ size_t cameraId = lua_tointeger( L, 1 );
+
+ if ( !validCamera3D( cameraId ) ) {
+ lua_pushnil( L );
+ return 1;
+ }
+ uluaPushVector3( L, GetCameraUp( state->camera3Ds[ cameraId ] ) );
+
+ return 1;
+}
+
+/*
+> forward = RL.GetCamera3DRight( camera3D camera )
+
+Returns the cameras right vector ( normalized )
+
+- Failure return nil
+- Success return Vector3
+*/
+int lcoreGetCamera3DRight( lua_State *L ) {
+ if ( !lua_isnumber( L, 1 ) ) {
+ TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GetCamera3DRight( camera3D camera )" );
+ lua_pushnil( L );
+ return 1;
+ }
+ size_t cameraId = lua_tointeger( L, 1 );
+
+ if ( !validCamera3D( cameraId ) ) {
+ lua_pushnil( L );
+ return 1;
+ }
+ uluaPushVector3( L, GetCameraRight( state->camera3Ds[ cameraId ] ) );
+
+ return 1;
+}
+
+/*
+> success = RL.Camera3DMoveForward( camera3D camera, float distance, bool moveInWorldPlane )
+
+Moves the camera in it's forward direction
+
+- Failure return false
+- Success return true
+*/
+int lcoreCamera3DMoveForward( lua_State *L ) {
+ if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isboolean( L, 3 ) ) {
+ TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GetCamera3DRight( camera3D camera )" );
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ size_t cameraId = lua_tointeger( L, 1 );
+ float distance = lua_tonumber( L, 2 );
+ bool moveInWorldPlane = lua_toboolean( L, 3 );
+
+ if ( !validCamera3D( cameraId ) ) {
+ lua_pushboolean( L, false );
+ return 1;
+ }
+
+ CameraMoveForward( state->camera3Ds[ cameraId ], distance, moveInWorldPlane );
+ lua_pushboolean( L, true );
+
+ return 1;
+}
+
+/*
+> success = RL.Camera3DMoveUp( camera3D camera, float distance )
+
+Moves the camera in it's up direction
+
+- Failure return false
+- Success return true
+*/
+int lcoreCamera3DMoveUp( lua_State *L ) {
+ if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) ) {
+ TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.Camera3DMoveUp( camera3D camera, float distance )" );
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ size_t cameraId = lua_tointeger( L, 1 );
+ float distance = lua_tonumber( L, 2 );
+
+ if ( !validCamera3D( cameraId ) ) {
+ lua_pushboolean( L, false );
+ return 1;
+ }
+
+ CameraMoveUp( state->camera3Ds[ cameraId ], distance );
+ lua_pushboolean( L, true );
+
+ return 1;
+}
+
+/*
+> success = RL.Camera3DMoveRight( camera3D camera, float distance, bool moveInWorldPlane )
+
+Moves the camera target in it's current right direction
+
+- Failure return false
+- Success return true
+*/
+int lcoreCamera3DMoveRight( lua_State *L ) {
+ if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isboolean( L, 3 ) ) {
+ TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.Camera3DMoveRight( camera3D camera, float distance, bool moveInWorldPlane )" );
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ size_t cameraId = lua_tointeger( L, 1 );
+ float distance = lua_tonumber( L, 2 );
+ bool moveInWorldPlane = lua_toboolean( L, 3 );
+
+ if ( !validCamera3D( cameraId ) ) {
+ lua_pushboolean( L, false );
+ return 1;
+ }
+
+ CameraMoveRight( state->camera3Ds[ cameraId ], distance, moveInWorldPlane );
+ lua_pushboolean( L, true );
+
+ return 1;
+}
+
+/*
+> success = RL.Camera3DMoveToTarget( camera3D camera, float delta )
+
+Moves the camera position closer/farther to/from the camera target
+
+- Failure return false
+- Success return true
+*/
+int lcoreCamera3DMoveToTarget( lua_State *L ) {
+ if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) ) {
+ TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.Camera3DMoveToTarget( camera3D camera, float delta )" );
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ size_t cameraId = lua_tointeger( L, 1 );
+ float delta = lua_tonumber( L, 2 );
+
+ if ( !validCamera3D( cameraId ) ) {
+ lua_pushboolean( L, false );
+ return 1;
+ }
+
+ CameraMoveToTarget( state->camera3Ds[ cameraId ], delta );
+ lua_pushboolean( L, true );
+
+ return 1;
+}
+
+/*
+> success = RL.Camera3DYaw( camera3D camera, float angle, bool rotateAroundTarget )
+
+Rotates the camera around it's up vector
+Yaw is "looking left and right"
+If rotateAroundTarget is false, the camera rotates around it's position
+Note: angle must be provided in radians
+
+- Failure return false
+- Success return true
+*/
+int lcoreCamera3DYaw( lua_State *L ) {
+ if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isboolean( L, 3 ) ) {
+ TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.Camera3DYaw( camera3D camera, float angle, bool rotateAroundTarget )" );
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ size_t cameraId = lua_tointeger( L, 1 );
+ float delta = lua_tonumber( L, 2 );
+ bool rotateAroundTarget = lua_toboolean( L, 3 );
+
+ if ( !validCamera3D( cameraId ) ) {
+ lua_pushboolean( L, false );
+ return 1;
+ }
+
+ CameraYaw( state->camera3Ds[ cameraId ], delta, rotateAroundTarget );
+ lua_pushboolean( L, true );
+
+ return 1;
+}
+
+/*
+> success = RL.Camera3DPitch( camera3D camera, float angle, bool lockView, bool rotateAroundTarget, bool rotateUp )
+
+Rotates the camera around it's right vector, pitch is "looking up and down"
+ - lockView prevents camera overrotation (aka "somersaults")
+ - rotateAroundTarget defines if rotation is around target or around it's position
+ - rotateUp rotates the up direction as well (typically only usefull in CAMERA_FREE)
+NOTE: angle must be provided in radians
+
+- Failure return false
+- Success return true
+*/
+int lcoreCamera3DPitch( lua_State *L ) {
+ if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isboolean( L, 3 )
+ || !lua_isboolean( L, 4 ) || !lua_isboolean( L, 5 ) ) {
+ TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.Camera3DYaw( camera3D camera, float angle, bool rotateAroundTarget )" );
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ size_t cameraId = lua_tointeger( L, 1 );
+ float delta = lua_tonumber( L, 2 );
+ bool lockView = lua_toboolean( L, 3 );
+ bool rotateAroundTarget = lua_toboolean( L, 4 );
+ bool rotateUp = lua_toboolean( L, 5 );
+
+ if ( !validCamera3D( cameraId ) ) {
+ lua_pushboolean( L, false );
+ return 1;
+ }
+
+ CameraPitch( state->camera3Ds[ cameraId ], delta, lockView, rotateAroundTarget, rotateUp );
+ lua_pushboolean( L, true );
+
+ return 1;
+}
+
+/*
+> success = RL.Camera3DRoll( camera3D camera, float angle )
+
+Rotates the camera around it's forward vector
+Roll is "turning your head sideways to the left or right"
+Note: angle must be provided in radians
+
+- Failure return false
+- Success return true
+*/
+int lcoreCamera3DRoll( lua_State *L ) {
+ if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) ) {
+ TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.Camera3DRoll( camera3D camera, float angle )" );
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ size_t cameraId = lua_tointeger( L, 1 );
+ float angle = lua_tonumber( L, 2 );
+
+ if ( !validCamera3D( cameraId ) ) {
+ lua_pushboolean( L, false );
+ return 1;
+ }
+
+ CameraRoll( state->camera3Ds[ cameraId ], angle );
+ lua_pushboolean( L, true );
+
+ return 1;
+}
+
+/*
+> view = RL.GetCamera3DViewMatrix( camera3D camera )
+
+Returns the camera view matrix
+
+- Failure return false
+- Success return Matrix
+*/
+int lcoreGetCamera3DViewMatrix( lua_State *L ) {
+ if ( !lua_isnumber( L, 1 ) ) {
+ TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GetCamera3DViewMatrix( camera3D camera )" );
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ size_t cameraId = lua_tointeger( L, 1 );
+
+ if ( !validCamera3D( cameraId ) ) {
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ uluaPushMatrix( L, GetCameraViewMatrix( state->camera3Ds[ cameraId ] ) );
+
+ return 1;
+}
+
+/*
+> projection = RL.GetCamera3DProjectionMatrix( camera3D camera, float aspect )
+
+Returns the camera projection matrix
+
+- Failure return false
+- Success return Matrix
+*/
+int lcoreGetCamera3DProjectionMatrix( lua_State *L ) {
+ if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) ) {
+ TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GetCamera3DProjectionMatrix( camera3D camera, float aspect )" );
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ size_t cameraId = lua_tointeger( L, 1 );
+ float aspect = lua_tonumber( L, 2 );
+
+ if ( !validCamera3D( cameraId ) ) {
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ uluaPushMatrix( L, GetCameraProjectionMatrix( state->camera3Ds[ cameraId ], aspect ) );
+
+ return 1;
+}
+
+/*
> success = RL.UpdateCamera3D( camera3D camera, int mode )
Update camera position for selected mode
diff --git a/src/lua_core.c b/src/lua_core.c
index ea0851b..dae916e 100644
--- a/src/lua_core.c
+++ b/src/lua_core.c
@@ -814,13 +814,20 @@ void luaRegister() {
assingGlobalFunction( "GetCamera3DUp", lcoreGetCamera3DUp );
assingGlobalFunction( "GetCamera3DFovy", lcoreGetCamera3DFovy );
assingGlobalFunction( "GetCamera3DProjection", lcoreGetCamera3DProjection );
+ assingGlobalFunction( "GetCamera3DForward", lcoreGetCamera3DForward );
+ assingGlobalFunction( "GetCamera3DUpNormalized", lcoreGetCamera3DUpNormalized );
+ assingGlobalFunction( "GetCamera3DRight", lcoreGetCamera3DRight );
+ assingGlobalFunction( "Camera3DMoveForward", lcoreCamera3DMoveForward );
+ assingGlobalFunction( "Camera3DMoveUp", lcoreCamera3DMoveUp );
+ assingGlobalFunction( "Camera3DMoveRight", lcoreCamera3DMoveRight );
+ assingGlobalFunction( "Camera3DMoveToTarget", lcoreCamera3DMoveToTarget );
+ assingGlobalFunction( "Camera3DYaw", lcoreCamera3DYaw );
+ assingGlobalFunction( "Camera3DPitch", lcoreCamera3DPitch );
+ assingGlobalFunction( "Camera3DRoll", lcoreCamera3DRoll );
+ assingGlobalFunction( "GetCamera3DViewMatrix", lcoreGetCamera3DViewMatrix );
+ assingGlobalFunction( "GetCamera3DProjectionMatrix", lcoreGetCamera3DProjectionMatrix );
assingGlobalFunction( "UpdateCamera3D", lcoreUpdateCamera3D );
assingGlobalFunction( "UpdateCamera3DPro", lcoreUpdateCamera3DPro );
- // assingGlobalFunction( "SetCameraMode", lcoreSetCameraMode );
- // assingGlobalFunction( "SetCameraPanControl", lcoreSetCameraPanControl );
- // assingGlobalFunction( "SetCameraAltControl", lcoreSetCameraAltControl );
- // assingGlobalFunction( "SetCameraSmoothZoomControl", lcoreSetCameraSmoothZoomControl );
- // assingGlobalFunction( "SetCameraMoveControls", lcoreSetCameraMoveControls );
/* Input-related Keyboard. */
assingGlobalFunction( "IsKeyPressed", lcoreIsKeyPressed );
assingGlobalFunction( "IsKeyDown", lcoreIsKeyDown );