View Full Version : Help With Camera
08-09-2011, 11:37 AM
Hey evebody, hi to all..
Need some help with "looking"...dont find in any tutorials...i want to understand this point, cause i want to program games.. :)
Lets supose that i have a character and i want a camera following him..I use gluLookAt() to point the camera behind it..
W - walk him forward...z+= 0.1f;
S - walk him backward...z-=0.1f;
now i want the A and D keys to turn left and right (angle)...
so lets supose that i turn 90º to left..now i want to press W to walk forward...but it walk for other side... weird..
maybe because this...
translate3f(x, y, z);
help me how to fix that, or some tutorial explained well the camera concept...
I think gluLookAt could be the best way...or am i wrong??
08-09-2011, 12:48 PM
I don't know a lot about this, but I'll see if I can help you a little.
I don't have your code, but let me see if I understand you correctly. At the moment you can walk straight forwards and backwards fine. But if you rotate 90 degrees to the left and press W (forward), the camera continues to move like it did before you rotated the camera. AKA, you're now strafing to the right?
08-10-2011, 05:07 AM
The wall from the right come to me..I know why this happen...its because when i press W its sums Z += 0.1f...So the camera will go to Z axis. Maybe i need to calculate with sen and con but I never used these functions..and dont know where to put..Can you help??
08-10-2011, 05:52 AM
Have you looked at tutorial sites like HeNe. They explain the basics of cameras and movement.
HeNe Camera Tutorial (http://nehe.gamedev.net/article/camera_class_tutorial/18010/)
08-10-2011, 09:52 AM
I don't know how NeHe goes about it, but it would also be helpful to understand Polar Coordinates (http://www.youtube.com/watch?v=jexMSlSDubM).
Essentially you have all the information you need for polar coordinates right now. You have an angle, and r can just be 1 (this will make sense if you watch that video).
The big idea is that ultimately you need a "line of sight" vector to orient your camera correctly with gluLookAt, because part of the set of parameters is the definition of a 3D point you're looking at. If you can obtain a vector defining the direction you're looking, you can add the components of that vector to your camera's current x, y, z location to get the point to look at.
Then, for motion, instead of updating your camera's position just straight bye the Z axis, or any other axis, update it with the line of sight component for each axis. This way you're moving in the direction you're currently facing, not just flat along an axis.
I hope this combined with the links you have makes it clear! If not, ask more questions. :)
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.