To simplify, essentially I want to take a line, rotate it, and translate it to fit between two points.
I have points, A, B, and C.
mesh.addVertex(ofVec3f(-150,0,0)); //A mesh.addVertex(ofVec3f(150,0,0)); //B mesh.addVertex(ofVec3f(-150,100,50)); //C
I have calculated the length between each, and, creating a line, with the midpoint being at (0,0,0), I am trying to perform quaternion rotation and then translate it to fit between it’s respective points.
//In Setup: angleRotX = atan2((destP.y-originP.y),(destP.z-originP.z))*180/PI; angleRotY = atan2((destP.z-originP.z),(destP.x-originP.x))*180/PI; angleRotZ = atan2((destP.y-originP.y),(destP.x-originP.x))*180/PI; xRot.makeRotate(angleRotX, ofVec3f(1,0,0)); yRot.makeRotate(angleRotY, ofVec3f(0,1,0)); zRot.makeRotate(angleRotZ, ofVec3f(0,0,1)); curRot *= xRot*yRot*zRot; //In Draw: ofPushMatrix(); ofTranslate((originP.x+destP.x)/2,(originP.y+destP.y)/2,(originP.z+destP.z)/2); ofVec3f axis; // to move the newly created line to fit between the points. There are components of my other transformations happening to my line that require that it is first created level with the x axis. float angle; curRot.getRotate(angle, axis); ofRotate(angle, axis.x, axis.y, axis.z); transformGL(); this->getMesh().draw(); restoreTransformGL(); ofPopMatrix();
This is getting me close, at least between A->B, and B->C. But problems come up with C->B, the angle is off, seemingly flipped around x. Finally, C->A, or A->C is staying horizontal…
Does anyone have any advice for handling this sort of application of quaternions? Below is a full pastebin of the project if you are curious:
Thank you! This project has been a great learning experience for me.