Hi Guys!
I have a dumb question, i know, they are a couple of solutions in this forum but i dont understand how it realy works…
lets say, i have
ofVec3f BoxUpVector (0,1,0);
ofVec3f BoxNormalVector(0,0,1);
some Object for ex.
ofDrawBox(bla bla bla);
and i have two others vectors
ofVec3f NewUpVector (-0.608556, 0.789434, 0.0803312);
ofVec3f NewNormalVector(0.20675, 0.060007, 0.976552);
The BoxUpVector and BoxNormalVector are Vectors that describe a rotation of the Box. How can i rotate my Box, so my BoxUpVector is aligned with NewUpVector and BoxNormalVector with NewNormalVector?
ive tryed this, but it does not works every time.
ofPushMatrix();
// align Normal Vectors
ofVec3f CrossNewBoxNormals = NewNormalVector.getCrossed(BoxNormalVector);
float AngleBetweenNewBox = NewNormalVector.angle(BoxNormalVector);
ofRotate(AngleBetweenNewBox, CrossNewBoxNormals.x, CrossNewBoxNormals.y, CrossNewBoxNormals.z);
// rotate BoxUpVector
ofVec3f RotatedBoxUpVector = BoxUpVector.getRotated(AngleBetweenNewBox, CrossNewBoxNormals);
// Align Up Vectors
ofVec3f CrossUpVectors = RotatedBoxUpVector.getCrossed(NewUpVector);
int RotationDirection = CrossUpVectors.angle(NewNormalVector) < 1? 1: -1;
float AngleBetweenUpVectors = RotatedBoxUpVector.angle(NewUpVector) * RotationDirection;
// Rotate
ofRotateZ(AngleBetweenUpVectors);
// Draw this sh...
ofDrawBox (0,0,0,100,200,300);
ofPopMatrix();
any suggestions?