translating model coodinates into world coodinates
I recently created a level for my project and I am able to load it and display it. I''m trying to do axis aligned bounding box collision detection between the player and the world but when the player bounding box collides with a bounding box of a world objects the player goes through the object. I assume it is because the positions of the world objects are not in world coordinates but in object coordinates. How would I go about translating the positions of the objects into world coordinates?
P.S. I''m using the equation (max + min)/2 (of the world object bounding box) to get the position of the world objects.
www.lefthandinteractive.net
that''s basically it, but reversed
You calculate the min, max of the object''s bounding box based on it''s local box''s min and max values and the position of the object.
what this algo does is, if the box collides, it puts the player to a position where he did not collide previously. it''s very simple, very dodgy, it''s just an example.

bool Collide(CBox playerbox, CBox worldbox){ if (playerbox.min.x > worldbox.max.x || playerbox.max.x < worldbox.min.x) return false; if (playerbox.min.y > worldbox.max.y || playerbox.max.y < worldbox.min.y) return false; if (playerbox.min.z > worldbox.max.z || playerbox.max.z < worldbox.min.z) return false; return true;}void ProcessCollision(){ CBox playerbox; CBox worldbox; playerbox.min = player.localbox.min + player.position; playerbox.max = player.localbox.max + player.position; bool collided = false; for(int i = 0; i < numobjects; i ++) { worldbox.min = object[i].localbox.min + object.position; worldbox.max = object[i].localbox.max + object.position; if (Collide(playerbox, worldbox)) { collided = true; break; } } if (collided) player.position = player.last_valid_position; else player.last_valid_position = player.position ;}
what this algo does is, if the box collides, it puts the player to a position where he did not collide previously. it''s very simple, very dodgy, it''s just an example.
Everything is better with Metal.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement