Rotating bounding box
Rotating bounding box
I wish to rotate a bounding box (not a simple character controller this time), how do i do that? I tried playing around with the .orientationmatrix but i dont quite get how to use it..
Re: Rotating bounding box
If you are referring to an actual axis-aligned bounding box (like the BoundingBox used by entities), it is impossible. By definition, they are axis aligned. Rotating the object that a bounding box contains will only change the dimensions of the bounding box.
If you just want to rotate a normal Box entity or something, then just changing the Orientation or OrientationMatrix properties will suffice.
If you just want to rotate a normal Box entity or something, then just changing the Orientation or OrientationMatrix properties will suffice.
Re: Rotating bounding box
I created a box and attached an entity to it. Thus, the entity will take up the position of the box. However, the created box will not be facing the right way. I want to create a box right in front of the character. Like an ice wall. However, its orientated wrongly (the ice wall is a rectangle). How do i make sure it appears rightly?
The ice wall is like this :
http://www.youtube.com/watch?v=dmJdKSSg ... re=related
right now my codes are like this
toAdd = new Box(mageFacingDirection*8 + icewallPosition, 2F, 0F, 8F, 500);
wallModel = new EntityModel(toAdd, IceWallModel, Matrix.Identity, game);
The ice wall is like this :
http://www.youtube.com/watch?v=dmJdKSSg ... re=related
right now my codes are like this
toAdd = new Box(mageFacingDirection*8 + icewallPosition, 2F, 0F, 8F, 500);
wallModel = new EntityModel(toAdd, IceWallModel, Matrix.Identity, game);
Re: Rotating bounding box
There's many ways to compute rotation matrices. None of them are specific to the physics engine, but here's a couple of options.
-A rotation matrix is an orthonormal basis. You have one of the axes already (facing direction). You need the two others to uniquely specify a rotation matrix. You could choose the second one to be the world up vector. The third one can be the side-facing direction, if you have it already computed, or you can compute by taking the cross product of the Up and Forward directions. Once you have the complete normalized basis, you can create the rotation by setting the appropriate vector properties. (matrix.Forward = ForwardDirection, matrix.Right = RightDirection, Matrix.Up = UpDirection)
-Create a rotation matrix from the facing angle. It corresponds to some yaw angle around the Y axis. Compute that, and use one of the XNA functions to create the matrix.
-A rotation matrix is an orthonormal basis. You have one of the axes already (facing direction). You need the two others to uniquely specify a rotation matrix. You could choose the second one to be the world up vector. The third one can be the side-facing direction, if you have it already computed, or you can compute by taking the cross product of the Up and Forward directions. Once you have the complete normalized basis, you can create the rotation by setting the appropriate vector properties. (matrix.Forward = ForwardDirection, matrix.Right = RightDirection, Matrix.Up = UpDirection)
-Create a rotation matrix from the facing angle. It corresponds to some yaw angle around the Y axis. Compute that, and use one of the XNA functions to create the matrix.
Re: Rotating bounding box
I only need to set the rotation Y rather than all the other axis. When i try to do that, it says cannot implictly convert type Vector3 to Quaternion.
I have no idea how to use quaternion :/
I have no idea how to use quaternion :/
Re: Rotating bounding box
It will be simpler to just use the matrix representation; just ignore the quaternion property. All the matrix direction properties can be set to vectors.
Re: Rotating bounding box
Also, the reason why one of my suggestions involved creating a full basis is that a rotation matrix is a full basis. A single direction vector cannot uniquely specify the whole orientation.
You can, however, use the helper methods in the xna matrix class (and the BEPUphysics Matrix3X3 matrix class) to create a matrix from an axis and angle. That process completely defines the rotation and creates the full basis internally.
You can, however, use the helper methods in the xna matrix class (and the BEPUphysics Matrix3X3 matrix class) to create a matrix from an axis and angle. That process completely defines the rotation and creates the full basis internally.
Re: Rotating bounding box
sorry but i've been trying to read up on matrices but i still dont get it. What kind of matrix does the orientationmatrix use? how to i set the forward right and up direction?
Re: Rotating bounding box
I tried assigning the orientation to be the same as the camera. However the rotation dont seem to be working. Is it because it is AABB ? I'm not sure how do i not use AABB ?
-edit-
Oh yeah i confirmed its AABB. Thus, i couldn't rotate in the y-axis. Are there other ways to do this?
-edit-
Oh yeah i confirmed its AABB. Thus, i couldn't rotate in the y-axis. Are there other ways to do this?
Re: Rotating bounding box
The orientation matrix's type is Matrix3X3. You can also use a normal XNA matrix and then convert it to a Matrix3X3 using one of the Matrix3X3 static helper methods. Both types have properties like Up, Right, and Forward that have getters and setters.
I'm not really capable of teaching linear algebra efficiently on the forum, so if that is where you are running into trouble, it may be a good idea to just focus on getting some of those basics down.
http://patrickjmt.com/ has an absolutely huge amount of lessons over just about everything in common math curricula up through undergraduate college levels. The linear algebra section would be the relevant part. Khan Academy (http://www.khanacademy.org/#browse) is another extremely helpful site- it has even more lessons.
There are some other geometrical resources that can come in handy for this sort of thing too. http://www.euclideanspace.com/ is a great reference for a lot of different things.
Obviously, that's a little overkill for trying to figure out how to orient a box
But, having that background is very valuable in 3d programming.
I'm not really capable of teaching linear algebra efficiently on the forum, so if that is where you are running into trouble, it may be a good idea to just focus on getting some of those basics down.
http://patrickjmt.com/ has an absolutely huge amount of lessons over just about everything in common math curricula up through undergraduate college levels. The linear algebra section would be the relevant part. Khan Academy (http://www.khanacademy.org/#browse) is another extremely helpful site- it has even more lessons.
There are some other geometrical resources that can come in handy for this sort of thing too. http://www.euclideanspace.com/ is a great reference for a lot of different things.
Obviously, that's a little overkill for trying to figure out how to orient a box

The Box entity itself is not an AABB, it can rotate. You may be using the camera's view matrix instead of the camera's world matrix. They are inverses of each other.I tried assigning the orientation to be the same as the camera. However the rotation dont seem to be working. Is it because it is AABB ? I'm not sure how do i not use AABB ?
Re: Rotating bounding box
Make sure you're not using the entity.CollisionInformation.BoundingBox. That bounding box is indeed axis-aligned. However, the Box shape that represents the actual collision geometry (and is contained WITHIN the bounding box) is not axis aligned.Oh yeah i confirmed its AABB. Thus, i couldn't rotate in the y-axis. Are there other ways to do this?