Game Development Community

Changing a bounding box position

by Bryce · in Torque Game Engine · 01/10/2009 (8:06 am) · 7 replies

Hello everyone,

I've got a function in C++ which needs to shift a player's bounding box a few meters in a direction. I'm wokring with this block of code:
F32 len_x, len_y, len_z;
         len_x = 0.7;
         len_y = 0.7;
         len_z = 2.275;

         mObjBox.max.x = len_x * 0.5;
         mObjBox.max.y = len_y * 0.5;
         mObjBox.max.z = len_z;
         mObjBox.min.x = -mObjBox.max.x;
         mObjBox.min.y = -mObjBox.max.y;
         mObjBox.min.z = 0;
      }
	  onScaleChanged();

All of this 3D-position math confuses me a little...Is there a way to manipulate the mObjBox fields to just shift the bounding box position, say, 2 meters to the left?
Help is always appreciated!

#1
01/10/2009 (3:37 pm)
Well, first off, is there any way you could create a new Box3F that is shifted to the side? It's just that I see that as being more efficient than having to shift the player's bounding box, and than shift it back once the function is over. Also, to who's left? I'm guessing the Player who's box is in question? Than you'll need to use their -sideVector.

So here's something just assuming you want to shift the coordinates of the box. This of course keeps the box's "position" equal to the player's position, and only shifts the 2 corner points. I think this should work, but then again, I could be confusing the ideas with something else...so give it a try.

Point3F sideVec  = getTransform().getColumn(0, &sideVector); //It may be getRow instead
//This vector points to the players right, so make it negative for the left
sideVec.neg();
Point3F axisVector = Point3F(1,0,0);
mObjBox.max.x += mDot(axisVector, sideVec);
mObjBox.min.x += mDot(axisVector, sideVec);
axisVector = Point3F(0,1,0);
mObjBox.max.y += mDot(axisVector, sideVec);
mObjBox.min.y += mDot(axisVector, sideVec);

And then from there, you'll need to reset the mObjBox back to what it was originally once whatever your function does is finished.
#2
01/10/2009 (6:11 pm)
Hmmm...not working, I'm not seeing any box changes in the world editor
Darn my misunderstanding of 3d math!
#3
01/10/2009 (6:46 pm)
Just a thought, but make sure that these changes are getting passed from client-to-server and vice-a-versa.

I did some messing around with "bounds or positions or something" ages ago (can't remember exactly what anymore!) and I noticed that changes I made in the client (using script not C++) didn't get passed to the server, which meant that the physicality of the object only appeared to change on screen but stayed at it's origin in the server's world --- or the other way around, I can't remember which.

I think that's about the limit of making myself useful for this problem! I still don't C++ :P
#4
01/11/2009 (7:33 am)
The client-server stuff is included (Im using the multiple player positions resource). What I'm trying to do is move the bounding box for AI Players who are stepping out of cover. Originally, I had the bounding box stretch when the step-out-of-cover animation plays, but there were then some issues with visibility.

Shouldn't there be some kind of box.x += 1 capability or something along those lines?
#5
01/11/2009 (8:12 am)
For your specific application, it's not possible to just ask them to move out of cover? As for moving the whole bounding box... have you checked out resources like Erik Madison's player positions resource? Other peoples' upgrades to this resource have done some dynamic bounding box stuff, which might give you a clue how to do it.
Or even implementing hitboxes, so that it doesn't matter where their bounding box is. That way you get locational damage as a bonus ;)
#6
01/11/2009 (9:38 am)
Quote:Shouldn't there be some kind of box.x += 1 capability or something along those lines?
The way bounding boxes work is they have min and max points, which are 2 opposite corners of the box. Based on these 2 corners it can assume the shape of the rest of the box. So you don't just directly effect the boxes x length, but you can through the min and max points. I've no idea why the bounding box wasn't updating in the mission editor. Maybe calls just aren't directly made to update the bounding box's rendering?

It turns out that mObjBox is in local space, not world space, so most of my code was unnecessary.
mObjBox.max.x -= 2;
mObjBox.min.x -= 2; //Remove this line if you want the box to stretch but not shift
Would actually achieve the same thing :p
#7
01/11/2009 (3:59 pm)
Ah, that worked. Thank you very much!