I searched and found a few similar questions, but for the sake of learning, I want to find out why this code doesn't work. I've been staring at it for a total of like 4 hours over the past 2 days and can't figure out why it isn't working. This is a code segment from my update() method which detects when the right arrow button is pressed (and held)
if (KeyBindingManager.getKeyBindingManager().isValidCommand("rightarrow",true))
{
//get the direction and location of the camera
Vector3f dir=cam.getDirection();
Vector3f loc=cam.getLocation();
//get the x and z coordinates of dir in relation to loc.
float xdif=dir.x-loc.x;
float zdif=dir.z-loc.z;
//findAngleXY() is a custom method and returns the radian value of a point (X,Y) when
//a circle with origin (0,0) is enlarged onto it.
//This method has been tested with known values and works properly.
//For example, when entering (1,1), it will return pi/4.
float degree=util.findAngleXY(xdif,zdif);
float radius=loc.distance(dir);
//Set dir.x to the x value of "degree", slightly rotated to the right, then added to the real origin.
dir.x=loc.x+(radius*(float)Math.cos(degree-.1));
//same for dir.z
dir.z=loc.z+(radius*(float)Math.sin(degree-.1));
//set camera direction to new coords.
cam.setDirection(dir);}
When I run that and hold right arrow, it seems "dir" is actually moving in a circle, but not around the camera. The screen just rotates left and right slightly.
One additional note: I have methods in update() that use the up and down arrows to move the camera forward and backward, and those work properly (except the camera is facing in the wrong direction). It's kind of hard to explain without seeing... When I press up, for example (without trying to rotate the camera first), the camera moves forward. If I try to rotate the camera 180 degrees, first, the camera doesn't rotate, then if I press up again, the camera moves backwards. This means dir is probably in the right place in relation to the camera, but camera is not looking directly at it. Maybe a problem in setDirection? Do I have to update anything on either cam or dir?