summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--API.md6
-rw-r--r--ReiLua_API.lua7
-rw-r--r--examples/ray_box_cells/main.lua8
-rw-r--r--src/core.c4
-rw-r--r--src/models.c27
5 files changed, 35 insertions, 17 deletions
diff --git a/API.md b/API.md
index b6479ac..8aa943f 100644
--- a/API.md
+++ b/API.md
@@ -7989,11 +7989,11 @@ Get collision info between ray and quad
---
-> cells = RL.GetRayBoxCells( Ray ray, BoundingBox box, Vector3 cellSize )
+> cells, exitPoint = RL.GetRayBoxCells( Ray ray, BoundingBox box, Vector3 cellSize )
-Get cell positions inside box that intersect with the ray. Returns empty table if ray misses the box
+Get cell positions inside box that intersect with the ray. Also returns ray exit point. Returns empty table if ray misses the box
-- Success return Vector3{}
+- Success return Vector3{}, RayCollision|nil
---
diff --git a/ReiLua_API.lua b/ReiLua_API.lua
index 2038d70..23977b0 100644
--- a/ReiLua_API.lua
+++ b/ReiLua_API.lua
@@ -5137,12 +5137,13 @@ function RL.GetRayCollisionTriangle( ray, p1, p2, p3 ) end
---@return any rayCollision
function RL.GetRayCollisionQuad( ray, p1, p2, p3, p4 ) end
----Get cell positions inside box that intersect with the ray. Returns empty table if ray misses the box
----- Success return Vector3{}
+---Get cell positions inside box that intersect with the ray. Also returns ray exit point. Returns empty table if ray misses the box
+---- Success return Vector3{}, RayCollision|nil
---@param ray any
---@param box any
---@param cellSize table
----@return any cells
+---@return any cells
+---@return any exitPoint
function RL.GetRayBoxCells( ray, box, cellSize ) end
-- Audio - Audio device management functions
diff --git a/examples/ray_box_cells/main.lua b/examples/ray_box_cells/main.lua
index 9c7e54f..77aa058 100644
--- a/examples/ray_box_cells/main.lua
+++ b/examples/ray_box_cells/main.lua
@@ -16,6 +16,7 @@ local drawCellSize = cellSize:clone()
local ray = nil
local rayCol = nil
local cells = {}
+local exitPoint = {}
local guiMouseHover = false
local spinnerEdit = {
@@ -64,7 +65,7 @@ function RL.update( delta )
ray = RL.GetMouseRay( RL.GetMousePosition(), camera.camera )
rayCol = box:getRayCollision( ray )
- cells = RL.GetRayBoxCells( ray, box:maxToPos(), cellSize )
+ cells, exitPoint = RL.GetRayBoxCells( ray, box:maxToPos(), cellSize )
drawCellSize:setV( cellSize )
end
end
@@ -95,11 +96,12 @@ function RL.draw()
RL.DrawRay( ray, RL.BLUE )
RL.DrawSphere( ray[1], 0.1, RL.GREEN )
end
-
if rayCol and rayCol.hit then
RL.DrawSphere( rayCol.point, 0.1, RL.RED )
end
-
+ if exitPoint.hit then
+ RL.DrawSphere( exitPoint.point, 0.1, RL.RED )
+ end
if cells then
for _, cell in ipairs( cells ) do
RL.DrawCubeWires( box.min + Vector3:tempT( cell ) * drawCellSize + drawCellSize:scale( 0.5 ), drawCellSize, RL.RED )
diff --git a/src/core.c b/src/core.c
index ed7641b..e93ca63 100644
--- a/src/core.c
+++ b/src/core.c
@@ -2532,7 +2532,9 @@ Check if a mouse button is NOT being pressed
int lcoreIsMouseButtonUp( lua_State* L ) {
int button = luaL_checkinteger( L, 1 );
- lua_pushboolean( L, IsMouseButtonUp( button ) );
+ /* IsMouseButtonUp is broken. Review when fixed in raylib. */
+ lua_pushboolean( L, !IsMouseButtonDown( button ) );
+ // lua_pushboolean( L, IsMouseButtonUp( button ) );
return 1;
}
diff --git a/src/models.c b/src/models.c
index f16620c..d33e130 100644
--- a/src/models.c
+++ b/src/models.c
@@ -2547,11 +2547,11 @@ static inline bool isInsideBox( Vector3 position, BoundingBox box ) {
}
/*
-> cells = RL.GetRayBoxCells( Ray ray, BoundingBox box, Vector3 cellSize )
+> cells, exitPoint = RL.GetRayBoxCells( Ray ray, BoundingBox box, Vector3 cellSize )
-Get cell positions inside box that intersect with the ray. Returns empty table if ray misses the box
+Get cell positions inside box that intersect with the ray. Also returns ray exit point. Returns empty table if ray misses the box
-- Success return Vector3{}
+- Success return Vector3{}, RayCollision|nil
*/
int lmodelsGetRayBoxCells( lua_State* L ) {
Ray ray = uluaGetRay( L, 1 );
@@ -2633,19 +2633,32 @@ int lmodelsGetRayBoxCells( lua_State* L ) {
absCell = Vector3Add( absCell, move );
cellPos = Vector3Add( cellPos, Vector3Multiply( move, signs ) );
- if ( absCell.x < absBounds.x && absCell.y < absBounds.y && absCell.z < absBounds.z ) {
- absPos = Vector3Add( absPos, Vector3Scale( absDir, fmin( fmin( cellDis.x, cellDis.y ), cellDis.z ) ) );
+ float rayMoveScale = fmin( fmin( cellDis.x, cellDis.y ), cellDis.z );
+
+ absPos = Vector3Add( absPos, Vector3Scale( absDir, rayMoveScale ) );
+ localRayPos = Vector3Add( localRayPos, Vector3Scale( ray.direction, rayMoveScale ) );
+ if ( absCell.x < absBounds.x && absCell.y < absBounds.y && absCell.z < absBounds.z ) {
uluaPushVector3( L, (Vector3){ round( cellPos.x ), round( cellPos.y ), round( cellPos.z ) } );
lua_rawseti( L, -2, cellId );
cellId++;
}
else {
- break;
+ Vector3 exitPoint = Vector3Add( localRayPos, box.min );
+
+ uluaPushRayCollision( L, (RayCollision){
+ .hit = true,
+ .distance = Vector3Distance( ray.position, exitPoint ),
+ .point = exitPoint,
+ .normal = Vector3Multiply( move, Vector3Negate( signs ) )
+ } );
+
+ return 2;
}
}
}
+ lua_pushnil( L );
- return 1;
+ return 2;
}