3
\$\begingroup\$

I've been trying to write my own collision code, less because I want to, more because I want to understand its working.

To do this, i've been working off of the popular collision book i'm sure you've all heard of: Morgan Kaufmann Real Time Collision.

I'm on the subject of Oriented Bounding Boxes. These are boxes that can have an orientaiton applied to them. If it matters, i'm doing my code in 2D. It seems easy enough to just cut out an axis from the books calculations.

Here is the OBB they define:

// Region R = { x | x = c+r*u[0]+s*u[1]+t*u[2] }, |r|<=e[0], |s|<=e[1], |t|<=e[2]
struct OBB {
    Point c;     // OBB Center Point
    Vector u[3]; // Local x-, y-, and z-axes
    Vector e     // Positive halfwidth extents of OBB along each axis
};

The confusing one is the Vector array, u.

Point c is the center 3 axis position of the box. Vector e is the width, height, and length of the box. Vector u[3] baffles me. My best guess is that it is the center-point of each of the 3 sides (with the reflected 3 finishing the box)

How does rotation work into this? Is the Vector u[3] taking the roation in somehow? How?

\$\endgroup\$

3 Answers 3

6
\$\begingroup\$

The u[3] is a 3x3 rotation matrix mapping from the OBB's local space to world space. The three elements are the vectors that the x, y, and z axes of local space end up being mapped to by the rotation. So your guess was somewhat correct - the vectors do point to the center of each of three perpendicular sides of the OBB. However, they are unit vectors; the actual (half-)size of the OBB along each axis is stored in e.

The answer is actually in the comment above the struct. The expression r*u[0]+s*u[1]+t*u[2] is just multiplying the vector (r, s, t) by the 3x3 matrix u[3].

For 2D, the equivalent of this data structure would have only a 2x2 rotation matrix, so you could define it as Vector2D u[2].

\$\endgroup\$
5
  • \$\begingroup\$ Makes sense, thank you. I'll have to go about implementing Matrices now, or at least multiplication via arrays of vectors. To clarify, whenever I set the rotation (say to 1.3 rads), I clean out u, set it to an identity, then apply a rotation of 1.3 rads to it, right? \$\endgroup\$
    – MintyAnt
    Feb 11, 2013 at 1:34
  • \$\begingroup\$ @MintyAnt Yes, though you can just set u to the rotation matrix directly, rather than setting it to the identity first and then multiplying in a rotation. \$\endgroup\$ Feb 11, 2013 at 18:19
  • \$\begingroup\$ Not sure this is quite right. The 3 vectors are what's known as the Orthonormal Basis of the orientated box. Effectively the local coordinate system. \$\endgroup\$
    – Robinson
    Nov 10, 2015 at 17:38
  • \$\begingroup\$ @Robinson That's true, but I don't see where that conflicts with what I said? \$\endgroup\$ Nov 10, 2015 at 18:47
  • \$\begingroup\$ It doesn't. Just want to put a keyword in there that corresponds to the actual meaning in the context of the code fragment. \$\endgroup\$
    – Robinson
    Nov 10, 2015 at 20:37
1
\$\begingroup\$

The statement Vector u[3] is a matrix. A common method in computing and programming for performing rotations is to use an array of vectors to represent a matrix that defines the rotation of the object. In order to create a rotation matrix for an object you simply take a matrix of the same dimensions (in this case 3x3) and use the rotations in all three coordinate directions to construct a general matrix form.

A good resource for information on rotation matrices is the wikipedia page: http://en.wikipedia.org/wiki/Rotation_matrix

For 2D there is only one rotation matrix to think of which is as such:

float theta;     // the angle of rotation
R= {{cos(theta), -sin(theta)},
    {sin(theta),  cos(theta)};

Once you get into 3 dimensional space rotation matrices tend to look a lot more complicated than they really are. In three dimensional space you can form a single rotation matrix simply by multiplying the rotation matrix for each coordinate directions like such:

 GenRotMatrix= XRotMatrix * YRotMatrix * ZRotMatrix;

Information for rotations of objects are commonly kept in an object known as a transform. The transform generally defines the position, scaling and rotation of an object in the world space.

I am not familiar with the book itself, so I cannot say with impunity that this is what he is doing as in computin there is always several ways of doing things. But if I had to hazard a guess this would be what he is doing. And the vector u is simply the general rotation matrix GenRotMatrix from above which represents the objects rotation in world space.

\$\endgroup\$
-1
\$\begingroup\$

Is u[3] the direction the box is rotated in?

Think of a box centered at the origin, rotated by a vector (u) and then shifted to c.

\$\endgroup\$
1
  • \$\begingroup\$ u isn't a single vector, it is 3 vectors (forming a 3x3 matrix) \$\endgroup\$
    – bobobobo
    Feb 10, 2013 at 19:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .