# Camera Movement Calculations

I am working on a Swing app and need help with calculations for camera movement.

Below I have my code for moving forward and backward. What I am having issue with is moving left and right with the arrow keys. What I would like is for the camera to move on a plane that intercepts 90 degrees its location → direction line. How I was thinking I would accomplish this is similar to the forward and backward movement. i just need to rotate direction 90 degrees. Then move along the location → rotated direction line.

Something else that comes up with that is which axis to rotate 90 degrees on. I would expect to move with the current rotation of the camera.

if this makes sense can someone help me on how I would calculate the new camera position?

Also, where is the code the SimpleApplication is using for the arrow and w,s,a,d keys? That may help if I could find that logic.

For Up and Down arrow, which would be forward and backwards. I was able to use the following.

Forward:

Vector3f location = getCamera().getLocation();

Vector3f direction = getCamera().getDirection();

getCamera().setLocation(result);

Backward:

Vector3f location = getCamera().getLocation();

Vector3f direction = getCamera().getDirection();

Vector3f result = location.subtract(direction);

getCamera().setLocation(result);

Use direction vectors, thinking in directions is usually much easier for the brain and you do not run into issues like gimbal lock and euler angle translation. You can “rotate” vectors easily using quaternions:

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

the code for the WASD controls is found in the FlyByCamera class, it should help you a lot.

I was able to get what I want with the code from FlyByCamera

Vector3f vel = new Vector3f();

Vector3f pos = cam.getLocation().clone();

getCamera().getLeft(vel);

vel.multLocal(10);

// if (motionAllowed != null)

// motionAllowed.checkMotionAllowed(pos, vel);

// else

getCamera().setLocation(pos);

I looked at the Math for Dummies slide show and made an attempt to use Quaternions. I think I understand the basic concept of what that object represented, which was an axis and the rotation around that axis.

So, I tried to rotate half pi around the direction of the camera. Thinking the direction would be my axis. But, I think the axis would actually be on that when from top to bottom of the camera, then i would rotate from the direction 90 left or right.

I may need some more experience with examples of using Quaternions before I can visualize exactly what I should be doing with them.