   Slerping from 2x Vertex3
  Hey,A friend of mine recently mentioned about slerping when using rotations to get a smooth rotation. Now one use he came up with was if i had 2 entities in a scene, lets pretend they are people. Then you wanted PersonA to look at PersonB you would need to rotate PersonA towards PersonB. Although all you will have from each person is their 3D position, which would be a vertex/vector or whatever you want to call it.One thing that puzzles me is how to turn my 3D points into quaternions to use in the slerp. Im assuming it isnt as easy as normalising and passing over the X/Y/Z to a new Quaternion and using it?Am i right in thinking that i would need to first work out the 2 angles on x/y then possibly convert to a matrix or something as a middle ground then from a matrix to a quaternion, but to be honest i dont know that much about this sort of thing, so i was hoping you boffins would be able to help fill me in on the knowledge gaps i have.Also on a side note im still trying to fully understand quaternions... am i right in saying that quaternions represent rotations rather than positions? i mean Vertex2/3 represent a direction or point in 3d space, however the impression i get is that a Quaternion is primarily to store rotation information and is more similar to a matrix than a vector.Anyway, any advice you can give on the main part of the topic or enrich my quaternion knowledge would be great... ive tried looking at lots of articles but everyone seems to use them differently... :([Edited by - Grofit on April 28, 2009 12:43:21 PM]
Quote:Original post by GrofitHey,A friend of mine recently mentioned about slerping when using rotations to get a smooth rotation. Now one use he came up with was if i had 2 entities in a scene, lets pretend they are people. Then you wanted PersonA to look at PersonB you would need to rotate PersonA towards PersonB. Although all you will have from each person is their 3D position, which would be a vertex/vector or whatever you want to call it.One thing that puzzles me is how to turn my 3D points into quaternions to use in the slerp. Im assuming it isnt as easy as normalising and passing over the X/Y/Z to a new Quaternion and using it?Am i right in thinking that i would need to first work out the 2 angles on x/y then possibly convert to a matrix or something as a middle ground then from a matrix to a quaternion, but to be honest i dont know that much about this sort of thing, so i was hoping you boffins would be able to help fill me in on the knowledge gaps i have.Also on a side note im still trying to fully understand quaternions... am i right in saying that quaternions represent rotations rather than positions? i mean Vertex2/3 represent a direction or point in 3d space, however the impression i get is that a Quaternion is primarily to store rotation information and is more similar to a matrix than a vector.Anyway, any advice you can give on the main part of the topic or enrich my quaternion knowledge would be great... ive tried looking at lots of articles but everyone seems to use them differently... :(Regarding your question about what quaternions are used for, yes, in this context they're most often used to represent orientations and rotations.A piece of advice I often give is to avoid using quaternions until you understand how to work with and manipulate rotations in matrix form. Functionally, there's nothing you can do with a quaternion that you can't do with a matrix (at least as far as rotations go), and for various reasons, matrices can be a little more intuitive to work with than quaternions (especially if you're new to 3-d math). That's just my opinion though - YMMV.As for your problem, I gather you're asking how to build a rotation matrix or quaternion that, given two positions and a world 'up' vector, will orient an object located at the first position towards the object located at the second position.In the 'fixed up' case, the problem can be reduced to finding the angle associated with a vector in 2-d. The code might look something like this (the code assumes that +z is up):float AbsoluteAngleToTarget(vector3 position, vector3 target) {    vector3 diff = target - position;    return atan2(diff.y, diff.x)}You would then use standard methods to build a matrix or quaternion representing a rotation about the z axis by the computed angle.   ;  Cheers, i thought it would be a case of building the angles then working from there...   ;  One other thing that may sound trivial to you guys but has me thinking...Would it be best off in the above example to store the direction the entities are facing as Quaternions or store them as Vector3s and just convert them to quaternions each time...The thing that puzzles me is that if im using Quaternions each time it makes sense to keep them as quaternions, but how do i rotate the quaternion? im sure its simple but quick searching yielded nothing worthwhile...As they will not always be looking towards entityB so if they want to look to the left or upwards im not sure how to do a rotation on the quaternion... or is it just like rotating a standard 3d vector? Everything i read just explains about how to create a quaternion from your RollPitchYaw or AxisAngles, so the Quaternion is the end point... never the starting point... if that makes sense...It sounds like it should be simple, and maybe it is and i will kick myself once someone posts...[Edited by - Grofit on April 29, 2009 3:54:39 PM];  If it helps anyone else, i think ive answered my own question...When rotating a quaternion you would need to create a new quaternion with the new rotation then do the special Quaternion multiply between the new and the old, which gives you the new quaternion with the total rotations...   