Added RaycastGround and ray picking example

This commit is contained in:
Joel Davis 2016-12-31 15:06:39 -08:00
parent 202f45415c
commit 037da8879a
4 changed files with 159 additions and 0 deletions

View file

@ -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;
}