mirror of
https://github.com/raysan5/raylib.git
synced 2025-09-16 16:28:14 +00:00
Added RaycastGround and ray picking example
This commit is contained in:
20
src/shapes.c
20
src/shapes.c
@@ -533,4 +533,24 @@ Rectangle GetCollisionRec(Rectangle rec1, Rectangle rec2)
|
||||
}
|
||||
|
||||
return retRec;
|
||||
}
|
||||
|
||||
|
||||
RayHitInfo RaycastGroundPlane( Ray ray, float groundHeight )
|
||||
{
|
||||
RayHitInfo result = {0};
|
||||
|
||||
if (fabs(ray.direction.y) > EPSILON)
|
||||
{
|
||||
float t = (ray.position.y - groundHeight) / -ray.direction.y;
|
||||
if (t >= 0.0) {
|
||||
Vector3 camDir = ray.direction;
|
||||
VectorScale( &camDir, t );
|
||||
result.hit = true;
|
||||
result.hitNormal = (Vector3){ 0.0, 1.0, 0.0};
|
||||
result.hitPosition = VectorAdd( ray.position, camDir );
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
Reference in New Issue
Block a user