Get Quaternion from Vector

well I kinda search for something like this, but in the other direction.



   public static Vector3f GetForward(Quaternion quat){
      Matrix3f matrix = quat.toRotationMatrix();
      Vector3f front = matrix.mult(Vector3f.UNIT_Y);
      return front;
   }



Since a Vector can not contain any data for the roll, it would be nice if i can just give a float as a second parameter.
But since I kinda suck at math, not to mention quaternions, any help would be nice.

Well what I meant i need the othe way round.



I have a vector and a roll float and want to make a quaternion out of it.

oh ok. I'm a bit slow sometimes   :expressionless:

There's a Quaternion method, fromAngleAxis.

Something like this should do it:



Quaternion q = new Quaternion();
q.fromAngleAxis(rollFloat, forwardVec);
return q;

You can use quat.getRotationColumn() to get the vector for a direction.

Not sure what you mean about the roll? Roll would have no effect on your heading.

Hm that does not seem to work :frowning:





com.jme.math.Vector3f [X=0.23848784, Y=-0.43953568, Z=0.86598617]

com.jme.math.Quaternion: [x=0.0 y=-0.0 z=0.0 w=1.0]



com.jme.math.Quaternion: [x=0.0 y=0.0 z=0.0 w=1.0]

com.jme.math.Vector3f [X=0.26400882, Y=0.19657567, Z=0.9442761]



This is the only code between the two System.out.println()



aimbox.setLocalRotation(new Quaternion().fromAngleAxis(0,InputGrabber.GetAimVector()));

System.out.println(aimbox.getLocalRotation());



I dunno why but when i set roll to another value, the Quaternion changes (still not in the way I want it, it's more like it#s center isrotated O.o?)



However how can I then represent an object that is absolutly parallel to the xy plane?

(roll 0 pitch 0 yaw 0)