diff options
| author | jussi | 2024-07-20 15:29:50 +0300 |
|---|---|---|
| committer | jussi | 2024-07-20 15:29:50 +0300 |
| commit | c6eb85b3674c36cfc426486d866a78dfc5452ae0 (patch) | |
| tree | 2682f880b3254bf1901556da809f5475b2693ccc /src | |
| parent | 03e9226b5f6c3fe4d113759b3a023ee92d7b2d4f (diff) | |
| download | reilua-enhanced-c6eb85b3674c36cfc426486d866a78dfc5452ae0.tar.gz reilua-enhanced-c6eb85b3674c36cfc426486d866a78dfc5452ae0.tar.bz2 reilua-enhanced-c6eb85b3674c36cfc426486d866a78dfc5452ae0.zip | |
GetRayBoxCells also returns exit point.
Diffstat (limited to 'src')
| -rw-r--r-- | src/core.c | 4 | ||||
| -rw-r--r-- | src/models.c | 27 |
2 files changed, 23 insertions, 8 deletions
@@ -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; } |
