Trying to simplify my original problems, and I think I have it condensed as well as I can. Right now, I have two target points. Between those points, I build a line that matches the length between it’s “target” points. I then am trying to use quaternions to rotate that line appropriately, and translate it into place, effectively placing it perfectly between the two target points.
Currently, I can’t seem to get rotation around the x axis to work properly. There are other placements of those target points that work fine, when the line remains flush with the x axis, but any z-depth and it’s stuck.
I think you need to rotate to the normal/direction between your 2 points. The 3D/orientation example has a good example of this. This works for your code…
ofVec3f direction = (destP - originP).getNormalized();
ofVec3f axis(1, 0, 0);
ofRotate(rotationAmount, rotationAngle.x, rotationAngle.y, rotationAngle.z);
This is really great and simplified. I’m trying to break down what you’ve provided, I still don’t have a great understanding of the role of normalization and it’s relationship to direction. Also, how do you get by without calculating the angle between the axis?
Thanks a lot though, this really helps me, I’ve been racking my brain over this for a while.
I think I can speak to this a bit.
destP - originP
gives you a vector3 with direction and magnitude. For example, if destP = (3, 5, 2) and originP = (1, 1, 1), then you’ll get a vector3 that is (2, 4, 1), so
magnitude = sqrt(22 + 44 + 1*1) = 4.58258.
And if you were to draw a line between the two points, you would obviously see the direction.
Normalization divides the vector by its own magnitude so you get just the direction. It divides each value in the vector by the magnitude so that the values are mapped between 0 and 1 (in this case the normalized values would be 0.436436, 0.872872, 0.218218). That way, it corresponds much better to the axis, which is also normalized (your axis above is (1, 0, 0) for example).
Since the direction is normalized now, he’s using
to directly compare it to ‘axis’ and get the difference between the two, and then
to calculate the angle.
Hope that clears some stuff up!
I appreciate the explanation, much cleaner way of doing things than I was before. Vectors still go over my head, this helps. Thanks!