[Solved] Rotating a vector3f around Y

Hello everyone,
I can’t seem to figure this one out. I want to have my player (wich is using bullet and thus has a vector3f for a view direction) to be rotated around Y with two keys.
Before this, it worked via the camera:
viewDirection.set(camera.getDirection().x, 0, camera.getDirection().z);
Now I need to have a rot value that I can increase or decrease with two keys:

{
    rot += 90 * FastMath.DEG_TO_RAD * tpf;
}
else if(key.equals("TurnRight") && isPressed)
{
    rot -= 90 * FastMath.DEG_TO_RAD * tpf;
}```
This basically says that I want the rotation speed to be 90 degrees per second. I now need to convert this into a view direction vector.
This is what I have until now, but it's not working:
```float[] angles = new float[3];
            System.out.println(rot);
            Quaternion q = new Quaternion();
//            q.lookAt(new Vector3f(0, rot, 0), Vector3f.UNIT_Y);
            q.fromAngleAxis(rot, Vector3f.UNIT_Y);
            angles = q.toAngles(angles);
            System.out.println(Arrays.toString(angles));
            viewDirection.set(angles[0], angles[1], angles[2]);
            System.out.println(viewDirection);```
Any ideas?
Quaternion q = new Quaternion();
q.fromAngleAxis(rot, Vector3f.UNIT_Y);
q.mult(Vector3f.UNIT_X, viewDirection);
System.out.println(viewDirection);

If your original viewing direction is UNIT_X when rot = 0, the above should work fine. Otherwise, replace the UNIT_X with the direction at rot = 0.

1 Like

And this might be helpful too:
https://jmonkeyengine.github.io/wiki/tutorials/math/assets/fallback/index.html

1 Like

@The_Leo That works, thanks a lot!

1 Like