VeliV's picture

Quaternion.LookAt or converting a matrix in to a Quaternion?

Hi ya.

I has a new problem ;) Here is the situation.

I need to make a cameraview based on a position and normal. The position is pretty easy to implement, but rotation isn't. I have tried making a matrix out of the normal vector and the multiply projection with that, but that changes position of the camera.

In examples found on these forums, people handled the situation by creating a ratation matrix out of quaternion. I' thought I'd try that but I am at loos about how to convert the normal into a quaternion.

Any suggestions?


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
nythrix's picture

A matrix to quaternion solution is here. I'm not sure that's enough to get your camera going, though.
Proper camera handling is an all time favourite question but the answer rarely fits into a single topic.
Try running through some of these.

zahirtezcan's picture

I had implemented something like this before, "quaternion from a vector". Actually, this declaration hides an assumption and that is "you have a default vector" (your case a default normal)

For example let's say (1)we are talking about terrain and tilt/rotate camera according to terrain normal. (2) I usually make my terrain grid on X-Y plane and my up vector is unit Z vector. (3) Therefore each normal on the terrain gives me a rotation from default up vector (which is Z) to the normal. Then, I can find the angle between Z vector and normal with a dot product, which is Z component of the normal(assuming normalized, the angle can be found by acos function but instead of that we use sine and cosine for quaternion and sine = sqrt(1 - cos^2)) . And also, I can find the rotation vector by cross product of Z and normal, which is straightforward too.

To conclude, you need a default or initial normal vector imho