I’m trying to implement a camera that uses a quaternion to store the orientation.
When I init the camera I calculate the view vector subtracting the interest point from the position point
view = position - interest
then I create my quaternion as
q = view.x, view.y, view.z 0.0
I found this way of setting the quaternion on a website (don’t remember which one), and I’m trying to interpret its meaning.
I think it is an axis-angle representation, but if cos(angle/2) = 0 then angle = PI and this doesn’t really make sense to me.
If you have any idea about this way to set the quaternion, please tell me.
The strange thing is that it actually quite works.
So basically I have my quaternion, every time I change position or interest points I reset the quaternion and everything works fine.
The problem is that I need to retrieve a set of axis to setup things for the camera, I usually need the forward vector (for example to perform a Dolly-like motion, or orbiting), the right and the up vector(to pan and setup opengl camera).
I thought I could get them simply applying the rotation stored in the quaternion to the standard axes for the camera (that is sup = (0,1,0) sright = (1,0,0) and sforward = (0,0,-1)).
So to calculate my set of vectors I do
v’ = Q * v * Q^
where Q^ is the conjugate of Q.
The calculation for the right and up vector seems to work, but if I apply the same to the forward vector I obtain something different from what I started with.
QsforwardQ^ != position - interest
What I really need is to setup a quaternion given a view vector, and then use it to transform the set of starting axis I define.
That is, I need to find a way to setup the quaternion, given a view vector ( Q( viewVector ) )
that satisfy this equation:
QsforwardQ^ == viewVector
I need this in order to be able to setup the camera given a quaternion and the position, because in this way I can just calculate the forward vector and find the interest point at a certain distance.
(I always need an interest point because I want to be able to orbit the camera around it).
I know my knowledge of quaternion is not sufficient, but I’m trying really hard to make things work.
Every help is really appreciated.