Quaternion Troubles

Hello! In my game, you can switch freely between the FlyCam and a CameraNode. I would like it so that when you switch from the FlyCam to the CameraNode, the CameraNode is looking in the same direction as the FlyCam. The CameraNode is attached to a player’s node, and I have applied “cameraNode.setControlDir(ControlDirection.SpatialToCamera);” to the CameraNode, which makes it so the Camera follows the player.

The player’s node is being controlled by a BetterCharacterControl, so I can do

[java]
Vector3f currentCamDirection = getCamera().getDirection();
betterCharacterControl.setViewDirection(currentCamDirection);
[/java]

to make the player (and, in turn, the Camera) look in the correct direction, but the problem is that this doesn’t affect at all how far the camera is looking up or down. To do this, I need to rotate the CameraNode itself, not the player, on the x-axis. I want to rotate the CameraNode so that its x-axis rotation (yaw) is the same as was for the FlyCam. I don’t know how to “extract” only the yaw part of the Camera’s rotation quaternion and “replace” the yaw part of the CameraNode’s localRotation. How would I do this?

I hope this makes sense. Please let me know if you do not understand the question and I will try to clarify.

To convert a quaternion to angles…
http://hub.jmonkeyengine.org/javadoc/com/jme3/math/Quaternion.html#toAngles(float[])

Never be afraid to look at the javadoc.

1 Like
@pspeed said: To convert a quaternion to angles... http://hub.jmonkeyengine.org/javadoc/com/jme3/math/Quaternion.html#toAngles(float[])

Never be afraid to look at the javadoc.

Wow! I completely missed that! Thank you so much, I was able to solve the problem using this method :slight_smile: