Added collision check between ray and box
- Added CheckCollisionRayBox() function. - Updated and improved core 3d picking example (currently working as expected).
This commit is contained in:
parent
4a637191f2
commit
1793f2c3b8
3 changed files with 32 additions and 3 deletions
20
src/models.c
20
src/models.c
|
@ -1336,6 +1336,26 @@ bool CheckCollisionBoxSphere(Vector3 minBBox, Vector3 maxBBox, Vector3 centerSph
|
|||
return collision;
|
||||
}
|
||||
|
||||
// Detect collision between ray and box
|
||||
bool CheckCollisionRayBox(Ray ray, Vector3 minBBox, Vector3 maxBBox)
|
||||
{
|
||||
bool collision = false;
|
||||
|
||||
float t[8];
|
||||
t[0] = (minBBox.x - ray.position.x) / ray.direction.x;
|
||||
t[1] = (maxBBox.x - ray.position.x) / ray.direction.x;
|
||||
t[2] = (minBBox.y - ray.position.y) / ray.direction.y;
|
||||
t[3] = (maxBBox.y - ray.position.y) / ray.direction.y;
|
||||
t[4] = (minBBox.z - ray.position.z) / ray.direction.z;
|
||||
t[5] = (maxBBox.z - ray.position.z) / ray.direction.z;
|
||||
t[6] = fmax(fmax(fmin(t[0], t[1]), fmin(t[2], t[3])), fmin(t[4], t[5]));
|
||||
t[7] = fmin(fmin(fmax(t[0], t[1]), fmax(t[2], t[3])), fmax(t[4], t[5]));
|
||||
|
||||
collision = !(t[7] < 0 || t[6] > t[7]);
|
||||
|
||||
return collision;
|
||||
}
|
||||
|
||||
// TODO: Useful function to check collision area?
|
||||
//BoundingBox GetCollisionArea(BoundingBox box1, BoundingBox box2)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue