DrawCapsule and DrawCapsuleWires. Free Camera3D example.

This commit is contained in:
jussi
2023-04-25 19:28:54 +03:00
parent a9ce78128d
commit 8b6337446d
9 changed files with 181 additions and 1 deletions

18
API.md
View File

@@ -4081,6 +4081,24 @@ Draw a cylinder wires with base at startPos and top at endPos
---
> success = RL.DrawCapsule( Vector3 startPos, Vector3 endPos, float radius, int slices, int rings, Color color )
Draw a capsule with the center of its sphere caps at startPos and endPos
- Failure return false
- Success return true
---
> success = RL.DrawCapsuleWires( Vector3 startPos, Vector3 endPos, float radius, int slices, int rings, Color color )
Draw capsule wireframe with the center of its sphere caps at startPos and endPos
- Failure return false
- Success return true
---
> success = RL.DrawPlane( Vector3 centerPos, Vector2 size, Color color )
Draw a plane XZ

View File

@@ -3129,6 +3129,30 @@ function RL.DrawCylinderWires( position, radiusTop, radiusBottom, height, slices
---@return any success
function RL.DrawCylinderWiresEx( startPos, endPos, startRadius, endRadius, sides, color ) end
---Draw a capsule with the center of its sphere caps at startPos and endPos
---- Failure return false
---- Success return true
---@param startPos table
---@param endPos table
---@param radius number
---@param slices integer
---@param rings integer
---@param color table
---@return any success
function RL.DrawCapsule( startPos, endPos, radius, slices, rings, color ) end
---Draw capsule wireframe with the center of its sphere caps at startPos and endPos
---- Failure return false
---- Success return true
---@param startPos table
---@param endPos table
---@param radius number
---@param slices integer
---@param rings integer
---@param color table
---@return any success
function RL.DrawCapsuleWires( startPos, endPos, radius, slices, rings, color ) end
---Draw a plane XZ
---- Failure return false
---- Success return true

View File

@@ -57,6 +57,8 @@ Detailed changes:
- ADDED: UpdateMusicStream
- ADDED: SetMusicLooping
- ADDED: GetMusicLooping
- ADDED: DrawCapsule and DrawCapsuleWires
- ADDED: Free Camera3D example
------------------------------------------------------------------------
Release: ReiLua version 0.4.0 Using Raylib 4.2

View File

@@ -21,7 +21,6 @@ Backlog {
* ImageDrawCircleLines
* ImageBlurGaussian
* Models
* DrawCapsule and DrawCapsuleWires
* LoadMaterials
* Needs Testing
* UpdateTexture

View File

@@ -0,0 +1,73 @@
package.path = package.path..";"..RL.GetBasePath().."../resources/lib/?.lua"
Util = require( "utillib" )
Vec2 = require( "vector2" )
Vec3 = require( "vector3" )
Cam3D = require( "camera3d" )
local monitor = 0
local camera = {}
local targetVisible = false
function RL.init()
local mPos = Vec2:new( RL.GetMonitorPosition( monitor ) )
local mSize = Vec2:new( RL.GetMonitorSize( monitor ) )
local winSize = Vec2:new( 1028, 720 )
RL.SetWindowTitle( "Free Camera3D" )
RL.SetWindowState( RL.FLAG_WINDOW_RESIZABLE )
RL.SetWindowState( RL.FLAG_VSYNC_HINT )
RL.SetWindowSize( winSize )
RL.SetWindowPosition( { mPos.x + mSize.x / 2 - winSize.x / 2, mPos.y + mSize.y / 2 - winSize.y / 2 } )
camera = Cam3D:new()
camera:setPosition( { 0, 8, 16 } )
camera:setTarget( { 0, 0, 0 } )
camera:setUp( { 0, 1, 0 } )
-- camera.mode = camera.MODES.ORBITAL
camera.mode = camera.MODES.FREE
-- camera.mode = camera.MODES.FIRST_PERSON
end
function RL.process( delta )
camera:process( delta )
if RL.IsKeyPressed( RL.KEY_SPACE ) then
if camera.mode == camera.MODES.FREE then
camera.mode = camera.MODES.FIRST_PERSON
else
camera.mode = camera.MODES.FREE
end
end
if RL.IsKeyPressed( RL.KEY_T ) then
targetVisible = not targetVisible
end
end
function RL.draw()
RL.ClearBackground( { 100, 150, 100 } )
camera:beginMode3D()
RL.DrawGrid( 16, 1 )
RL.DrawCapsule( { 0, 0, 0 }, { 0, 2, 0 }, 1.0, 8, 6, RL.BLUE )
RL.DrawCapsuleWires( { 0, -0.01, 0 }, { 0, 2.01, 0 }, 1.01, 8, 6, RL.RED )
if targetVisible then
camera:draw()
end
camera:endMode3D()
local text = "Press space to toggle camera mode.\nCurrent mode: "
if camera.mode == camera.MODES.FREE then
text = text.."FREE"
elseif camera.mode == camera.MODES.FIRST_PERSON then
text = text.."FIRST_PERSON"
end
text = text.."\nPress T to toggle target visible.\nVisible: "..tostring( targetVisible )
RL.DrawText( 0, text, { 16, 16 }, 30, 4, RL.WHITE )
end

View File

@@ -33,6 +33,10 @@ function Camera3D:new()
object.camera = RL.CreateCamera3D()
object.mode = object.MODES.CUSTOM
object:setPosition( { 0, 0, 0 } )
object:setTarget( { 0, 0, 0 } )
object:setUp( { 0, 1, 0 } )
return object
end

View File

@@ -18,6 +18,8 @@ int lmodelsDrawCylinder( lua_State *L );
int lmodelsDrawCylinderEx( lua_State *L );
int lmodelsDrawCylinderWires( lua_State *L );
int lmodelsDrawCylinderWiresEx( lua_State *L );
int lmodelsDrawCapsule( lua_State *L );
int lmodelsDrawCapsuleWires( lua_State *L );
int lmodelsDrawPlane( lua_State *L );
int lmodelDrawQuad3DTexture( lua_State *L );
int lmodelsDrawRay( lua_State *L );

View File

@@ -1050,6 +1050,8 @@ void luaRegister() {
assingGlobalFunction( "DrawCylinderEx", lmodelsDrawCylinderEx );
assingGlobalFunction( "DrawCylinderWires", lmodelsDrawCylinderWires );
assingGlobalFunction( "DrawCylinderWiresEx", lmodelsDrawCylinderWiresEx );
assingGlobalFunction( "DrawCapsule", lmodelsDrawCapsule );
assingGlobalFunction( "DrawCapsuleWires", lmodelsDrawCapsuleWires );
assingGlobalFunction( "DrawPlane", lmodelsDrawPlane );
assingGlobalFunction( "DrawQuad3DTexture", lmodelDrawQuad3DTexture );
assingGlobalFunction( "DrawRay", lmodelsDrawRay );

View File

@@ -523,6 +523,62 @@ int lmodelsDrawCylinderWiresEx( lua_State *L ) {
return 1;
}
/*
> success = RL.DrawCapsule( Vector3 startPos, Vector3 endPos, float radius, int slices, int rings, Color color )
Draw a capsule with the center of its sphere caps at startPos and endPos
- Failure return false
- Success return true
*/
int lmodelsDrawCapsule( lua_State *L ) {
if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) || !lua_isnumber( L, 3 )
|| !lua_isnumber( L, 4 ) || !lua_isnumber( L, 5 ) || !lua_istable( L, 6 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.DrawCapsule( Vector3 startPos, Vector3 endPos, float radius, int slices, int rings, Color color )" );
lua_pushboolean( L, false );
return 1;
}
Vector3 startPos = uluaGetVector3Index( L, 1 );
Vector3 endPos = uluaGetVector3Index( L, 2 );
float radius = lua_tonumber( L, 3 );
int slices = lua_tonumber( L, 4 );
int rings = lua_tointeger( L, 5 );
Color color = uluaGetColorIndex( L, 6 );
DrawCapsule( startPos, endPos, radius, slices, rings, color );
lua_pushboolean( L, true );
return 1;
}
/*
> success = RL.DrawCapsuleWires( Vector3 startPos, Vector3 endPos, float radius, int slices, int rings, Color color )
Draw capsule wireframe with the center of its sphere caps at startPos and endPos
- Failure return false
- Success return true
*/
int lmodelsDrawCapsuleWires( lua_State *L ) {
if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) || !lua_isnumber( L, 3 )
|| !lua_isnumber( L, 4 ) || !lua_isnumber( L, 5 ) || !lua_istable( L, 6 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.DrawCapsuleWires( Vector3 startPos, Vector3 endPos, float radius, int slices, int rings, Color color )" );
lua_pushboolean( L, false );
return 1;
}
Vector3 startPos = uluaGetVector3Index( L, 1 );
Vector3 endPos = uluaGetVector3Index( L, 2 );
float radius = lua_tonumber( L, 3 );
int slices = lua_tonumber( L, 4 );
int rings = lua_tointeger( L, 5 );
Color color = uluaGetColorIndex( L, 6 );
DrawCapsuleWires( startPos, endPos, radius, slices, rings, color );
lua_pushboolean( L, true );
return 1;
}
/*
> success = RL.DrawPlane( Vector3 centerPos, Vector2 size, Color color )