#### Archived

This topic is now archived and is closed to further replies.

# gluLookAt Camera - something's really wrong here...

This topic is 5503 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I''m working on a camera that uses gluLookAt and vectors (..i think ). I have gotten it to move forward and backward properly, but when i try to rotate it around the y-axis, something really strange happen. When you for instance hit the right-arrow it start turning right but going faster and faster around...and when you then hit the left arrow it keeps on rotating to the right as mutch as you had already rotated before going left...ehh... Ex: Hit right arrow. Camera rotates left for say 90 degrees. Hit left arrow. Camera keeps going right for 90 degrees. Camera is finally going left... Some code:
void CCamera::RotateYaw(float speed)
{
CVector vView;

yawAngle += speed;

vView.x = ((m_vView.x * cos(yawAngle)) + (m_vView.z * sin(yawAngle)));
vView.y = m_vView.y;
vView.z = (-(m_vView.x * sin(yawAngle)) + (m_vView.z * cos(yawAngle)));

m_vView = vView;
}

speed is at the time beeing just a konstant with the value 0.03f and m_vView is the view vector. I call RoteteYaw with either +"value" or -"value" and i set the camera with: gluLookAt( m_vPosition.x, m_vPosition.y, m_vPosition.z, (m_vPosition.x + m_vView.x), (m_vPosition.y + m_vView.y), (m_vPosition.z + m_vView.z), 0, 1, 0); Now, i do suck at math. Perhaps one can''t do it like this i really can''t tell. I''ll be thankful for any help i can get..

##### Share on other sites
stab in the dark: yawangle = speed, as you want to rotate speed to left or right and not change the angle, as youre using the previous view vector and are not starting at zero every time you rotate (which would sound a lot like eulers and be a veeeeeery evil thing *lol*).

##### Share on other sites
What the...it works!
I will be honest and say i have no idea how, but removing the + sign did it! I have to spend some time thinking on why it should be like this...
Thanks Trienco! You saved me from a lot of headaque!

##### Share on other sites
When you were adding speed to yawangle, here''s the effect you were getting (assuming speed = 2 and yawangle = 0 to start with):

Frame 1: yawangle + speed = 2 (you rotate 2 degrees)
Frame 2: yawangle + speed = 4 (you rotate 4 degrees)
Frame 3: yawangle + speed = 6 (you rotate 6 degrees)
...
...
Frame 180: yawangle + speed = 360 (you rotate 360 degrees!).

When you changed direction and add a -speed, the rotation keeps going in the original direction because yawangle is still positive. As yawangle gets smaller, it appears to slow down until it reaches 0 and stops. Then we get on the negative side and it rotates the other way.

By assigning speed to yawangle rather than adding it, you move at a constant rotation each frame:

Frame 1: yawangle = speed (you rotate 2 degrees)
Frame 2: yawangle = speed (you rotate 2 degrees)
Frame 3: yawangle = speed (you rotate 2 degrees)

Then when you change diorections and yawangle = -2, the change is instant.

That''s why it worked.

##### Share on other sites
That seems resonable. I guess i was thinking of "normal" use of cos() and sin() where one have to add to the angle in order to change the rotation...
Thanks Aldacron for explaining this

1. 1
2. 2
3. 3
Rutin
13
4. 4
5. 5

• 20
• 10
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633694
• Total Posts
3013366
×