Game Development Community

3D Math Question

by Ron Nelson · in Game Design and Creative Issues · 09/05/2009 (10:24 pm) · 6 replies

OK I have been beating myself in the head on this one and I hope someone can give me a solution.

OK first you have an object's bounding box.
i72.photobucket.com/albums/i192/DTDA/3DMath1.jpg
Point A is the box center which is an available function in Torque.

Point B is an object colliding with the box.

Point C is where if the object colliding with the box at Point B traveled straight through to the other side of the box.

I cannot figure out Point C.

I can tell that the distance between A and B is as simple as A-B = Distance and that a straight travel from B trough A to the outside of the box would be A+Distance = Straight through center.

However, I am trying to figure this out based upon the vector the object colliding with the box is travelling at.

#1
09/05/2009 (10:36 pm)
You would need to know the Velocity that Object B were traveling in, unless you wanted to base it off the contact normal. In any case, you need *some* normal vector to multiply with the the box's size.
// Fetch Object A's Box Properties.
const Box3F &objABox = objectA->getObjBox();
const Point3F objABoxSize( objABox.len_x(), objABox.len_y(), objABox.len_z() );

// Fetch Object B's Velocity.
VectorF objBVelocity = objectB->getVelocity();
objBVelocity.normalize();

// Determine the Offset.
Point3F pointCOffset = objABoxSize;
pointCOffset.convolve( objBVelocity );

Point3F pointC = pointB + pointCOffset;
I'm no Math whiz, but the above was my first thought. Does anyone else think this make sense?
#2
09/05/2009 (11:21 pm)
Phillip you Rock! thank you so very much. I seriously can't believe it was this easy. I guess thats what happens when you stare at a problem too long. Thanks again.
#3
09/06/2009 (1:18 am)
So it worked ok? You're most welcome!
#4
09/06/2009 (2:35 am)
Just curious - is this for your advanced projectiles? If so, would raycasting be an option? Just cast a ray backwards along the velocity and see where you hit.
#5
09/06/2009 (3:15 am)
Phillip - Yes it worked beautifully, Thanks again.

Daniel - Yes it was for my projectiles code and the method you mentioned is how I used to do it. Unfortunately that lead to huge problems when dealing different sized players, and if you happen to use my player position resource, it really screwwed things up because you had to use some sort of variable to adjust the point to start the raycast at to get to the backside of the player bounding box. Phillip's code was exactly the perfect solution all around because no matter what angle you choose to shoot the player at, the only variable needed was to set how far from the back of the player's bounding box you want to cast. That is just needed so you aren't creating blood splatters twenty meters away from the player and allows you to customize how close you want it for that projectile. Kind of like a super high powered rifle would create splatters further away than a 22 cal. pistol.
#6
09/06/2009 (12:27 pm)
Okay, just curious. I haven't got far in my projectile work, so I might end up pinching this method instead of my planned back-raycasting ;)