How do I get a Quaternion or Matrix3f from Direction given in Vector?

Hi!

I got these bullets that I shoot. They are geometries, tho collision is done through ray (Finaly :slight_smile:

Now the problem is that I need to rotate the bullet so that its pointing to the way I shoot.



Right now the bullets goes from the camera towards the target and rotation is taken from

the camera.getRotation()

But I want them to go from the gun pipe to the target.



So I can give you:

direction vector

start and goal vector

and I need a quaternion or matrix3f that gives the rotation nessecary.



I tried myself calculate it but it did not go too well. I have not gone through matrixes

or quaternions in school yet…

So care to help me out ? :slight_smile:

Use Quaternion.lookAt for that. You also need an up-vector as one vector cannot give enough info for a rotation.

https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:math_for_dummies

i havent done something similar to my code, but i guess :



[java]bullet.lookAt(bulletPosition.add(bulletForward), bulletUpward); //or replace bulletUpward with Vector3f.Unit_Y[/java]