Jump to content
  • Advertisement
Sign in to follow this  
uglybdavis

Moving Sphere into OBB space

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

If you intended to correct an error in the post then please contact us.

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);

    Sphere s2(sPos.x, sPos.y, sPos.z, sphere.radius);

    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 this post


Link to post
Share on other sites
Advertisement

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 this post


Link to post
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 this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!