I have a FPP quaternion Camera
and Plane
with known normal vector
.
I want to find the orientation of this Plane
so I can replace it to the Camera
orientation to put the camera forward vector to a plane's normal vector.
First method I tried, I don't understand
RotationAxis
andRotationAngle
. I built a rotation matrix and applied it to the camera but it didn't behave as I wanted.The second method I tried is with method called "from_one_vector_to_another". I don't understand what the "from" vector is in my example; is it the camera's forward vector?
Here is my pseudo code:
Vector3 vector_from = camera->getForwardVector();
Vector3 vector_to = triangle->faceNormal;
Quat cameraQuaternion = camera->getOrientation();
Quat q = vector_from.getRotationTo(vector_to);//The method `getRotationTo` is from Ogre.
camera->setOrientation(cameraQuaternion * q);
Camera does not change their orientation as I expected; it changes its orientation just a little bit.
EDIT:
Maybe I have something wrong with my code:
//Quat xrot = axisToQuat(Vector3(1, 0, 0), vertical); // disabled for now
Quat yrot = axisToQuat(Vector3(0, 1, 0), horizontal);
rot = rot * yrot;
position += velocity;
Matrix lookAt = Matrix::createLookAt
(
Vector3(position.x, position.y, position.z),
Vector3(position.x, position.y, position.z-1),
Vector3(0,1,0)
);
view = rot.toMatrix() * lookAt;
I am only rotating the quaternion. Should I rotate lookAt Matrix too?