Currently, I am trying to align an object to the surface or the normal it is on. This is easy enough in most case, as I just recalculate the orthonormal basis of the object from it's previous forward, up and right vectors. This allows me to also maintain the rotation of the object. I do this like so:
Code: Select all
core::matrix4 trans = fairyNode->getRelativeTransformation();
core::vector3df oldY(0.f, 1.f, 0.f);
core::vector3df oldX(1.f, 0.f, 0.f);
core::vector3df oldZ(0.f, 0.f, 1.f);
trans.rotateVect(oldY);
trans.rotateVect(oldZ);
trans.rotateVect(oldX);
oldX.normalize();
oldY.normalize();
oldZ.normalize();
core::vector3df nForward = oldX.crossProduct(normal);
core::vector3df nRight = normal.crossProduct(nForward);
My question: Does anyone know of a simple and elegant (actually, any) way of handling this situation? It's easy enough to test for the zero vector using an epsilon, but then what? I'm thinking I could do a rotation, but I'd much rather do this in vector space.
Any pointers would be appreciated.
Happy coding!