PDA

View Full Version : Getting One Vector Based On An Angle...



Sephiroth
12-03-2002, 12:16 PM
OK, I need to figure out what I've done to mess up my viewing system. I use gluLookAt() to move a camera in object space, but when I built my new box I rebuilt my app from the ground up. Everything else works, but I have not done my viewing correctly. Here's the current source.



//Structure

typedef struct tagCAMERA
{
float X, Y, Z;
float LX, LY, LZ;
short int Heading, LookUp;
} CAMERA;

//In the engine...
CAMERA Base;
...
void DrawScreen()
{
Base.LX = Base.X + cos(Base.Heading * (pi / 180)) + 64;
Base.LY = Base.Y + sin(Base.LookUp * (pi / 180)) + 64;
Base.LZ = Base.Z + sin(Base.Heading * (pi / 180)) + 64;

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
gluLookAt(Base.X, Base.Y, Base.Z, Base.LX, Base.LY, Base.LZ, 0.0, 1.0, 0.0);
}

What's wrong with this? Also, should I use glNormal3f() as well? If so, what exactly does it do? Heading is which way in the world the player is looking, ranging from 0 to 359. LookUp ranges from -90 to +90. The way i thought I had it setup was to look at a vector about 64 units away, but when i turn left or right, the view just rotates in a tiny circle, very slowly. Thanks for the help.

Sephiroth
12-03-2002, 08:16 PM
Fixed it. Should have been * 1.5, not + 64, which made it look right around the "64/64/64" vector all the time. I don't like multiplying by 1.5 though, so i am working on a formula to reduce that value down to no more than 128 in front of the camera so I can use more mapping space.