Added initial files.
This commit is contained in:
272
src/audio.c
Normal file
272
src/audio.c
Normal file
@@ -0,0 +1,272 @@
|
||||
#include "main.h"
|
||||
#include "state.h"
|
||||
#include "audio.h"
|
||||
#include "lua_core.h"
|
||||
|
||||
static bool validSound( size_t id ) {
|
||||
if ( id < 0 || state->soundCount < id || state->sounds[ id ] == NULL ) {
|
||||
TraceLog( LOG_WARNING, "%s %d", "Invalid sound", id );
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
static void checkSoundRealloc( int i ) {
|
||||
if ( i == state->soundCount ) {
|
||||
state->soundCount++;
|
||||
}
|
||||
|
||||
if ( state->soundCount == state->soundAlloc ) {
|
||||
state->soundAlloc += ALLOC_PAGE_SIZE;
|
||||
state->sounds = realloc( state->sounds, state->soundAlloc * sizeof( Sound* ) );
|
||||
|
||||
for ( i = state->soundCount; i < state->soundAlloc; i++ ) {
|
||||
state->sounds[i] = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
## Audio - Sounds
|
||||
*/
|
||||
|
||||
/*
|
||||
> sound = RL_LoadSound( string fileName )
|
||||
|
||||
Load sound from file
|
||||
|
||||
- Failure return -1
|
||||
- Success return int
|
||||
*/
|
||||
int laudioLoadSound( lua_State *L ) {
|
||||
if ( !lua_isstring( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_LoadSound( string fileName )" );
|
||||
lua_pushinteger( L, -1 );
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ( FileExists( lua_tostring( L, -1 ) ) ) {
|
||||
int i = 0;
|
||||
|
||||
for ( i = 0; i < state->soundCount; i++ ) {
|
||||
if ( state->sounds[i] == NULL ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
state->sounds[i] = malloc( sizeof( Sound ) );
|
||||
*state->sounds[i] = LoadSound( lua_tostring( L, -1 ) );
|
||||
lua_pushinteger( L, i );
|
||||
checkSoundRealloc( i );
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> success = RL_PlaySoundMulti( Sound sound )
|
||||
|
||||
Play a sound ( Using multichannel buffer pool )
|
||||
|
||||
- Failure return false
|
||||
- Success return true
|
||||
*/
|
||||
int laudioPlaySoundMulti( lua_State *L ) {
|
||||
if ( !lua_isnumber( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_PlaySoundMulti( Sound sound )" );
|
||||
lua_pushboolean( L, false );
|
||||
return 1;
|
||||
}
|
||||
if ( !validSound( lua_tointeger( L, -1 ) ) ) {
|
||||
lua_pushboolean( L, false );
|
||||
return 1;
|
||||
}
|
||||
PlaySoundMulti( *state->sounds[ lua_tointeger( L, -1 ) ] );
|
||||
lua_pushboolean( L, true );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> success = RL_SetSoundVolume( Sound sound, float volume )
|
||||
|
||||
Set volume for a sound ( 1.0 is max level )
|
||||
|
||||
- Failure return false
|
||||
- Success return true
|
||||
*/
|
||||
int laudioSetSoundVolume( lua_State *L ) {
|
||||
if ( !lua_isnumber( L, -2 ) || !lua_isnumber( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_SetSoundVolume( Sound sound, float volume )" );
|
||||
lua_pushboolean( L, false );
|
||||
return 1;
|
||||
}
|
||||
if ( !validSound( lua_tointeger( L, -2 ) ) ) {
|
||||
lua_pushboolean( L, false );
|
||||
return 1;
|
||||
}
|
||||
SetSoundVolume( *state->sounds[ lua_tointeger( L, -2 ) ], lua_tonumber( L, -1 ) );
|
||||
lua_pushboolean( L, true );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> success = RL_SetSoundPitch( Sound sound, float pitch )
|
||||
|
||||
Set pitch for a sound ( 1.0 is base level )
|
||||
|
||||
- Failure return false
|
||||
- Success return true
|
||||
*/
|
||||
int laudioSetSoundPitch( lua_State *L ) {
|
||||
if ( !lua_isnumber( L, -2 ) || !lua_isnumber( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_SetSoundPitch( Sound sound, float pitch )" );
|
||||
lua_pushboolean( L, false );
|
||||
return 1;
|
||||
}
|
||||
if ( !validSound( lua_tointeger( L, -2 ) ) ) {
|
||||
lua_pushboolean( L, false );
|
||||
return 1;
|
||||
}
|
||||
SetSoundPitch( *state->sounds[ lua_tointeger( L, -2 ) ], lua_tonumber( L, -1 ) );
|
||||
lua_pushboolean( L, true );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> success = RL_UnloadSound( Sound sound )
|
||||
|
||||
Unload sound
|
||||
|
||||
- Failure return false
|
||||
- Success return true
|
||||
*/
|
||||
int laudioUnloadSound( lua_State *L ) {
|
||||
if ( !lua_isnumber( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_UnloadSound( Sound sound )" );
|
||||
lua_pushboolean( L, false );
|
||||
return 1;
|
||||
}
|
||||
size_t id = lua_tointeger( L, -1 );
|
||||
|
||||
if ( !validSound( id ) ) {
|
||||
lua_pushboolean( L, false );
|
||||
return 1;
|
||||
}
|
||||
UnloadSound( *state->sounds[ id ] );
|
||||
state->sounds[ id ] = NULL;
|
||||
lua_pushboolean( L, true );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
## Audio - Music
|
||||
*/
|
||||
|
||||
/*
|
||||
> success = RL_LoadMusicStream( string fileName )
|
||||
|
||||
Load music stream from file
|
||||
|
||||
- Failure return false
|
||||
- Success return true
|
||||
*/
|
||||
int laudioLoadMusicStream( lua_State *L ) {
|
||||
if ( !lua_isstring( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_LoadMusicStream( string fileName )" );
|
||||
lua_pushboolean( L, false );
|
||||
return 1;
|
||||
}
|
||||
if ( FileExists( lua_tostring( L, -1 ) ) ) {
|
||||
state->music = LoadMusicStream( lua_tostring( L, -1 ) );
|
||||
state->music.looping = false;
|
||||
|
||||
lua_pushboolean( L, true );
|
||||
}
|
||||
else {
|
||||
lua_pushboolean( L, false );
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> PlayMusicStream()
|
||||
|
||||
Start music playing
|
||||
*/
|
||||
int laudioPlayMusicStream( lua_State *L ) {
|
||||
PlayMusicStream( state->music );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> StopMusicStream()
|
||||
|
||||
Stop music playing
|
||||
*/
|
||||
int laudioStopMusicStream( lua_State *L ) {
|
||||
StopMusicStream( state->music );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> PauseMusicStream()
|
||||
|
||||
Pause music playing
|
||||
*/
|
||||
int laudioPauseMusicStream( lua_State *L ) {
|
||||
PauseMusicStream( state->music );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> ResumeMusicStream()
|
||||
|
||||
Resume playing paused music
|
||||
*/
|
||||
int laudioResumeMusicStream( lua_State *L ) {
|
||||
ResumeMusicStream( state->music );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> playing = PlayMusicStream()
|
||||
|
||||
Check if music is playing
|
||||
|
||||
- Success return bool
|
||||
*/
|
||||
int laudioIsMusicStreamPlaying( lua_State *L ) {
|
||||
lua_pushboolean( L, IsMusicStreamPlaying( state->music ) );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> success = RL_SetMusicVolume( float volume )
|
||||
|
||||
Set volume for music ( 1.0 is max level )
|
||||
|
||||
- Failure return false
|
||||
- Success return true
|
||||
*/
|
||||
int laudioSetMusicVolume( lua_State *L ) {
|
||||
if ( !lua_isnumber( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_SetMusicVolume( float volume )" );
|
||||
lua_pushboolean( L, false );
|
||||
return 1;
|
||||
}
|
||||
SetMusicVolume( state->music, lua_tonumber( L, -1 ) );
|
||||
lua_pushboolean( L, true );
|
||||
|
||||
return 1;
|
||||
}
|
||||
1908
src/core.c
Normal file
1908
src/core.c
Normal file
File diff suppressed because it is too large
Load Diff
1033
src/lua_core.c
Normal file
1033
src/lua_core.c
Normal file
File diff suppressed because it is too large
Load Diff
37
src/main.c
Normal file
37
src/main.c
Normal file
@@ -0,0 +1,37 @@
|
||||
#include "main.h"
|
||||
#include "state.h"
|
||||
#include "lua_core.h"
|
||||
|
||||
int main( int argn, const char **argc ) {
|
||||
char exePath[ STRING_LEN ] = { '\0' };
|
||||
|
||||
if ( 1 < argn ) {
|
||||
if ( strcmp( argc[1], "--version" ) == 0 || strcmp( argc[1], "-v" ) == 0 ) {
|
||||
printf( "ReiLua %d.%d\n", VERSION_MAJOR, VERSION_MINOR );
|
||||
|
||||
return 1;
|
||||
}
|
||||
else{
|
||||
sprintf( exePath, "%s/%s", GetWorkingDirectory(), argc[1] );
|
||||
}
|
||||
}
|
||||
else {
|
||||
sprintf( exePath, "%s/", GetWorkingDirectory() );
|
||||
}
|
||||
|
||||
stateInit( exePath );
|
||||
|
||||
while ( state->run ) {
|
||||
if ( WindowShouldClose() ) {
|
||||
state->run = false;
|
||||
}
|
||||
if ( IsAudioDeviceReady() ) {
|
||||
UpdateMusicStream( state->music );
|
||||
}
|
||||
luaCallProcess();
|
||||
luaCallDraw();
|
||||
}
|
||||
stateFree();
|
||||
|
||||
return 1;
|
||||
}
|
||||
2113
src/models.c
Normal file
2113
src/models.c
Normal file
File diff suppressed because it is too large
Load Diff
544
src/rgui.c
Normal file
544
src/rgui.c
Normal file
@@ -0,0 +1,544 @@
|
||||
#include "main.h"
|
||||
#include "state.h"
|
||||
#include "rgui.h"
|
||||
#include "lua_core.h"
|
||||
|
||||
#define RAYGUI_IMPLEMENTATION
|
||||
#include "raygui.h"
|
||||
|
||||
/*
|
||||
## Gui - Global
|
||||
*/
|
||||
|
||||
/*
|
||||
> RL_GuiEnable()
|
||||
|
||||
Enable gui controls ( Global state )
|
||||
*/
|
||||
int lguiGuiEnable( lua_State *L ) {
|
||||
GuiEnable();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> RL_GuiDisable()
|
||||
|
||||
Disable gui controls ( Global state )
|
||||
*/
|
||||
int lguiGuiDisable( lua_State *L ) {
|
||||
GuiDisable();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> RL_GuiLock()
|
||||
|
||||
Lock gui controls ( Global state )
|
||||
*/
|
||||
int lguiGuiLock( lua_State *L ) {
|
||||
GuiLock();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> RL_GuiUnlock()
|
||||
|
||||
Unlock gui controls ( Global state )
|
||||
*/
|
||||
int lguiGuiUnlock( lua_State *L ) {
|
||||
GuiUnlock();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
## Gui - Font
|
||||
*/
|
||||
|
||||
/*
|
||||
> success = RL_GuiSetFont( Font font )
|
||||
|
||||
Set gui custom font ( Global state )
|
||||
|
||||
- Failure return false
|
||||
- Success return true
|
||||
*/
|
||||
int lguiGuiSetFont( lua_State *L ) {
|
||||
if ( !lua_isnumber( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GuiSetFont( Font font )" );
|
||||
lua_pushboolean( L, false );
|
||||
return 1;
|
||||
}
|
||||
GuiSetFont( *state->fonts[ lua_tointeger( L, -1 ) ] );
|
||||
lua_pushboolean( L, true );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
## Gui - Container
|
||||
*/
|
||||
|
||||
/*
|
||||
> state = RL_GuiWindowBox( Rectangle bounds, string title )
|
||||
|
||||
Window Box control, shows a window that can be closed
|
||||
|
||||
- Failure return nil
|
||||
- Success return bool
|
||||
*/
|
||||
int lguiGuiWindowBox( lua_State *L ) {
|
||||
if ( !lua_istable( L, -2 ) || !lua_isstring( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GuiWindowBox( Rectangle bounds, string title )" );
|
||||
lua_pushnil( L );
|
||||
return 1;
|
||||
}
|
||||
char text[ STRING_LEN ] = { '\0' };
|
||||
strcpy( text, lua_tostring( L, -1 ) );
|
||||
lua_pop( L, 1 );
|
||||
Rectangle rect = uluaGetRectangle( L );
|
||||
|
||||
lua_pushboolean( L, GuiWindowBox( rect, text ) );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> success = RL_GuiPanel( Rectangle bounds )
|
||||
|
||||
Panel control, useful to group controls
|
||||
|
||||
- Failure return false
|
||||
- Success return true
|
||||
*/
|
||||
int lguiGuiPanel( lua_State *L ) {
|
||||
if ( !lua_istable( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GuiPanel( Rectangle bounds )" );
|
||||
lua_pushboolean( L, false );
|
||||
return 1;
|
||||
}
|
||||
Rectangle rect = uluaGetRectangle( L );
|
||||
|
||||
GuiPanel( rect );
|
||||
lua_pushboolean( L, true );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> view, scroll = RL_GuiScrollPanel( Rectangle bounds, Rectangle content, Vector2 scroll )
|
||||
|
||||
Scroll Panel control
|
||||
|
||||
- Failure return false
|
||||
- Success return Rectangle, Vector2
|
||||
*/
|
||||
int lguiGuiScrollPanel( lua_State *L ) {
|
||||
if ( !lua_istable( L, -3 ) || !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GuiScrollPanel( Rectangle bounds, Rectangle content, Vector2 scroll )" );
|
||||
lua_pushboolean( L, false );
|
||||
return 1;
|
||||
}
|
||||
Vector2 scroll = uluaGetVector2( L );
|
||||
lua_pop( L, 1 );
|
||||
Rectangle content = uluaGetRectangle( L );
|
||||
lua_pop( L, 1 );
|
||||
Rectangle bounds = uluaGetRectangle( L );
|
||||
|
||||
uluaPushRectangle( L, GuiScrollPanel( bounds, content, &scroll ) );
|
||||
uluaPushVector2( L, scroll );
|
||||
|
||||
return 2;
|
||||
}
|
||||
|
||||
/*
|
||||
## Gui - Basic
|
||||
*/
|
||||
|
||||
/*
|
||||
> success = RL_GuiLabel( Rectangle bounds, string text )
|
||||
|
||||
Label control, shows text
|
||||
|
||||
- Failure return false
|
||||
- Success return true
|
||||
*/
|
||||
int lguiGuiLabel( lua_State *L ) {
|
||||
if ( !lua_istable( L, -2 ) || !lua_isstring( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GuiLabel( Rectangle bounds, string text )" );
|
||||
lua_pushboolean( L, false );
|
||||
return 1;
|
||||
}
|
||||
char text[ STRING_LEN ] = { '\0' };
|
||||
strcpy( text, lua_tostring( L, -1 ) );
|
||||
lua_pop( L, 1 );
|
||||
Rectangle rect = uluaGetRectangle( L );
|
||||
|
||||
GuiLabel( rect, text );
|
||||
lua_pushboolean( L, true );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> clicked = RL_GuiButton( Rectangle bounds, string text )
|
||||
|
||||
Button control, returns true when clicked
|
||||
|
||||
- Failure return nil
|
||||
- Success return boolean
|
||||
*/
|
||||
int lguiGuiButton( lua_State *L ) {
|
||||
if ( !lua_istable( L, -2 ) || !lua_isstring( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GuiButton( Rectangle bounds, string text )" );
|
||||
lua_pushnil( L );
|
||||
return 1;
|
||||
}
|
||||
char text[ STRING_LEN ] = { '\0' };
|
||||
strcpy( text, lua_tostring( L, -1 ) );
|
||||
lua_pop( L, 1 );
|
||||
Rectangle rect = uluaGetRectangle( L );
|
||||
|
||||
lua_pushboolean( L, GuiButton( rect, text ) );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> active = RL_GuiToggle( Rectangle bounds, string text, bool active )
|
||||
|
||||
Toggle Button control, returns true when active
|
||||
|
||||
- Failure return nil
|
||||
- Success return boolean
|
||||
*/
|
||||
int lguiGuiToggle( lua_State *L ) {
|
||||
if ( !lua_istable( L, -3 ) || !lua_isstring( L, -2 ) || !lua_isboolean( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GuiToggle( Rectangle bounds, string text, bool active )" );
|
||||
lua_pushnil( L );
|
||||
return 1;
|
||||
}
|
||||
bool checked = lua_toboolean( L, -1 );
|
||||
lua_pop( L, 1 );
|
||||
char text[ STRING_LEN ] = { '\0' };
|
||||
strcpy( text, lua_tostring( L, -1 ) );
|
||||
lua_pop( L, 1 );
|
||||
Rectangle rect = uluaGetRectangle( L );
|
||||
|
||||
lua_pushboolean( L, GuiToggle( rect, text, checked ) );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> active = RL_GuiCheckBox( Rectangle bounds, string text, bool checked )
|
||||
|
||||
Check Box control, returns true when active
|
||||
|
||||
- Failure return nil
|
||||
- Success return boolean
|
||||
*/
|
||||
int lguiGuiCheckBox( lua_State *L ) {
|
||||
if ( !lua_istable( L, -3 ) || !lua_isstring( L, -2 ) || !lua_isboolean( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GuiCheckBox( Rectangle bounds, string text, bool checked )" );
|
||||
lua_pushnil( L );
|
||||
return 1;
|
||||
}
|
||||
bool checked = lua_toboolean( L, -1 );
|
||||
lua_pop( L, 1 );
|
||||
char text[ STRING_LEN ] = { '\0' };
|
||||
strcpy( text, lua_tostring( L, -1 ) );
|
||||
lua_pop( L, 1 );
|
||||
Rectangle rect = uluaGetRectangle( L );
|
||||
|
||||
lua_pushboolean( L, GuiCheckBox( rect, text, checked ) );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> pressed, text = RL_GuiTextBox( Rectangle bounds, string text, int textSize, bool editMode )
|
||||
|
||||
Text Box control, updates input text
|
||||
|
||||
- Failure return nil
|
||||
- Success return boolean, string
|
||||
*/
|
||||
int lguiGuiTextBox( lua_State *L ) {
|
||||
if ( !lua_istable( L, -4 ) || !lua_isstring( L, -3 ) || !lua_isnumber( L, -2 ) || !lua_isboolean( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GuiTextBox( Rectangle bounds, string text, int textSize, bool editMode )" );
|
||||
lua_pushnil( L );
|
||||
return 1;
|
||||
}
|
||||
bool editMode = lua_toboolean( L, -1 );
|
||||
lua_pop( L, 1 );
|
||||
int textSize = lua_tointeger( L, -1 );
|
||||
lua_pop( L, 1 );
|
||||
char text[ STRING_LEN ] = { '\0' };
|
||||
strcpy( text, lua_tostring( L, -1 ) );
|
||||
lua_pop( L, 1 );
|
||||
Rectangle rect = uluaGetRectangle( L );
|
||||
|
||||
lua_pushboolean( L, GuiTextBox( rect, text, textSize, editMode ) );
|
||||
lua_pushstring( L, text );
|
||||
|
||||
return 2;
|
||||
}
|
||||
|
||||
/*
|
||||
> pressed, text = RL_GuiTextBoxMulti( Rectangle bounds, string text, int textSize, bool editMode )
|
||||
|
||||
Text Box control with multiple lines
|
||||
|
||||
- Failure return nil
|
||||
- Success return boolean, string
|
||||
*/
|
||||
int lguiGuiTextBoxMulti( lua_State *L ) {
|
||||
if ( !lua_istable( L, -4 ) || !lua_isstring( L, -3 ) || !lua_isnumber( L, -2 ) || !lua_isboolean( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GuiTextBoxMulti( Rectangle bounds, string text, int textSize, bool editMode )" );
|
||||
lua_pushnil( L );
|
||||
return 1;
|
||||
}
|
||||
bool editMode = lua_toboolean( L, -1 );
|
||||
lua_pop( L, 1 );
|
||||
int textSize = lua_tointeger( L, -1 );
|
||||
lua_pop( L, 1 );
|
||||
char text[ STRING_LEN ] = { '\0' };
|
||||
strcpy( text, lua_tostring( L, -1 ) );
|
||||
lua_pop( L, 1 );
|
||||
Rectangle rect = uluaGetRectangle( L );
|
||||
|
||||
lua_pushboolean( L, GuiTextBoxMulti( rect, text, textSize, editMode ) );
|
||||
lua_pushstring( L, text );
|
||||
|
||||
return 2;
|
||||
}
|
||||
|
||||
/*
|
||||
> pressed, value = RL_GuiSpinner( Rectangle bounds, string text, int value, int minValue, int maxValue, bool editMode )
|
||||
|
||||
Spinner control, returns selected value
|
||||
|
||||
- Failure return nil
|
||||
- Success return boolean, int
|
||||
*/
|
||||
int lguiGuiSpinner( lua_State *L ) {
|
||||
if ( !lua_istable( L, -6 ) || !lua_isstring( L, -5 ) || !lua_isnumber( L, -4 )
|
||||
|| !lua_isnumber( L, -3 ) || !lua_isnumber( L, -2 ) || !lua_isboolean( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GuiSpinner( Rectangle bounds, string text, int value, int minValue, int maxValue, bool editMode )" );
|
||||
lua_pushnil( L );
|
||||
return 1;
|
||||
}
|
||||
bool editMode = lua_toboolean( L, -1 );
|
||||
lua_pop( L, 1 );
|
||||
int maxValue = lua_tointeger( L, -1 );
|
||||
lua_pop( L, 1 );
|
||||
int minValue = lua_tointeger( L, -1 );
|
||||
lua_pop( L, 1 );
|
||||
int value = lua_tointeger( L, -1 );
|
||||
lua_pop( L, 1 );
|
||||
char text[ STRING_LEN ] = { '\0' };
|
||||
strcpy( text, lua_tostring( L, -1 ) );
|
||||
lua_pop( L, 1 );
|
||||
Rectangle rect = uluaGetRectangle( L );
|
||||
|
||||
lua_pushboolean( L, GuiSpinner( rect, text, &value, minValue, maxValue, editMode ) );
|
||||
lua_pushinteger( L, value );
|
||||
|
||||
return 2;
|
||||
}
|
||||
|
||||
/*
|
||||
> pressed, value = RL_GuiValueBox( Rectangle bounds, string text, int value, int minValue, int maxValue, bool editMode )
|
||||
|
||||
Value Box control, updates input text with numbers
|
||||
|
||||
- Failure return nil
|
||||
- Success return boolean, int
|
||||
*/
|
||||
int lguiGuiValueBox( lua_State *L ) {
|
||||
if ( !lua_istable( L, -6 ) || !lua_isstring( L, -5 ) || !lua_isnumber( L, -4 )
|
||||
|| !lua_isnumber( L, -3 ) || !lua_isnumber( L, -2 ) || !lua_isboolean( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GuiValueBox( Rectangle bounds, string text, int value, int minValue, int maxValue, bool editMode )" );
|
||||
lua_pushnil( L );
|
||||
return 1;
|
||||
}
|
||||
bool editMode = lua_toboolean( L, -1 );
|
||||
lua_pop( L, 1 );
|
||||
int maxValue = lua_tointeger( L, -1 );
|
||||
lua_pop( L, 1 );
|
||||
int minValue = lua_tointeger( L, -1 );
|
||||
lua_pop( L, 1 );
|
||||
int value = lua_tointeger( L, -1 );
|
||||
lua_pop( L, 1 );
|
||||
char text[ STRING_LEN ] = { '\0' };
|
||||
strcpy( text, lua_tostring( L, -1 ) );
|
||||
lua_pop( L, 1 );
|
||||
Rectangle rect = uluaGetRectangle( L );
|
||||
|
||||
lua_pushboolean( L, GuiValueBox( rect, text, &value, minValue, maxValue, editMode ) );
|
||||
lua_pushinteger( L, value );
|
||||
|
||||
return 2;
|
||||
}
|
||||
|
||||
/*
|
||||
> value = RL_GuiSlider( Rectangle bounds, string textLeft, string textRight, float value, float minValue, float maxValue )
|
||||
|
||||
Slider control, returns selected value
|
||||
|
||||
- Failure return nil
|
||||
- Success return float
|
||||
*/
|
||||
int lguiGuiSlider( lua_State *L ) {
|
||||
if ( !lua_istable( L, -6 ) || !lua_isstring( L, -5 ) || !lua_isstring( L, -4 )
|
||||
|| !lua_isnumber( L, -3 ) || !lua_isnumber( L, -2 ) || !lua_isnumber( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GuiSlider( Rectangle bounds, string textLeft, string textRight, float value, float minValue, float maxValue )" );
|
||||
lua_pushnil( L );
|
||||
return 1;
|
||||
}
|
||||
float maxValue = lua_tonumber( L, -1 );
|
||||
lua_pop( L, 1 );
|
||||
float minValue = lua_tonumber( L, -1 );
|
||||
lua_pop( L, 1 );
|
||||
float value = lua_tonumber( L, -1 );
|
||||
lua_pop( L, 1 );
|
||||
char textRight[ STRING_LEN ] = { '\0' };
|
||||
strcpy( textRight, lua_tostring( L, -1 ) );
|
||||
lua_pop( L, 1 );
|
||||
char textLeft[ STRING_LEN ] = { '\0' };
|
||||
strcpy( textLeft, lua_tostring( L, -1 ) );
|
||||
lua_pop( L, 1 );
|
||||
Rectangle rect = uluaGetRectangle( L );
|
||||
|
||||
lua_pushnumber( L, GuiSlider( rect, textLeft, textRight, value, minValue, maxValue ) );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> value = RL_GuiSliderBar( Rectangle bounds, string textLeft, string textRight, float value, float minValue, float maxValue )
|
||||
|
||||
Slider Bar control, returns selected value
|
||||
|
||||
- Failure return nil
|
||||
- Success return float
|
||||
*/
|
||||
int lguiGuiSliderBar( lua_State *L ) {
|
||||
if ( !lua_istable( L, -6 ) || !lua_isstring( L, -5 ) || !lua_isstring( L, -4 )
|
||||
|| !lua_isnumber( L, -3 ) || !lua_isnumber( L, -2 ) || !lua_isnumber( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GuiSliderBar( Rectangle bounds, string textLeft, string textRight, float value, float minValue, float maxValue )" );
|
||||
lua_pushnil( L );
|
||||
return 1;
|
||||
}
|
||||
float maxValue = lua_tonumber( L, -1 );
|
||||
lua_pop( L, 1 );
|
||||
float minValue = lua_tonumber( L, -1 );
|
||||
lua_pop( L, 1 );
|
||||
float value = lua_tonumber( L, -1 );
|
||||
lua_pop( L, 1 );
|
||||
char textRight[ STRING_LEN ] = { '\0' };
|
||||
strcpy( textRight, lua_tostring( L, -1 ) );
|
||||
lua_pop( L, 1 );
|
||||
char textLeft[ STRING_LEN ] = { '\0' };
|
||||
strcpy( textLeft, lua_tostring( L, -1 ) );
|
||||
lua_pop( L, 1 );
|
||||
Rectangle rect = uluaGetRectangle( L );
|
||||
|
||||
lua_pushnumber( L, GuiSliderBar( rect, textLeft, textRight, value, minValue, maxValue ) );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> value = RL_GuiProgressBar( Rectangle bounds, string textLeft, string textRight, float value, float minValue, float maxValue )
|
||||
|
||||
Progress Bar control, shows current progress value
|
||||
|
||||
- Failure return nil
|
||||
- Success return float
|
||||
*/
|
||||
int lguiGuiProgressBar( lua_State *L ) {
|
||||
if ( !lua_istable( L, -6 ) || !lua_isstring( L, -5 ) || !lua_isstring( L, -4 )
|
||||
|| !lua_isnumber( L, -3 ) || !lua_isnumber( L, -2 ) || !lua_isnumber( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GuiProgressBar( Rectangle bounds, string textLeft, string textRight, float value, float minValue, float maxValue )" );
|
||||
lua_pushnil( L );
|
||||
return 1;
|
||||
}
|
||||
float maxValue = lua_tonumber( L, -1 );
|
||||
lua_pop( L, 1 );
|
||||
float minValue = lua_tonumber( L, -1 );
|
||||
lua_pop( L, 1 );
|
||||
float value = lua_tonumber( L, -1 );
|
||||
lua_pop( L, 1 );
|
||||
char textRight[ STRING_LEN ] = { '\0' };
|
||||
strcpy( textRight, lua_tostring( L, -1 ) );
|
||||
lua_pop( L, 1 );
|
||||
char textLeft[ STRING_LEN ] = { '\0' };
|
||||
strcpy( textLeft, lua_tostring( L, -1 ) );
|
||||
lua_pop( L, 1 );
|
||||
Rectangle rect = uluaGetRectangle( L );
|
||||
|
||||
lua_pushnumber( L, GuiProgressBar( rect, textLeft, textRight, value, minValue, maxValue ) );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> value = RL_GuiScrollBar( Rectangle bounds, int value, int minValue, int maxValue )
|
||||
|
||||
Scroll Bar control
|
||||
|
||||
- Failure return nil
|
||||
- Success return int
|
||||
*/
|
||||
int lguiGuiScrollBar( lua_State *L ) {
|
||||
if ( !lua_istable( L, -4 ) || !lua_isnumber( L, -3 ) || !lua_isnumber( L, -2 ) || !lua_isnumber( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GuiScrollBar( Rectangle bounds, int value, int minValue, int maxValue )" );
|
||||
lua_pushnil( L );
|
||||
return 1;
|
||||
}
|
||||
int maxValue = lua_tointeger( L, -1 );
|
||||
lua_pop( L, 1 );
|
||||
int minValue = lua_tointeger( L, -1 );
|
||||
lua_pop( L, 1 );
|
||||
int value = lua_tointeger( L, -1 );
|
||||
lua_pop( L, 1 );
|
||||
Rectangle rect = uluaGetRectangle( L );
|
||||
|
||||
lua_pushinteger( L, GuiScrollBar( rect, value, minValue, maxValue ) );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> pressed, item = RL_GuiDropdownBox( Rectangle bounds, string text, int active, bool editMode )
|
||||
|
||||
Dropdown Box control, returns selected item
|
||||
|
||||
- Failure return nil
|
||||
- Success return bool, int
|
||||
*/
|
||||
int lguiGuiDropdownBox( lua_State *L ) {
|
||||
if ( !lua_istable( L, -4 ) || !lua_isstring( L, -3 ) || !lua_isnumber( L, -2 ) || !lua_isboolean( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GuiDropdownBox( Rectangle bounds, string text, int active, bool editMode )" );
|
||||
lua_pushnil( L );
|
||||
return 1;
|
||||
}
|
||||
bool editMode = lua_toboolean( L, -1 );
|
||||
lua_pop( L, 1 );
|
||||
int active = lua_tointeger( L, -1 );
|
||||
lua_pop( L, 1 );
|
||||
char text[ STRING_LEN ] = { '\0' };
|
||||
strcpy( text, lua_tostring( L, -1 ) );
|
||||
lua_pop( L, 1 );
|
||||
Rectangle rect = uluaGetRectangle( L );
|
||||
|
||||
lua_pushboolean( L, GuiDropdownBox( rect, text, &active, editMode ) );
|
||||
lua_pushinteger( L, active );
|
||||
|
||||
return 2;
|
||||
}
|
||||
978
src/rmath.c
Normal file
978
src/rmath.c
Normal file
@@ -0,0 +1,978 @@
|
||||
#include "main.h"
|
||||
#include "state.h"
|
||||
#include "rmath.h"
|
||||
#include "lua_core.h"
|
||||
|
||||
inline int imin( int a, int b ) {
|
||||
return a < b ? a : b;
|
||||
}
|
||||
|
||||
inline int imax( int a, int b ) {
|
||||
return a > b ? a : b;
|
||||
}
|
||||
|
||||
/*
|
||||
## Math - Vector2
|
||||
*/
|
||||
|
||||
/*
|
||||
> result = RL_Vector2Add( Vector2 v1, Vector2 v2 )
|
||||
|
||||
Add two vectors (v1 + v2)
|
||||
|
||||
- Failure return false
|
||||
- Success return Vector2
|
||||
*/
|
||||
int lmathVector2Add( lua_State *L ) {
|
||||
if ( !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_Vector2Add( Vector2 v1, Vector2 v2 )" );
|
||||
lua_pushboolean( L, false );
|
||||
return 1;
|
||||
}
|
||||
Vector2 v2 = uluaGetVector2( L );
|
||||
lua_pop( L, 1 );
|
||||
Vector2 v1 = uluaGetVector2( L );
|
||||
|
||||
uluaPushVector2( L, Vector2Add( v1, v2 ) );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> result = RL_Vector2Subtract( Vector2 v1, Vector2 v2 )
|
||||
|
||||
Subtract two vectors (v1 - v2)
|
||||
|
||||
- Failure return false
|
||||
- Success return Vector2
|
||||
*/
|
||||
int lmathVector2Subtract( lua_State *L ) {
|
||||
if ( !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_Vector2Subtract( Vector2 v1, Vector2 v2 )" );
|
||||
lua_pushboolean( L, false );
|
||||
return 1;
|
||||
}
|
||||
Vector2 v2 = uluaGetVector2( L );
|
||||
lua_pop( L, 1 );
|
||||
Vector2 v1 = uluaGetVector2( L );
|
||||
|
||||
uluaPushVector2( L, Vector2Subtract( v1, v2 ) );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> result = RL_Vector2Multiply( Vector2 v1, Vector2 v2 )
|
||||
|
||||
Multiply vector by vector
|
||||
|
||||
- Failure return false
|
||||
- Success return Vector2
|
||||
*/
|
||||
int lmathVector2Multiply( lua_State *L ) {
|
||||
if ( !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_Vector2Multiply( Vector2 v1, Vector2 v2 )" );
|
||||
lua_pushboolean( L, false );
|
||||
return 1;
|
||||
}
|
||||
Vector2 v2 = uluaGetVector2( L );
|
||||
lua_pop( L, 1 );
|
||||
Vector2 v1 = uluaGetVector2( L );
|
||||
|
||||
uluaPushVector2( L, Vector2Multiply( v1, v2 ) );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> result = RL_Vector2Length( vector2 vector )
|
||||
|
||||
Calculate vector length
|
||||
|
||||
- Failure return false
|
||||
- Success return float
|
||||
*/
|
||||
int lmathVector2Length( lua_State *L ) {
|
||||
if ( !lua_istable( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_Vector2Length( vector2 v )" );
|
||||
lua_pushboolean( L, false );
|
||||
return 1;
|
||||
}
|
||||
Vector2 v = uluaGetVector2( L );
|
||||
|
||||
lua_pushnumber( L, Vector2Length( v ) );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> result = RL_Vector2DotProduct( Vector2 v1, Vector2 v2 )
|
||||
|
||||
Calculate two vectors dot product
|
||||
|
||||
- Failure return false
|
||||
- Success return float
|
||||
*/
|
||||
int lmathVector2DotProduct( lua_State *L ) {
|
||||
if ( !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_Vector2DotProduct( Vector2 v1, Vector2 v2 )" );
|
||||
lua_pushboolean( L, false );
|
||||
return 1;
|
||||
}
|
||||
Vector2 v2 = uluaGetVector2( L );
|
||||
lua_pop( L, 1 );
|
||||
Vector2 v1 = uluaGetVector2( L );
|
||||
|
||||
lua_pushnumber( L, Vector2DotProduct( v1, v2 ) );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> result = RL_Vector2Distance( Vector2 v1, Vector2 v2 )
|
||||
|
||||
Calculate distance between two vectors
|
||||
|
||||
- Failure return false
|
||||
- Success return float
|
||||
*/
|
||||
int lmathVector2Distance( lua_State *L ) {
|
||||
if ( !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_Vector2Distance( Vector2 v1, Vector2 v2 )" );
|
||||
lua_pushboolean( L, false );
|
||||
return 1;
|
||||
}
|
||||
Vector2 v2 = uluaGetVector2( L );
|
||||
lua_pop( L, 1 );
|
||||
Vector2 v1 = uluaGetVector2( L );
|
||||
|
||||
lua_pushnumber( L, Vector2Distance( v1, v2 ) );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> result = RL_Vector2Angle( Vector2 v1, Vector2 v2 )
|
||||
|
||||
Calculate angle from two vectors
|
||||
|
||||
- Failure return false
|
||||
- Success return float
|
||||
*/
|
||||
int lmathVector2Angle( lua_State *L ) {
|
||||
if ( !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_Vector2Angle( Vector2 v1, Vector2 v2 )" );
|
||||
lua_pushboolean( L, false );
|
||||
return 1;
|
||||
}
|
||||
Vector2 v2 = uluaGetVector2( L );
|
||||
lua_pop( L, 1 );
|
||||
Vector2 v1 = uluaGetVector2( L );
|
||||
|
||||
lua_pushnumber( L, Vector2Angle( v1, v2 ) );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> result = RL_Vector2Normalize( Vector2 v )
|
||||
|
||||
Normalize provided vector
|
||||
|
||||
- Failure return false
|
||||
- Success return Vector2
|
||||
*/
|
||||
int lmathVector2Normalize( lua_State *L ) {
|
||||
if ( !lua_istable( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_Vector2Normalize( Vector2 v )" );
|
||||
lua_pushboolean( L, false );
|
||||
return 1;
|
||||
}
|
||||
Vector2 v = Vector2Normalize( uluaGetVector2( L ) );
|
||||
|
||||
uluaPushVector2( L, v );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> result = RL_Vector2Lerp( Vector2 v1, Vector2 v2, float amount )
|
||||
|
||||
Calculate linear interpolation between two vectors
|
||||
|
||||
- Failure return false
|
||||
- Success return Vector2
|
||||
*/
|
||||
int lmathVector2Lerp( lua_State *L ) {
|
||||
if ( !lua_istable( L, -3 ) || !lua_istable( L, -2 ) || !lua_isnumber( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_Vector2Lerp( Vector2 v1, Vector2 v2, float amount )" );
|
||||
lua_pushboolean( L, false );
|
||||
return 1;
|
||||
}
|
||||
float amount = lua_tonumber( L, -1 );
|
||||
lua_pop( L, 1 );
|
||||
Vector2 v2 = uluaGetVector2( L );
|
||||
lua_pop( L, 1 );
|
||||
Vector2 v1 = uluaGetVector2( L );
|
||||
|
||||
uluaPushVector2( L, Vector2Lerp( v1, v2, amount ) );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> result = RL_Vector2Reflect( Vector2 v, Vector2 normal )
|
||||
|
||||
Calculate reflected vector to normal
|
||||
|
||||
- Failure return false
|
||||
- Success return Vector2
|
||||
*/
|
||||
int lmathVector2Reflect( lua_State *L ) {
|
||||
if ( !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_Vector2Reflect( Vector2 v, Vector2 normal )" );
|
||||
lua_pushboolean( L, false );
|
||||
return 1;
|
||||
}
|
||||
Vector2 v2 = uluaGetVector2( L );
|
||||
lua_pop( L, 1 );
|
||||
Vector2 v1 = uluaGetVector2( L );
|
||||
|
||||
uluaPushVector2( L, Vector2Reflect( v1, v2 ) );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> result = RL_Vector2Rotate( Vector2 v, float angle )
|
||||
|
||||
Rotate vector by angle
|
||||
|
||||
- Failure return false
|
||||
- Success return Vector2
|
||||
*/
|
||||
int lmathVector2Rotate( lua_State *L ) {
|
||||
if ( !lua_istable( L, -2 ) || !lua_isnumber( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_Vector2Rotate( Vector2 v, float angle )" );
|
||||
lua_pushboolean( L, false );
|
||||
return 1;
|
||||
}
|
||||
float degs = lua_tonumber( L, -1 );
|
||||
lua_pop( L, 1 );
|
||||
Vector2 v = uluaGetVector2( L );
|
||||
|
||||
uluaPushVector2( L, Vector2Rotate( v, degs ) );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> result = RL_Vector2MoveTowards( Vector2 v, Vector2 target, float maxDistance )
|
||||
|
||||
Move Vector towards target
|
||||
|
||||
- Failure return false
|
||||
- Success return Vector2
|
||||
*/
|
||||
int lmathVector2MoveTowards( lua_State *L ) {
|
||||
if ( !lua_istable( L, -3 ) || !lua_istable( L, -2 ) || !lua_isnumber( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_Vector2MoveTowards( Vector2 v, Vector2 target, float maxDistance )" );
|
||||
lua_pushboolean( L, false );
|
||||
return 1;
|
||||
}
|
||||
float maxDistance = lua_tonumber( L, -1 );
|
||||
lua_pop( L, 1 );
|
||||
Vector2 v2 = uluaGetVector2( L );
|
||||
lua_pop( L, 1 );
|
||||
Vector2 v1 = uluaGetVector2( L );
|
||||
|
||||
uluaPushVector2( L, Vector2MoveTowards( v1, v2, maxDistance ) );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
## Math - Vector 3
|
||||
*/
|
||||
|
||||
/*
|
||||
> result = RL_Vector3CrossProduct( Vector3 v1, Vector3 v2 )
|
||||
|
||||
Add two vectors
|
||||
|
||||
- Failure return false
|
||||
- Success return Vector3
|
||||
*/
|
||||
int lmathVector3Add( lua_State *L ) {
|
||||
if ( !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_Vector3Add( Vector3 v1, Vector3 v2 )" );
|
||||
lua_pushboolean( L, false );
|
||||
return 1;
|
||||
}
|
||||
Vector3 v2 = uluaGetVector3( L );
|
||||
lua_pop( L, 1 );
|
||||
Vector3 v1 = uluaGetVector3( L );
|
||||
|
||||
uluaPushVector3( L, Vector3Add( v1, v2 ) );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> result = RL_Vector3Subtract( Vector3 v1, Vector3 v2 )
|
||||
|
||||
Subtract two vectors
|
||||
|
||||
- Failure return false
|
||||
- Success return Vector3
|
||||
*/
|
||||
int lmathVector3Subtract( lua_State *L ) {
|
||||
if ( !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_Vector3Subtract( Vector3 v1, Vector3 v2 )" );
|
||||
lua_pushboolean( L, false );
|
||||
return 1;
|
||||
}
|
||||
Vector3 v2 = uluaGetVector3( L );
|
||||
lua_pop( L, 1 );
|
||||
Vector3 v1 = uluaGetVector3( L );
|
||||
|
||||
uluaPushVector3( L, Vector3Subtract( v1, v2 ) );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> result = RL_Vector3Subtract( Vector3 v1, Vector3 v2 )
|
||||
|
||||
Multiply vector by vector
|
||||
|
||||
- Failure return false
|
||||
- Success return Vector3
|
||||
*/
|
||||
int lmathVector3Multiply( lua_State *L ) {
|
||||
if ( !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_Vector3Multiply( Vector3 v1, Vector3 v2 )" );
|
||||
lua_pushboolean( L, false );
|
||||
return 1;
|
||||
}
|
||||
Vector3 v2 = uluaGetVector3( L );
|
||||
lua_pop( L, 1 );
|
||||
Vector3 v1 = uluaGetVector3( L );
|
||||
|
||||
uluaPushVector3( L, Vector3Multiply( v1, v2 ) );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> result = RL_Vector3CrossProduct( Vector3 v1, Vector3 v2 )
|
||||
|
||||
Calculate two vectors cross product
|
||||
|
||||
- Failure return false
|
||||
- Success return Vector3
|
||||
*/
|
||||
int lmathVector3CrossProduct( lua_State *L ) {
|
||||
if ( !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_Vector3CrossProduct( Vector3 v1, Vector3 v2 )" );
|
||||
lua_pushboolean( L, false );
|
||||
return 1;
|
||||
}
|
||||
Vector3 v2 = uluaGetVector3( L );
|
||||
lua_pop( L, 1 );
|
||||
Vector3 v1 = uluaGetVector3( L );
|
||||
|
||||
uluaPushVector3( L, Vector3CrossProduct( v1, v2 ) );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> result = RL_Vector3Perpendicular( Vector3 v )
|
||||
|
||||
Calculate one vector perpendicular vector
|
||||
|
||||
- Failure return false
|
||||
- Success return Vector3
|
||||
*/
|
||||
int lmathVector3Perpendicular( lua_State *L ) {
|
||||
if ( !lua_istable( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_Vector3Perpendicular( Vector3 v )" );
|
||||
lua_pushboolean( L, false );
|
||||
return 1;
|
||||
}
|
||||
Vector3 v = uluaGetVector3( L );
|
||||
|
||||
uluaPushVector3( L, Vector3Perpendicular( v ) );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> result = RL_Vector3Length( Vector3 v )
|
||||
|
||||
Calculate one vector perpendicular vector
|
||||
|
||||
- Failure return false
|
||||
- Success return float
|
||||
*/
|
||||
int lmathVector3Length( lua_State *L ) {
|
||||
if ( !lua_istable( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_Vector3Length( Vector3 v )" );
|
||||
lua_pushboolean( L, false );
|
||||
return 1;
|
||||
}
|
||||
Vector3 v = uluaGetVector3( L );
|
||||
|
||||
lua_pushnumber( L, Vector3Length( v ) );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> result = RL_Vector3LengthSqr( Vector3 v )
|
||||
|
||||
Calculate vector square length
|
||||
|
||||
- Failure return false
|
||||
- Success return float
|
||||
*/
|
||||
int lmathVector3LengthSqr( lua_State *L ) {
|
||||
if ( !lua_istable( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_Vector3LengthSqr( Vector3 v )" );
|
||||
lua_pushboolean( L, false );
|
||||
return 1;
|
||||
}
|
||||
Vector3 v = uluaGetVector3( L );
|
||||
|
||||
lua_pushnumber( L, Vector3LengthSqr( v ) );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> result = RL_Vector3DotProduct( Vector3 v1, Vector3 v2 )
|
||||
|
||||
Calculate two vectors dot product
|
||||
|
||||
- Failure return false
|
||||
- Success return float
|
||||
*/
|
||||
int lmathVector3DotProduct( lua_State *L ) {
|
||||
if ( !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_Vector3DotProduct( Vector3 v1, Vector3 v2 )" );
|
||||
lua_pushboolean( L, false );
|
||||
return 1;
|
||||
}
|
||||
Vector3 v2 = uluaGetVector3( L );
|
||||
lua_pop( L, 1 );
|
||||
Vector3 v1 = uluaGetVector3( L );
|
||||
|
||||
lua_pushnumber( L, Vector3DotProduct( v1, v2 ) );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> result = RL_Vector3Distance( Vector3 v1, Vector3 v2 )
|
||||
|
||||
Calculate distance between two vectors
|
||||
|
||||
- Failure return false
|
||||
- Success return float
|
||||
*/
|
||||
int lmathVector3Distance( lua_State *L ) {
|
||||
if ( !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_Vector3Distance( Vector3 v1, Vector3 v2 )" );
|
||||
lua_pushboolean( L, false );
|
||||
return 1;
|
||||
}
|
||||
Vector3 v2 = uluaGetVector3( L );
|
||||
lua_pop( L, 1 );
|
||||
Vector3 v1 = uluaGetVector3( L );
|
||||
|
||||
lua_pushnumber( L, Vector3Distance( v1, v2 ) );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> result = RL_Vector3Normalize( Vector3 v )
|
||||
|
||||
Normalize provided vector
|
||||
|
||||
- Failure return false
|
||||
- Success return Vector3
|
||||
*/
|
||||
int lmathVector3Normalize( lua_State *L ) {
|
||||
/* Vector. */
|
||||
if ( !lua_istable( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_Vector3Normalize( Vector3 v )" );
|
||||
lua_pushboolean( L, false );
|
||||
return 1;
|
||||
}
|
||||
Vector3 v = uluaGetVector3( L );
|
||||
|
||||
uluaPushVector3( L, Vector3Normalize( v ) );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> v1, v2 = RL_Vector3OrthoNormalize( Vector3 v1, Vector3 v2 )
|
||||
|
||||
Orthonormalize provided vectors. Makes vectors normalized and orthogonal to each other.
|
||||
Gram-Schmidt function implementation
|
||||
|
||||
- Failure return false
|
||||
- Success return Vector3, Vector3
|
||||
*/
|
||||
int lmathVector3OrthoNormalize( lua_State *L ) {
|
||||
if ( !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_Vector3OrthoNormalize( Vector3 v1, Vector3 v2 )" );
|
||||
lua_pushboolean( L, false );
|
||||
return 1;
|
||||
}
|
||||
Vector3 v2 = uluaGetVector3( L );
|
||||
lua_pop( L, 1 );
|
||||
Vector3 v1 = uluaGetVector3( L );
|
||||
|
||||
Vector3OrthoNormalize( &v1, &v2 );
|
||||
|
||||
uluaPushVector3( L, v1 );
|
||||
uluaPushVector3( L, v2 );
|
||||
|
||||
return 2;
|
||||
}
|
||||
|
||||
/*
|
||||
> result = RL_Vector3Transform( Vector3 v, Matrix mat )
|
||||
|
||||
Transforms a Vector3 by a given Matrix
|
||||
|
||||
- Failure return false
|
||||
- Success return Vector3
|
||||
*/
|
||||
int lmathVector3Transform( lua_State *L ) {
|
||||
if ( !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_Vector3Transform( Vector3 v, Matrix mat )" );
|
||||
lua_pushboolean( L, false );
|
||||
return 1;
|
||||
}
|
||||
Vector3 v1 = uluaGetVector3( L );
|
||||
lua_pop( L, 1 );
|
||||
Matrix mat = uluaGetMatrix( L );
|
||||
|
||||
uluaPushVector3( L, Vector3Transform( v1, mat ) );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> result = RL_Vector3RotateByQuaternion( Vector3 v, Quaternion q )
|
||||
|
||||
Transform a vector by quaternion rotation
|
||||
|
||||
- Failure return false
|
||||
- Success return Vector3
|
||||
*/
|
||||
int lmathVector3RotateByQuaternion( lua_State *L ) {
|
||||
if ( !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_Vector3RotateByQuaternion( Vector3 v, Quaternion q )" );
|
||||
lua_pushboolean( L, false );
|
||||
return 1;
|
||||
}
|
||||
Vector3 v1 = uluaGetVector3( L );
|
||||
lua_pop( L, 1 );
|
||||
Quaternion q = uluaGetQuaternion( L );
|
||||
|
||||
uluaPushVector3( L, Vector3RotateByQuaternion( v1, q ) );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> result = RL_Vector3Lerp( Vector3 v1, Vector3 v2, float amount )
|
||||
|
||||
Calculate linear interpolation between two vectors
|
||||
|
||||
- Failure return false
|
||||
- Success return Vector3
|
||||
*/
|
||||
int lmathVector3Lerp( lua_State *L ) {
|
||||
if ( !lua_istable( L, -3 ) || !lua_istable( L, -2 ) || !lua_isnumber( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_Vector3Lerp( Vector3 v1, Vector3 v2, float amount )" );
|
||||
lua_pushboolean( L, false );
|
||||
return 1;
|
||||
}
|
||||
float amount = lua_tonumber( L, -1 );
|
||||
lua_pop( L, 1 );
|
||||
Vector3 v2 = uluaGetVector3( L );
|
||||
lua_pop( L, 1 );
|
||||
Vector3 v1 = uluaGetVector3( L );
|
||||
|
||||
uluaPushVector3( L, Vector3Lerp( v1, v2, amount ) );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> result = RL_Vector3Reflect( Vector3 v, Vector3 normal )
|
||||
|
||||
Calculate reflected vector to normal
|
||||
|
||||
- Failure return false
|
||||
- Success return Vector3
|
||||
*/
|
||||
int lmathVector3Reflect( lua_State *L ) {
|
||||
if ( !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_Vector3Reflect( Vector3 v, Vector3 normal )" );
|
||||
lua_pushboolean( L, false );
|
||||
return 1;
|
||||
}
|
||||
Vector3 normal = uluaGetVector3( L );
|
||||
lua_pop( L, 1 );
|
||||
Vector3 v1 = uluaGetVector3( L );
|
||||
|
||||
uluaPushVector3( L, Vector3Reflect( v1, normal ) );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
## Math - Matrix
|
||||
*/
|
||||
|
||||
/*
|
||||
> result = RL_MatrixDeterminant( Matrix mat )
|
||||
|
||||
Compute matrix determinant
|
||||
|
||||
- Failure return false
|
||||
- Success return float
|
||||
*/
|
||||
int lmathMatrixDeterminant( lua_State *L ) {
|
||||
if ( !lua_istable( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_MatrixDeterminant( Matrix mat )" );
|
||||
lua_pushboolean( L, false );
|
||||
return 1;
|
||||
}
|
||||
Matrix mat = uluaGetMatrix( L );
|
||||
|
||||
lua_pushnumber( L, MatrixDeterminant( mat ) );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> result = RL_MatrixTranspose( Matrix mat )
|
||||
|
||||
Transposes provided matrix
|
||||
|
||||
- Failure return false
|
||||
- Success return Matrix
|
||||
*/
|
||||
int lmathMatrixTranspose( lua_State *L ) {
|
||||
if ( !lua_istable( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_MatrixTranspose( Matrix mat )" );
|
||||
lua_pushboolean( L, false );
|
||||
return 1;
|
||||
}
|
||||
Matrix mat = uluaGetMatrix( L );
|
||||
|
||||
uluaPushMatrix( L, MatrixTranspose( mat ) );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> result = RL_MatrixInvert( Matrix mat )
|
||||
|
||||
Invert provided matrix
|
||||
|
||||
- Failure return false
|
||||
- Success return Matrix
|
||||
*/
|
||||
int lmathMatrixInvert( lua_State *L ) {
|
||||
if ( !lua_istable( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_MatrixInvert( Matrix mat )" );
|
||||
lua_pushboolean( L, false );
|
||||
return 1;
|
||||
}
|
||||
Matrix mat = uluaGetMatrix( L );
|
||||
|
||||
uluaPushMatrix( L, MatrixInvert( mat ) );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> result = RL_MatrixNormalize( Matrix mat )
|
||||
|
||||
Normalize provided matrix
|
||||
|
||||
- Failure return false
|
||||
- Success return Matrix
|
||||
*/
|
||||
int lmathMatrixNormalize( lua_State *L ) {
|
||||
if ( !lua_istable( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_MatrixNormalize( Matrix mat )" );
|
||||
lua_pushboolean( L, false );
|
||||
return 1;
|
||||
}
|
||||
Matrix mat = uluaGetMatrix( L );
|
||||
|
||||
uluaPushMatrix( L, MatrixNormalize( mat ) );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> result = MatrixIdentity()
|
||||
|
||||
Get identity matrix
|
||||
|
||||
- Success return Matrix
|
||||
*/
|
||||
int lmathMatrixIdentity( lua_State *L ) {
|
||||
uluaPushMatrix( L, MatrixIdentity() );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> result = RL_MatrixAdd( Matrix left, Matrix right )
|
||||
|
||||
Add two matrices
|
||||
|
||||
- Failure return false
|
||||
- Success return Matrix
|
||||
*/
|
||||
int lmathMatrixAdd( lua_State *L ) {
|
||||
if ( !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_MatrixAdd( Matrix left, Matrix right )" );
|
||||
lua_pushboolean( L, false );
|
||||
return 1;
|
||||
}
|
||||
Matrix mat2 = uluaGetMatrix( L );
|
||||
lua_pop( L, 1 );
|
||||
Matrix mat1 = uluaGetMatrix( L );
|
||||
|
||||
uluaPushMatrix( L, MatrixAdd( mat1, mat2 ) );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> result = RL_MatrixAdd( Matrix left, Matrix right )
|
||||
|
||||
Subtract two matrices (left - right)
|
||||
|
||||
- Failure return false
|
||||
- Success return Matrix
|
||||
*/
|
||||
int lmathMatrixSubtract( lua_State *L ) {
|
||||
if ( !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_MatrixSubtract( Matrix left, Matrix right )" );
|
||||
lua_pushboolean( L, false );
|
||||
return 1;
|
||||
}
|
||||
Matrix mat2 = uluaGetMatrix( L );
|
||||
lua_pop( L, 1 );
|
||||
Matrix mat1 = uluaGetMatrix( L );
|
||||
|
||||
uluaPushMatrix( L, MatrixSubtract( mat1, mat2 ) );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> result = RL_MatrixMultiply( Matrix left, Matrix right )
|
||||
|
||||
Get two matrix multiplication
|
||||
|
||||
- Failure return false
|
||||
- Success return Matrix
|
||||
*/
|
||||
int lmathMatrixMultiply( lua_State *L ) {
|
||||
if ( !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_MatrixMultiply( Matrix left, Matrix right )" );
|
||||
lua_pushboolean( L, false );
|
||||
return 1;
|
||||
}
|
||||
Matrix mat2 = uluaGetMatrix( L );
|
||||
lua_pop( L, 1 );
|
||||
Matrix mat1 = uluaGetMatrix( L );
|
||||
|
||||
uluaPushMatrix( L, MatrixMultiply( mat1, mat2 ) );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> result = RL_MatrixTranslate( Vector3 translate )
|
||||
|
||||
Get translation matrix
|
||||
|
||||
- Failure return false
|
||||
- Success return Matrix
|
||||
*/
|
||||
int lmathMatrixTranslate( lua_State *L ) {
|
||||
if ( !lua_istable( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_MatrixTranslate( Vector3 translate )" );
|
||||
lua_pushboolean( L, false );
|
||||
return 1;
|
||||
}
|
||||
Vector3 v = uluaGetVector3( L );
|
||||
|
||||
uluaPushMatrix( L, MatrixTranslate( v.x, v.y, v.z ) );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> result = RL_MatrixRotate( Vector3 axis, float angle )
|
||||
|
||||
Create rotation matrix from axis and angle. NOTE: Angle should be provided in radians
|
||||
|
||||
- Failure return false
|
||||
- Success return Matrix
|
||||
*/
|
||||
int lmathMatrixRotate( lua_State *L ) {
|
||||
if ( !lua_istable( L, -2 ) || !lua_isnumber( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_MatrixRotate( Vector3 axis, float angle )" );
|
||||
lua_pushboolean( L, false );
|
||||
return 1;
|
||||
}
|
||||
float angle = lua_tonumber( L, -1 );
|
||||
lua_pop( L, 1 );
|
||||
Vector3 axis = uluaGetVector3( L );
|
||||
|
||||
uluaPushMatrix( L, MatrixRotate( axis, angle ) );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> result = RL_MatrixScale( Vector3 scale )
|
||||
|
||||
Get scaling matrix
|
||||
|
||||
- Failure return false
|
||||
- Success return Matrix
|
||||
*/
|
||||
int lmathMatrixScale( lua_State *L ) {
|
||||
if ( !lua_istable( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_MatrixScale( Vector3 scale )" );
|
||||
lua_pushboolean( L, false );
|
||||
return 1;
|
||||
}
|
||||
Vector3 v = uluaGetVector3( L );
|
||||
|
||||
uluaPushMatrix( L, MatrixScale( v.x, v.y, v.z ) );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> result = RL_MatrixFrustum( double left, double right, double bottom, double top, double near, double far )
|
||||
|
||||
Get perspective projection matrix
|
||||
|
||||
- Failure return false
|
||||
- Success return Matrix
|
||||
*/
|
||||
int lmathMatrixFrustum( lua_State *L ) {
|
||||
if ( !lua_isnumber( L, -6 ) || !lua_isnumber( L, -5 ) || !lua_isnumber( L, -4 )
|
||||
|| !lua_isnumber( L, -3 ) || !lua_isnumber( L, -2 ) || !lua_isnumber( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_MatrixFrustum( double left, double right, double bottom, double top, double near, double far )" );
|
||||
lua_pushboolean( L, false );
|
||||
return 1;
|
||||
}
|
||||
float far = lua_tonumber( L, -1 );
|
||||
float near = lua_tonumber( L, -2 );
|
||||
float top = lua_tonumber( L, -3 );
|
||||
float bottom = lua_tonumber( L, -4 );
|
||||
float right = lua_tonumber( L, -5 );
|
||||
float left = lua_tonumber( L, -6 );
|
||||
|
||||
uluaPushMatrix( L, MatrixFrustum( left, right, bottom, top, near, far ) );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> result = RL_MatrixPerspective( double fovy, double aspect, double near, double far )
|
||||
|
||||
Get perspective projection matrix
|
||||
|
||||
- Failure return false
|
||||
- Success return Matrix
|
||||
*/
|
||||
int lmathMatrixPerspective( lua_State *L ) {
|
||||
if ( !lua_isnumber( L, -4 ) || !lua_isnumber( L, -3 ) || !lua_isnumber( L, -2 ) || !lua_isnumber( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_MatrixPerspective( double fovy, double aspect, double near, double far )" );
|
||||
lua_pushboolean( L, false );
|
||||
return 1;
|
||||
}
|
||||
float far = lua_tonumber( L, -1 );
|
||||
float near = lua_tonumber( L, -2 );
|
||||
float aspect = lua_tonumber( L, -3 );
|
||||
float fovy = lua_tonumber( L, -4 );
|
||||
|
||||
uluaPushMatrix( L, MatrixPerspective( fovy, aspect, near, far ) );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> result = RL_MatrixOrtho( double left, double right, double bottom, double top, double near, double far )
|
||||
|
||||
Get orthographic projection matrix
|
||||
|
||||
- Failure return false
|
||||
- Success return Matrix
|
||||
*/
|
||||
int lmathMatrixOrtho( lua_State *L ) {
|
||||
if ( !lua_isnumber( L, -6 ) || !lua_isnumber( L, -5 ) || !lua_isnumber( L, -4 )
|
||||
|| !lua_isnumber( L, -3 ) || !lua_isnumber( L, -2 ) || !lua_isnumber( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_MatrixOrtho( double left, double right, double bottom, double top, double near, double far )" );
|
||||
lua_pushboolean( L, false );
|
||||
return 1;
|
||||
}
|
||||
float far = lua_tonumber( L, -1 );
|
||||
float near = lua_tonumber( L, -2 );
|
||||
float top = lua_tonumber( L, -3 );
|
||||
float bottom = lua_tonumber( L, -4 );
|
||||
float right = lua_tonumber( L, -5 );
|
||||
float left = lua_tonumber( L, -6 );
|
||||
|
||||
uluaPushMatrix( L, MatrixOrtho( left, right, bottom, top, near, far ) );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> result = RL_MatrixLookAt( Vector3 eye, Vector3 target, Vector3 up )
|
||||
|
||||
Get camera look-at matrix ( View matrix )
|
||||
|
||||
- Failure return false
|
||||
- Success return Matrix
|
||||
*/
|
||||
int lmathMatrixLookAt( lua_State *L ) {
|
||||
if ( !lua_istable( L, -3 ) || !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_MatrixLookAt( Vector3 eye, Vector3 target, Vector3 up )" );
|
||||
lua_pushboolean( L, false );
|
||||
return 1;
|
||||
}
|
||||
Vector3 up = uluaGetVector3( L );
|
||||
lua_pop( L, 1 );
|
||||
Vector3 target = uluaGetVector3( L );
|
||||
lua_pop( L, 1 );
|
||||
Vector3 eye = uluaGetVector3( L );
|
||||
|
||||
uluaPushMatrix( L, MatrixLookAt( eye, target, up ) );
|
||||
|
||||
return 1;
|
||||
}
|
||||
457
src/shapes.c
Normal file
457
src/shapes.c
Normal file
@@ -0,0 +1,457 @@
|
||||
#include "main.h"
|
||||
#include "shapes.h"
|
||||
#include "lua_core.h"
|
||||
|
||||
/*
|
||||
## Shapes - Drawing
|
||||
*/
|
||||
|
||||
/*
|
||||
> success = RL_DrawPixel( Vector2 pos, Color color )
|
||||
|
||||
Draw a pixel
|
||||
|
||||
- Failure return false
|
||||
- Success return true
|
||||
*/
|
||||
int lshapesDrawPixel( lua_State *L ) {
|
||||
if ( !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_DrawPixel( Vector2 pos, Color color )" );
|
||||
lua_pushboolean( L, false );
|
||||
return 1;
|
||||
}
|
||||
Color color = uluaGetColor( L );
|
||||
lua_pop( L, 1 );
|
||||
Vector2 pos = uluaGetVector2( L );
|
||||
|
||||
DrawPixelV( pos, color );
|
||||
lua_pushboolean( L, true );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> success = RL_DrawLine( Vector2 startPos, Vector2 endPos, float thickness, Color color )
|
||||
|
||||
Draw a line defining thickness
|
||||
|
||||
- Failure return false
|
||||
- Success return true
|
||||
*/
|
||||
int lshapesDrawLine( lua_State *L ) {
|
||||
if ( !lua_istable( L, -4 ) || !lua_istable( L, -3 ) || !lua_isnumber( L, -2 ) || !lua_istable( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_DrawLine( Vector2 startPos, Vector2 endPos, float thickness, Color color )" );
|
||||
lua_pushboolean( L, false );
|
||||
return 1;
|
||||
}
|
||||
Color color = uluaGetColor( L );
|
||||
lua_pop( L, 1 );
|
||||
float thickness = lua_tonumber( L, -1 );
|
||||
lua_pop( L, 1 );
|
||||
Vector2 endPos = uluaGetVector2( L );
|
||||
lua_pop( L, 1 );
|
||||
Vector2 startPos = uluaGetVector2( L );
|
||||
|
||||
DrawLineEx( startPos, endPos, thickness, color );
|
||||
lua_pushboolean( L, true );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> success = RL_DrawCircle( Vector2 center, float radius, Color color )
|
||||
|
||||
Draw a color-filled circle
|
||||
|
||||
- Failure return false
|
||||
- Success return true
|
||||
*/
|
||||
int lshapesDrawCircle( lua_State *L ) {
|
||||
if ( !lua_istable( L, -3 ) || !lua_isnumber( L, -2 ) || !lua_istable( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_DrawCircle( Vector2 center, float radius, Color color )" );
|
||||
lua_pushboolean( L, false );
|
||||
return 1;
|
||||
}
|
||||
Color color = uluaGetColor( L );
|
||||
lua_pop( L, 1 );
|
||||
float radius = lua_tonumber( L, -1 );
|
||||
lua_pop( L, 1 );
|
||||
Vector2 center = uluaGetVector2( L );
|
||||
|
||||
DrawCircleV( center, radius, color );
|
||||
lua_pushboolean( L, true );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> success = RL_DrawCircleLines( Vector2 center, float radius, Color color )
|
||||
|
||||
Draw circle outline
|
||||
|
||||
- Failure return false
|
||||
- Success return true
|
||||
*/
|
||||
int lshapesDrawCircleLines( lua_State *L ) {
|
||||
if ( !lua_istable( L, -3 ) || !lua_isnumber( L, -2 ) || !lua_istable( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_DrawCircleLines( Vector2 center, float radius, Color color )" );
|
||||
lua_pushboolean( L, false );
|
||||
return 1;
|
||||
}
|
||||
Color color = uluaGetColor( L );
|
||||
lua_pop( L, 1 );
|
||||
float radius = lua_tonumber( L, -1 );
|
||||
lua_pop( L, 1 );
|
||||
Vector2 center = uluaGetVector2( L );
|
||||
|
||||
DrawCircleLines( center.x, center.y, radius, color );
|
||||
lua_pushboolean( L, true );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> success = RL_DrawRectangle( Rectangle rec, Color color )
|
||||
|
||||
Draw a color-filled rectangle
|
||||
|
||||
- Failure return false
|
||||
- Success return true
|
||||
*/
|
||||
int lshapesDrawRectangle( lua_State *L ) {
|
||||
if ( !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_DrawRectangle( Rectangle rec, Color color )" );
|
||||
lua_pushboolean( L, false );
|
||||
return 1;
|
||||
}
|
||||
Rectangle rect = { 0, 0, 0, 0 };
|
||||
Color color = { 0, 0, 0, 0 };
|
||||
|
||||
color = uluaGetColor( L );
|
||||
lua_pop( L, 1 );
|
||||
rect = uluaGetRectangle( L );
|
||||
|
||||
DrawRectangleRec( rect, color );
|
||||
lua_pushboolean( L, true );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> success = RL_DrawRectanglePro( Rectangle rec, Vector2 origin, float rotation, Color color )
|
||||
|
||||
Draw a color-filled rectangle with pro parameters
|
||||
|
||||
- Failure return false
|
||||
- Success return true
|
||||
*/
|
||||
int lshapesDrawRectanglePro( lua_State *L ) {
|
||||
if ( !lua_istable( L, -4 ) || !lua_istable( L, -3 ) || !lua_isnumber( L, -2 ) || !lua_istable( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_DrawRectanglePro( Rectangle rec, Vector2 origin, float rotation, Color color )" );
|
||||
lua_pushboolean( L, false );
|
||||
return 1;
|
||||
}
|
||||
Color color = uluaGetColor( L );
|
||||
lua_pop( L, 1 );
|
||||
float rotation = lua_tonumber( L, -1 );
|
||||
lua_pop( L, 1 );
|
||||
Vector2 origin = uluaGetVector2( L );
|
||||
lua_pop( L, 1 );
|
||||
Rectangle rec = uluaGetRectangle( L );
|
||||
|
||||
DrawRectanglePro( rec, origin, rotation, color );
|
||||
lua_pushboolean( L, true );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> success = RL_DrawTriangle( Vector2 v1, Vector2 v2, Vector2 v3, Color color )
|
||||
|
||||
Draw a color-filled triangle ( Vertex in counter-clockwise order! )
|
||||
|
||||
- Failure return false
|
||||
- Success return true
|
||||
*/
|
||||
int lshapesDrawTriangle( lua_State *L ) {
|
||||
if ( !lua_istable( L, -4 ) || !lua_istable( L, -3 ) || !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_DrawTriangle( Vector2 v1, Vector2 v2, Vector2 v3, Color color )" );
|
||||
lua_pushboolean( L, false );
|
||||
return 1;
|
||||
}
|
||||
Color color = uluaGetColor( L );
|
||||
lua_pop( L, 1 );
|
||||
Vector2 v3 = uluaGetVector2( L );
|
||||
lua_pop( L, 1 );
|
||||
Vector2 v2 = uluaGetVector2( L );
|
||||
lua_pop( L, 1 );
|
||||
Vector2 v1 = uluaGetVector2( L );
|
||||
|
||||
DrawTriangle( v1, v2, v3, color );
|
||||
lua_pushboolean( L, true );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> success = RL_DrawTriangleLines( Vector2 v1, Vector2 v2, Vector2 v3, Color color )
|
||||
|
||||
Draw triangle outline ( Vertex in counter-clockwise order! )
|
||||
|
||||
- Failure return false
|
||||
- Success return true
|
||||
*/
|
||||
int lshapesDrawTriangleLines( lua_State *L ) {
|
||||
if ( !lua_istable( L, -4 ) || !lua_istable( L, -3 ) || !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_DrawTriangleLines( Vector2 v1, Vector2 v2, Vector2 v3, Color color )" );
|
||||
lua_pushboolean( L, false );
|
||||
return 1;
|
||||
}
|
||||
Color color = uluaGetColor( L );
|
||||
lua_pop( L, 1 );
|
||||
Vector2 v3 = uluaGetVector2( L );
|
||||
lua_pop( L, 1 );
|
||||
Vector2 v2 = uluaGetVector2( L );
|
||||
lua_pop( L, 1 );
|
||||
Vector2 v1 = uluaGetVector2( L );
|
||||
|
||||
DrawTriangleLines( v1, v2, v3, color );
|
||||
lua_pushboolean( L, true );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
## Shapes - Collision
|
||||
*/
|
||||
|
||||
/*
|
||||
> collision = RL_CheckCollisionRecs( Rectangle rec1, Rectangle rec2 )
|
||||
|
||||
Check collision between two rectangles
|
||||
|
||||
- Failure return nil
|
||||
- Success return bool
|
||||
*/
|
||||
int lshapesCheckCollisionRecs( lua_State *L ) {
|
||||
if ( !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_CheckCollisionRecs( Rectangle rec1, Rectangle rec2 )" );
|
||||
lua_pushnil( L );
|
||||
return 1;
|
||||
}
|
||||
Rectangle rect1 = uluaGetRectangle( L );
|
||||
lua_pop( L, 1 );
|
||||
Rectangle rect2 = uluaGetRectangle( L );
|
||||
|
||||
lua_pushboolean( L, CheckCollisionRecs( rect1, rect2 ) );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> collision = RL_CheckCollisionCircles( Vector2 center1, float radius1, Vector2 center2, float radius2 )
|
||||
|
||||
Check collision between two circles
|
||||
|
||||
- Failure return nil
|
||||
- Success return bool
|
||||
*/
|
||||
int lshapesCheckCollisionCircles( lua_State *L ) {
|
||||
if ( !lua_istable( L, -4 ) || !lua_isnumber( L, -3 ) || !lua_istable( L, -2 ) || !lua_isnumber( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_CheckCollisionCircles( Vector2 center1, float radius1, Vector2 center2, float radius2 )" );
|
||||
lua_pushnil( L );
|
||||
return 1;
|
||||
}
|
||||
float radius2 = lua_tonumber( L, -1 );
|
||||
lua_pop( L, 1 );
|
||||
Vector2 center2 = uluaGetVector2( L );
|
||||
lua_pop( L, 1 );
|
||||
float radius1 = lua_tonumber( L, -1 );
|
||||
lua_pop( L, 1 );
|
||||
Vector2 center1 = uluaGetVector2( L );
|
||||
|
||||
lua_pushboolean( L, CheckCollisionCircles( center1, radius1, center2, radius2 ) );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> collision = RL_CheckCollisionCircleRec( Vector2 center, float radius, Rectangle rec )
|
||||
|
||||
Check collision between circle and rectangle
|
||||
|
||||
- Failure return nil
|
||||
- Success return bool
|
||||
*/
|
||||
int lshapesCheckCollisionCircleRec( lua_State *L ) {
|
||||
if ( !lua_istable( L, -3 ) || !lua_isnumber( L, -2 ) || !lua_istable( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_CheckCollisionCircleRec( Vector2 center, float radius, Rectangle rec )" );
|
||||
lua_pushnil( L );
|
||||
return 1;
|
||||
}
|
||||
Rectangle rec = uluaGetRectangle( L );
|
||||
lua_pop( L, 1 );
|
||||
float radius = lua_tonumber( L, -1 );
|
||||
lua_pop( L, 1 );
|
||||
Vector2 center = uluaGetVector2( L );
|
||||
|
||||
lua_pushboolean( L, CheckCollisionCircleRec( center, radius, rec ) );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> collision = RL_CheckCollisionPointRec( Vector2 point, Rectangle rec )
|
||||
|
||||
Check if point is inside rectangle
|
||||
|
||||
- Failure return nil
|
||||
- Success return bool
|
||||
*/
|
||||
int lshapesCheckCollisionPointRec( lua_State *L ) {
|
||||
if ( !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_CheckCollisionPointRec( Vector2 point, Rectangle rec )" );
|
||||
lua_pushnil( L );
|
||||
return 1;
|
||||
}
|
||||
Rectangle rec = uluaGetRectangle( L );
|
||||
lua_pop( L, 1 );
|
||||
Vector2 point = uluaGetVector2( L );
|
||||
|
||||
lua_pushboolean( L, CheckCollisionPointRec( point, rec ) );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> collision = RL_CheckCollisionPointCircle( Vector2 point, Vector2 center, float radius )
|
||||
|
||||
Check if point is inside circle
|
||||
|
||||
- Failure return nil
|
||||
- Success return bool
|
||||
*/
|
||||
int lshapesCheckCollisionPointCircle( lua_State *L ) {
|
||||
if ( !lua_istable( L, -3 ) || !lua_istable( L, -2 ) || !lua_isnumber( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_CheckCollisionPointCircle( Vector2 point, Vector2 center, float radius )" );
|
||||
lua_pushnil( L );
|
||||
return 1;
|
||||
}
|
||||
float radius = lua_tonumber( L, -1 );
|
||||
lua_pop( L, 1 );
|
||||
Vector2 center = uluaGetVector2( L );
|
||||
lua_pop( L, 1 );
|
||||
Vector2 point = uluaGetVector2( L );
|
||||
|
||||
lua_pushboolean( L, CheckCollisionPointCircle( point, center, radius ) );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> collision = RL_CheckCollisionPointTriangle( Vector2 point, Vector2 p1, Vector2 p2, Vector2 p3 )
|
||||
|
||||
Check if point is inside a triangle
|
||||
|
||||
- Failure return nil
|
||||
- Success return bool
|
||||
*/
|
||||
int lshapesCheckCollisionPointTriangle( lua_State *L ) {
|
||||
if ( !lua_istable( L, -4 ) || !lua_istable( L, -3 ) || !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_CheckCollisionPointTriangle( Vector2 point, Vector2 p1, Vector2 p2, Vector2 p3 )" );
|
||||
lua_pushnil( L );
|
||||
return 1;
|
||||
}
|
||||
Vector2 p3 = uluaGetVector2( L );
|
||||
lua_pop( L, 1 );
|
||||
Vector2 p2 = uluaGetVector2( L );
|
||||
lua_pop( L, 1 );
|
||||
Vector2 p1 = uluaGetVector2( L );
|
||||
lua_pop( L, 1 );
|
||||
Vector2 point = uluaGetVector2( L );
|
||||
|
||||
lua_pushboolean( L, CheckCollisionPointTriangle( point, p1, p2, p3 ) );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> collision, position = RL_CheckCollisionLines( Vector2 startPos1, Vector2 endPos1, Vector2 startPos2, Vector2 endPos2 )
|
||||
|
||||
Check the collision between two lines defined by two points each, returns collision point by reference
|
||||
|
||||
- Failure return nil
|
||||
- Success return bool, Vector2
|
||||
*/
|
||||
int lshapesCheckCollisionLines( lua_State *L ) {
|
||||
if ( !lua_istable( L, -4 ) || !lua_istable( L, -3 ) || !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_CheckCollisionLines( Vector2 startPos1, Vector2 endPos1, Vector2 startPos2, Vector2 endPos2 )" );
|
||||
lua_pushnil( L );
|
||||
return 1;
|
||||
}
|
||||
Vector2 endPos2 = uluaGetVector2( L );
|
||||
lua_pop( L, 1 );
|
||||
Vector2 startPos2 = uluaGetVector2( L );
|
||||
lua_pop( L, 1 );
|
||||
Vector2 endPos1 = uluaGetVector2( L );
|
||||
lua_pop( L, 1 );
|
||||
Vector2 startPos1 = uluaGetVector2( L );
|
||||
|
||||
Vector2 colPoint = { 0, 0 };
|
||||
|
||||
lua_pushboolean( L, CheckCollisionLines( startPos1, endPos1, startPos2, endPos2, &colPoint ) );
|
||||
uluaPushVector2( L, colPoint );
|
||||
|
||||
return 2;
|
||||
}
|
||||
|
||||
/*
|
||||
> collision = RL_CheckCollisionPointLine( Vector2 point, Vector2 p1, Vector2 p2, int threshold )
|
||||
|
||||
Check if point belongs to line created between two points [p1] and [p2] with defined margin in pixels [threshold]
|
||||
|
||||
- Failure return nil
|
||||
- Success return bool
|
||||
*/
|
||||
int lshapesCheckCollisionPointLine( lua_State *L ) {
|
||||
if ( !lua_istable( L, -4 ) || !lua_istable( L, -3 ) || !lua_istable( L, -2 ) || !lua_isnumber( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_CheckCollisionPointLine( Vector2 point, Vector2 p1, Vector2 p2, int threshold )" );
|
||||
lua_pushnil( L );
|
||||
return 1;
|
||||
}
|
||||
int threshold = lua_tointeger( L, -1 );
|
||||
lua_pop( L, 1 );
|
||||
Vector2 p2 = uluaGetVector2( L );
|
||||
lua_pop( L, 1 );
|
||||
Vector2 p1 = uluaGetVector2( L );
|
||||
lua_pop( L, 1 );
|
||||
Vector2 point = uluaGetVector2( L );
|
||||
|
||||
lua_pushboolean( L, CheckCollisionPointLine( point, p1, p2, threshold ) );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> rectangle = RL_GetCollisionRec( Rectangle rec1, Rectangle rec2 )
|
||||
|
||||
Get collision rectangle for two rectangles collision
|
||||
|
||||
- Failure return nil
|
||||
- Success return Rectangle
|
||||
*/
|
||||
int lshapesGetCollisionRec( lua_State *L ) {
|
||||
/* Rectangle rec1, Rectangle rec2 */
|
||||
if ( !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GetCollisionRec( Rectangle rec1, Rectangle rec2 )" );
|
||||
lua_pushnil( L );
|
||||
return 1;
|
||||
}
|
||||
Rectangle rec2 = uluaGetRectangle( L );
|
||||
lua_pop( L, 1 );
|
||||
Rectangle rec1 = uluaGetRectangle( L );
|
||||
|
||||
uluaPushRectangle( L, GetCollisionRec( rec1, rec2 ) );
|
||||
|
||||
return 1;
|
||||
}
|
||||
194
src/state.c
Normal file
194
src/state.c
Normal file
@@ -0,0 +1,194 @@
|
||||
#include "main.h"
|
||||
#include "state.h"
|
||||
#include "lua_core.h"
|
||||
#include "textures.h"
|
||||
|
||||
State *state;
|
||||
|
||||
bool stateInit( const char *exePath ) {
|
||||
state = malloc( sizeof( State ) );
|
||||
|
||||
state->exePath = malloc( STRING_LEN * sizeof( char ) );
|
||||
strncpy( state->exePath, exePath, STRING_LEN - 1 );
|
||||
|
||||
state->hasWindow = true;
|
||||
state->run = true;
|
||||
state->resolution = (Vector2){ 1024, 720 };
|
||||
state->luaState = NULL;
|
||||
state->targetFPS = 60;
|
||||
state->textureSource = TEXTURE_SOURCE_TEXTURE;
|
||||
/* Images. */
|
||||
state->imageAlloc = ALLOC_PAGE_SIZE;
|
||||
state->imageCount = 0;
|
||||
state->images = malloc( state->imageAlloc * sizeof( Image* ) );
|
||||
/* Textures. */
|
||||
state->textureAlloc = ALLOC_PAGE_SIZE;
|
||||
state->textureCount = 0;
|
||||
state->textures = malloc( state->textureAlloc * sizeof( Texture2D* ) );
|
||||
/* RenderTextures. */
|
||||
state->renderTextureAlloc = ALLOC_PAGE_SIZE;
|
||||
state->renderTextureCount = 0;
|
||||
state->renderTextures = malloc( state->renderTextureAlloc * sizeof( RenderTexture2D* ) );
|
||||
/* Fonts. */
|
||||
state->fontAlloc = ALLOC_PAGE_SIZE;
|
||||
state->fontCount = 1;
|
||||
state->fonts = malloc( state->fontAlloc * sizeof( Font* ) );
|
||||
/* Sounds. */
|
||||
state->soundAlloc = ALLOC_PAGE_SIZE;
|
||||
state->soundCount = 0;
|
||||
state->sounds = malloc( state->soundAlloc * sizeof( Sound* ) );
|
||||
/* Camera3D's. */
|
||||
state->camera3DAlloc = ALLOC_PAGE_SIZE;
|
||||
state->camera3DCount = 0;
|
||||
state->camera3Ds = malloc( state->camera3DAlloc * sizeof( Camera3D* ) );
|
||||
/* Meshes. */
|
||||
state->meshAlloc = ALLOC_PAGE_SIZE;
|
||||
state->meshCount = 0;
|
||||
state->meshes = malloc( state->meshAlloc * sizeof( Mesh* ) );
|
||||
/* Materials. */
|
||||
state->materialAlloc = ALLOC_PAGE_SIZE;
|
||||
state->materialCount = 1;
|
||||
state->materials = malloc( state->materialAlloc * sizeof( Material* ) );
|
||||
/* Models. */
|
||||
state->modelAlloc = ALLOC_PAGE_SIZE;
|
||||
state->modelCount = 0;
|
||||
state->models = malloc( state->modelAlloc * sizeof( Model* ) );
|
||||
/* ModelsAnimations. */
|
||||
state->animationAlloc = ALLOC_PAGE_SIZE;
|
||||
state->animationCount = 0;
|
||||
state->animations = malloc( state->animationAlloc * sizeof( ModelAnimations* ) );
|
||||
/* Shaders. */
|
||||
state->shaderAlloc = ALLOC_PAGE_SIZE;
|
||||
state->shaderCount = 0;
|
||||
state->shaders = malloc( state->shaderAlloc * sizeof( Shader* ) );
|
||||
|
||||
for ( int i = 0; i < ALLOC_PAGE_SIZE; i++ ) {
|
||||
state->images[i] = NULL;
|
||||
state->textures[i] = NULL;
|
||||
state->renderTextures[i] = NULL;
|
||||
state->sounds[i] = NULL;
|
||||
state->camera3Ds[i] = NULL;
|
||||
state->meshes[i] = NULL;
|
||||
state->models[i] = NULL;
|
||||
state->animations[i] = NULL;
|
||||
state->shaders[i] = NULL;
|
||||
|
||||
/* The ones we want to save the first. */
|
||||
if ( 0 < i ) {
|
||||
state->fonts[i] = NULL;
|
||||
state->materials[i] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
InitWindow( state->resolution.x, state->resolution.y, "ReiLua" );
|
||||
/* Has to be after InitWindod where opengl context is created. */
|
||||
state->materials[0] = malloc( sizeof( Material ) );
|
||||
*state->materials[0] = LoadMaterialDefault();
|
||||
state->fonts[0] = malloc( sizeof( Font ) );
|
||||
*state->fonts[0] = GetFontDefault();
|
||||
|
||||
if ( !IsWindowReady() ) {
|
||||
state->hasWindow = false;
|
||||
state->run = false;
|
||||
}
|
||||
else {
|
||||
SetTargetFPS( state->targetFPS );
|
||||
}
|
||||
|
||||
InitAudioDevice();
|
||||
state->run = luaInit();
|
||||
|
||||
return state->run;
|
||||
}
|
||||
|
||||
void stateFree() {
|
||||
for ( int i = 0; i < state->imageCount; ++i ) {
|
||||
if ( state->images[i] != NULL ) {
|
||||
UnloadImage( *state->images[i] );
|
||||
free( state->images[i] );
|
||||
}
|
||||
}
|
||||
for ( int i = 0; i < state->textureCount; ++i ) {
|
||||
if ( state->textures[i] != NULL ) {
|
||||
UnloadTexture( *state->textures[i] );
|
||||
free( state->textures[i] );
|
||||
}
|
||||
}
|
||||
for ( int i = 0; i < state->renderTextureCount; ++i ) {
|
||||
if ( state->renderTextures[i] != NULL ) {
|
||||
UnloadRenderTexture( *state->renderTextures[i] );
|
||||
free( state->renderTextures[i] );
|
||||
}
|
||||
}
|
||||
for ( int i = 0; i < state->fontCount; ++i ) {
|
||||
if ( state->fonts[i] != NULL ) {
|
||||
UnloadFont( *state->fonts[i] );
|
||||
free( state->fonts[i] );
|
||||
}
|
||||
}
|
||||
for ( int i = 0; i < state->soundCount; ++i ) {
|
||||
if ( state->sounds[i] != NULL ) {
|
||||
UnloadSound( *state->sounds[i] );
|
||||
free( state->sounds[i] );
|
||||
}
|
||||
}
|
||||
for ( int i = 0; i < state->camera3DCount; ++i ) {
|
||||
if ( state->camera3Ds[i] != NULL ) {
|
||||
free( state->camera3Ds[i] );
|
||||
}
|
||||
}
|
||||
for ( int i = 0; i < state->modelCount; ++i ) {
|
||||
if ( state->models[i] != NULL ) {
|
||||
// UnloadModel( *state->models[i] );
|
||||
UnloadModelKeepMeshes( *state->models[i] );
|
||||
free( state->models[i] );
|
||||
}
|
||||
}
|
||||
for ( int i = 0; i < state->meshCount; ++i ) {
|
||||
if ( state->meshes[i] != NULL ) {
|
||||
UnloadMesh( *state->meshes[i] );
|
||||
free( state->meshes[i] );
|
||||
}
|
||||
}
|
||||
for ( int i = 0; i < state->materialCount; ++i ) {
|
||||
if ( state->materials[i] != NULL ) {
|
||||
UnloadMaterial( *state->materials[i] );
|
||||
free( state->materials[i] );
|
||||
}
|
||||
}
|
||||
for ( int i = 0; i < state->animationCount; ++i ) {
|
||||
if ( state->animations[i] != NULL ) {
|
||||
UnloadModelAnimations( state->animations[i]->animations, state->animations[i]->animCount );
|
||||
free( state->animations[i] );
|
||||
}
|
||||
}
|
||||
for ( int i = 0; i < state->shaderCount; ++i ) {
|
||||
if ( state->shaders[i] != NULL ) {
|
||||
UnloadShader( *state->shaders[i] );
|
||||
free( state->shaders[i] );
|
||||
}
|
||||
}
|
||||
|
||||
if ( IsAudioDeviceReady() ) {
|
||||
CloseAudioDevice();
|
||||
UnloadMusicStream( state->music );
|
||||
}
|
||||
if ( state->hasWindow ) {
|
||||
CloseWindow();
|
||||
}
|
||||
if ( state->luaState != NULL ) {
|
||||
lua_close( state->luaState );
|
||||
}
|
||||
free( state->images );
|
||||
free( state->textures );
|
||||
free( state->renderTextures );
|
||||
free( state->fonts );
|
||||
free( state->sounds );
|
||||
free( state->camera3Ds );
|
||||
free( state->meshes );
|
||||
free( state->materials );
|
||||
free( state->models );
|
||||
free( state->animations );
|
||||
free( state->shaders );
|
||||
free( state );
|
||||
}
|
||||
102
src/text.c
Normal file
102
src/text.c
Normal file
@@ -0,0 +1,102 @@
|
||||
#include "main.h"
|
||||
#include "state.h"
|
||||
#include "text.h"
|
||||
#include "lua_core.h"
|
||||
|
||||
static void checkFontRealloc( int i ) {
|
||||
if ( i == state->fontCount ) {
|
||||
state->fontCount++;
|
||||
}
|
||||
|
||||
if ( state->fontCount == state->fontAlloc ) {
|
||||
state->fontAlloc += ALLOC_PAGE_SIZE;
|
||||
state->fonts = realloc( state->fonts, state->fontAlloc * sizeof( Font* ) );
|
||||
|
||||
for ( i = state->fontCount; i < state->fontAlloc; i++ ) {
|
||||
state->fonts[i] = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool validFont( size_t id ) {
|
||||
if ( id < 0 || state->fontCount < id || state->fonts[ id ] == NULL ) {
|
||||
TraceLog( LOG_WARNING, "%s %d", "Invalid font", id );
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
## Text - Loading
|
||||
*/
|
||||
|
||||
/*
|
||||
> font = RL_LoadFont( string fileName )
|
||||
|
||||
Load font from file into GPU memory ( VRAM )
|
||||
|
||||
- Failure return -1
|
||||
- Success return int
|
||||
*/
|
||||
int lmodelsLoadFont( lua_State *L ) {
|
||||
if ( !lua_isstring( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_LoadFont( string fileName )" );
|
||||
lua_pushinteger( L, -1 );
|
||||
return 1;
|
||||
}
|
||||
int i = 0;
|
||||
|
||||
for ( i = 0; i < state->fontCount; i++ ) {
|
||||
if ( state->fonts[i] == NULL ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
state->fonts[i] = malloc( sizeof( Font ) );
|
||||
*state->fonts[i] = LoadFont( lua_tostring( L, -1 ) );
|
||||
lua_pushinteger( L, i );
|
||||
checkFontRealloc( i );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
## Text - Draw
|
||||
*/
|
||||
|
||||
/*
|
||||
> success = RL_DrawText( Font font, string text, Vector2 position, float fontSize, float spacing, Color tint )
|
||||
|
||||
Draw text using font and additional parameters
|
||||
|
||||
- Failure return false
|
||||
- Success return true
|
||||
*/
|
||||
int ltextDrawText( lua_State *L ) {
|
||||
if ( !lua_isnumber( L, -6 ) || !lua_isstring( L, -5 ) || !lua_istable( L, -4 )
|
||||
|| !lua_isnumber( L, -3 ) || !lua_isnumber( L, -2 ) || !lua_istable( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_DrawText( Font font, string text, Vector2 position, float fontSize, float spacing, Color tint )" );
|
||||
lua_pushboolean( L, false );
|
||||
return 1;
|
||||
}
|
||||
Color color = uluaGetColor( L );
|
||||
lua_pop( L, 1 );
|
||||
float spacing = lua_tonumber( L, -1 );
|
||||
lua_pop( L, 1 );
|
||||
float fontSize = lua_tonumber( L, -1 );
|
||||
lua_pop( L, 1 );
|
||||
Vector2 position = uluaGetVector2( L );
|
||||
lua_pop( L, 1 );
|
||||
size_t fontId = lua_tointeger( L, -2 );
|
||||
|
||||
if ( !validFont( fontId ) ) {
|
||||
lua_pushboolean( L, false );
|
||||
return 1;
|
||||
}
|
||||
|
||||
DrawTextEx( *state->fonts[ fontId ], lua_tostring( L, -1 ), position, fontSize, spacing, color );
|
||||
lua_pushboolean( L, true );
|
||||
|
||||
return 1;
|
||||
}
|
||||
1057
src/textures.c
Normal file
1057
src/textures.c
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user