diff options
| author | Joel Davis <[email protected]> | 2016-12-31 15:06:39 -0800 |
|---|---|---|
| committer | Joel Davis <[email protected]> | 2016-12-31 15:06:39 -0800 |
| commit | 037da8879a3ae61b09d8388bc2b4a2fe5359256a (patch) | |
| tree | 15f63d24730128f9a3534d20c866f2898e4490e1 /src/shapes.c | |
| parent | 202f45415c98df2201202ba8edb10b6496cbeb62 (diff) | |
| download | raylib-037da8879a3ae61b09d8388bc2b4a2fe5359256a.tar.gz raylib-037da8879a3ae61b09d8388bc2b4a2fe5359256a.zip | |
Added RaycastGround and ray picking example
Diffstat (limited to 'src/shapes.c')
| -rw-r--r-- | src/shapes.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/shapes.c b/src/shapes.c index 3d3333c1..4b2de4f2 100644 --- a/src/shapes.c +++ b/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; }
\ No newline at end of file |
