GetRayBoxCells fix.

This commit is contained in:
jussi
2024-08-05 23:35:57 +03:00
parent c6eb85b367
commit b011b2ca4e
16 changed files with 126 additions and 60 deletions

View File

@@ -755,6 +755,7 @@ static void defineGlobals() {
assignGlobalColor( RAYWHITE, "RAYWHITE" ); // My own White (raylib logo)
/* Math */
assignGlobalFloat( PI, "PI" ); // Pi
assignGlobalFloat( EPSILON, "EPSILON" ); // Epsilon
assignGlobalFloat( DEG2RAD, "DEG2RAD" ); // Degrees to radians
assignGlobalFloat( RAD2DEG, "RAD2DEG" ); // Radians to degrees
/* Gui control state */

View File

@@ -2516,7 +2516,7 @@ int lmodelsGetRayCollisionTriangle( lua_State* L ) {
/*
> rayCollision = RL.GetRayCollisionQuad( Ray ray, Vector3 p1, Vector3 p2, Vector3 p3, Vector3 p4 )
Get collision info between ray and quad
Get collision info between ray and quad. NOTE: The points are expected to be in counter-clockwise winding
- Success return RayCollision
*/
@@ -2599,11 +2599,6 @@ int lmodelsGetRayBoxCells( lua_State* L ) {
0.0f <= ray.direction.z ? 1.0f : -1.0f
};
/* We transform everything to absolute space to make this simpler. */
Vector3 absBounds = {
0.0f < signs.x ? boxSizeCells.x - cellPos.x : cellPos.x + 1.0f,
0.0f < signs.y ? boxSizeCells.y - cellPos.y : cellPos.y + 1.0f,
0.0f < signs.z ? boxSizeCells.z - cellPos.z : cellPos.z + 1.0f
};
Vector3 absDir = {
fabsf( ray.direction.x ),
fabsf( ray.direction.y ),
@@ -2614,6 +2609,21 @@ int lmodelsGetRayBoxCells( lua_State* L ) {
0.0f < signs.y ? localRayPos.y - cellPos.y * cellSize.y : cellSize.y - ( localRayPos.y - cellPos.y * cellSize.y ),
0.0f < signs.z ? localRayPos.z - cellPos.z * cellSize.z : cellSize.z - ( localRayPos.z - cellPos.z * cellSize.z )
};
Vector3 absBounds = {
0.0f < signs.x ? boxSize.x - localRayPos.x : localRayPos.x,
0.0f < signs.y ? boxSize.y - localRayPos.y : localRayPos.y,
0.0f < signs.z ? boxSize.z - localRayPos.z : localRayPos.z
};
absBounds = Vector3Add( absBounds, absPos );
Vector3 exitDis = {
( absBounds.x - absPos.x ) / absDir.x,
( absBounds.y - absPos.y ) / absDir.y,
( absBounds.z - absPos.z ) / absDir.z
};
float exitScale = fmin( fmin( exitDis.x, exitDis.y ), exitDis.z );
Vector3 exitPoint = Vector3Add( Vector3Scale( ray.direction, exitScale ), Vector3Add( localRayPos, box.min ) );
Vector3 absCell = { 0, 0, 0 };
int cellId = 2; /* We already added first so we will start at 2. */
@@ -2636,17 +2646,14 @@ int lmodelsGetRayBoxCells( lua_State* L ) {
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 ) {
if ( absPos.x < absBounds.x && absPos.y < absBounds.y && absPos.z < absBounds.z ) {
uluaPushVector3( L, (Vector3){ round( cellPos.x ), round( cellPos.y ), round( cellPos.z ) } );
lua_rawseti( L, -2, cellId );
cellId++;
}
else {
Vector3 exitPoint = Vector3Add( localRayPos, box.min );
uluaPushRayCollision( L, (RayCollision){
.hit = true,
.distance = Vector3Distance( ray.position, exitPoint ),

View File

@@ -99,6 +99,7 @@ int lcoreGetKeyScancode( lua_State* L ) {
Called when the window is resized. Type GLFW_WINDOW_SIZE_EVENT
*/
static void windowSizeEvent( GLFWwindow* window, int width, int height ) {
// GLFWwindowsizefun windowSizeEvent( GLFWwindow* window, int width, int height ) {
/* Pass through to raylib callback. */
state->raylibWindowSizeCallback( window, width, height );
@@ -617,7 +618,7 @@ static void penTabletProximityEvent( int proxState ) {
static void platformRegisterEvents() {
/* Window events. */
state->raylibWindowSizeCallback = glfwSetWindowSizeCallback( GetWindowHandle(), windowSizeEvent );
state->raylibWindowSizeCallback = glfwSetWindowSizeCallback( GetWindowHandle(), (GLFWwindowsizefun)windowSizeEvent );
#if !defined( PLATFORM_WEB )
state->raylibWindowMaximizeCallback = glfwSetWindowMaximizeCallback( GetWindowHandle(), windowMaximizeEvent );
#endif
@@ -634,9 +635,9 @@ static void platformRegisterEvents() {
state->raylibCursorEnterCallback = glfwSetCursorEnterCallback( GetWindowHandle(), cursorEnterInputEvent );
state->raylibJoystickCallback = glfwSetJoystickCallback( joystickEvent );
/* NOTE! Experimental. Needs glfw PR https://github.com/glfw/glfw/pull/1445 */
// state->glfwtabletDataCallback = glfwSetPenTabletDataCallback( penTabletDataEvent );
// state->glfwtabletCursorCallback = glfwSetPenTabletCursorCallback( penTabletCursorEvent );
// state->glfwtabletProximityCallback = glfwSetPenTabletProximityCallback( penTabletProximityEvent );
// state->glfwTabletDataCallback = glfwSetPenTabletDataCallback( penTabletDataEvent );
// state->glfwTabletCursorCallback = glfwSetPenTabletCursorCallback( penTabletCursorEvent );
// state->glfwTabletProximityCallback = glfwSetPenTabletProximityCallback( penTabletProximityEvent );
}
void luaPlatformRegister() {

View File

@@ -255,7 +255,7 @@ Generate image: plain color
*/
int ltexturesGenImageColor( lua_State* L ) {
Vector2 size = uluaGetVector2( L, 1 );
Color color = uluaGetColor( L, 1 );
Color color = uluaGetColor( L, 2 );
uluaPushImage( L, GenImageColor( size.x, size.y, color ) );