Added RaycastGround and ray picking example
This commit is contained in:
parent
202f45415c
commit
037da8879a
4 changed files with 159 additions and 0 deletions
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;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue