From Vector3f to Quaternion

Hello!



I'm trying to get some of my code cleaner… It's now time to face Quaternions :slight_smile:



This is what i'm attempting to do:

  1. I have a normalized vector, say 0.5f, 0, 0.5f which identifies the direction a Node is facing;
  2. I'd love to have a quaternion out of it;



    My attempts are not that good (I mean, it's just plain wrong). So, something tells me there's an easy solution to this problem :slight_smile:



    Thanks for your time…

I think you need at least one more Vector.

A single vector can indicate a direction but, if you imagine, your node can roll without changing that vector - therefore the vector alone cannot define a quaternion. If you have two vectors, then you can calculate the third (product) from them and use the .fromAxes method to get a quaternion.



You should bear the following points in mind when considering the above paragraph.

  • I am unnecessarily verbose at the best of times.
  • I am really tired.
  • I am quite drunk.
  • I am not very good at math.

Quaternion has a lookAt method, but you need to specify an up vector.

Momoko_Fan said:

Quaternion has a lookAt method, but you need to specify an up vector.


Ah nice! Exactly what I needed. Thanks ^_^

Alric said:

bear the following points in mind


Hmm, in my case, I'd also add:
- Read the javadoc for the methods.
I couldn't get it why lookAt (1,0,0), (0,1,0) made me look at (0,0,1). Makes sense when reading javadoc...

It computes the rotation to transform the z-axis to point into 'direction'