# Rotate cam position

Hey everybody,

I’ve got a simple question (hope so) but i just can’t figure it out…

I want to rotate the cam around location x150, y150 & z150
Because of my class “linear algebra” I want to do it by updating a vector with sinus and cosinus.
I used this piece of code with an airplane which had to make corners and it worked perfectly.

But for some reason I can’t get it to work with the cam.

Some ideas?

[java]Vector3f newPos = new Vector3f(1,0,1);

``````    // change coörds according to new angle
newPos = new Vector3f(
newPos.x * cos + newPos.z * -sin,
newPos.y,
newPos.x * sin + newPos.z * cos
);

cam.lookAt(new Vector3f(150,150,150), cam.getLocation());[/java]``````

Perhaps meditate on what these parameters mean:

To me it looks like you are just passing random stuff… I can’t even close to make the second parameter into an up vector and I don’t know enough about your coordinate system to know if the first is sensible at all.

Let me explain how the airplane works:

[java]
public pattern()
{

``````    airPlane = new AirPlane(startingPosition); // I create my airPlane (its a custom shape) and set it to the default position

// this way i make a 90 degree rotation
if(i &lt;= 180)
corner(0.5f,0.5f);

airPlane.addTranslation(newPos); // i add the new position to the current position of the plane
``````

}

private void corner(float rotX, float rotZ)
{
Vector3f newPos = new Vector3f(rotX,0,rotZ); // axis of rotation

``````    // change coörds according to new angle
newPos = new Vector3f(
newPos.x * cos + newPos.z * -sin,
newPos.y,
newPos.x * sin + newPos.z * cos
);
``````

}

[/java]

Well, I will say it clearer, this line is definitely wrong:
cam.lookAt(new Vector3f(150,150,150), cam.getLocation());

you were right, I’m sorry

I was looking for a problem in the rotation but in fact, the rotation was perfect, only the lookAt was wrong…

[java]cam.lookAt(cube.getCenter(), new Vector3f(0,1,0));[/java]

Thnx a lot!