# Moving Sphere into OBB space

This topic is 2058 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I have some code that is working just fine, it moves a sphere into an OBB's local space, then performs a OBB-AABB test. I have a peculiar issue tough:

bool OBBSphere(const OBB& obb, const Sphere& sphere) {

Matrix aRot;

aRot.mat16f[0] = obb.localX[0];

aRot.mat16f[4] = obb.localX[1];

aRot.mat16f[8] = obb.localX[2];

aRot.mat16f[1] = obb.localY[0];

aRot.mat16f[5] = obb.localY[1];

aRot.mat16f[9] = obb.localY[2];

aRot.mat16f[2] = obb.localZ[0];

aRot.mat16f[6] = obb.localZ[1];

aRot.mat16f[10] = obb.localZ[2];

aRot = aRot.Transpose();

aRot.mat16f[3] = obb.x;

aRot.mat16f[7] = obb.y;

aRot.mat16f[11] = obb.z;

aRot = aRot.Inverse();

Vector sPos(sphere.x, sphere.y, sphere.z);

sPos.w = 1.0f;

sPos = aRot.Multiply(sPos);

AABB aabb(-obb.halfSize[0], -obb.halfSize[1], -obb.halfSize[2], obb.halfSize[0], obb.halfSize[1], obb.halfSize[2]);

return AABBSphere(aabb, s2);

}

I use the OBB's local rotation to populate the rotation part of a matrix, then it's position for the translation. Then i invert the matrix and multiply the sphere by it.

BEFORE the invert, if i don't transpose the matrix after populating the rotation, everything breaks.

To my knowledge, the basis matrix for openGL is:

| Xx  Yx  Zx  Tx |

| Xy  Yy  Zy  Ty |

| Xz  Yz  Zz  Tz |

| 0    0    0    1   |

So, why do i have to transpose? I don't understand.

Thanks!

##### Share on other sites

Is it:

aRot contains information to take a point from world space to obb space.

Transpose

aRot now contains information to take a point form obb space to world space.

Invert

aRot now contains information to take a point from world space to obb space.

##### Share on other sites

I'm not sure if this is exactly what your wondering or not..

but your transpose should be 3 elements - transform scaling, transform position, and transform rotation - these three things are order dependent.

If you scale then rotate then transpose the position you usually get the results you want (scale the object to the right size, rotate the object, then move it where it should be)

the rotation rotates the object around the origin (x y and z axis) and so this is usually what you want.

If you change the order then you get completely different results ( scale the object to the right size, move the object where is should be, then rotate the object ) - the rotation here still rotates the object around the origin which means if it is at x = 10 then rotating 180 degrees will change the position to x = -10 (rotates about the x axis).

Forgive me if I'm stating things you already know - my point is just that most matrix operations are order dependent

##### Share on other sites

I'd recommend researching Separating Axis Tests.

http://www.codezealot.org/archives/55

(There's no need for any transposing or inverting a matrix.  Just projecting/dot products, of two objects geometry, to a line. Then check for overlap. )

1. 1
2. 2
Rutin
19
3. 3
4. 4
khawk
15
5. 5
A4L
13

• 13
• 26
• 10
• 11
• 44
• ### Forum Statistics

• Total Topics
633743
• Total Posts
3013643
×