Original Post
im trying to learn OpenGL and 3dimensional theory. and also trying to write my own code for this stuff as much as possible. now i have a function that will rotate the camera so that you can look up and down, but i have a problem with turning left and right rotation. currently my code is this for the turn.
float DEG2RAD(float x) {
return (x*(PI/180));
}
typedef struct {
double x;
double y;
double z;
} vector;
class camera {
public:
camera();
void move(float speed);
void stafe(int speed);
void setpos(int x, int y, int z);
void setlook(int x, int y, int z);
void look(float degree);
void turn(float degree);
void display();
int setmaxup(int degree);
int maxup();
float lookangle;
float clookangle;
float turnangle;
float cturnangle;
private:
vector position;
vector lookat;
int maxlook;
};
void camera::turn(float degree) {
cturnangle+=degree;
if(cturnangle >= 360.0f) {
cturnangle-=360.0f;
}
if(cturnangle <= 360.0f) {
cturnangle+=360.0f;
}
float xx=cos(DEG2RAD(cturnangle));
float zz=sin(DEG2RAD(cturnangle));
lookat.x=(position.x + xx);
lookat.z=(position.z + zz);
};
can anyone tell me what is wrong with this function. If i rotate it at ANY degree anything that was on the screen is lost, so what can I do about that.
the source code included has other functions, i just put the relavent information, or what i thought was relavent.
Higher Forces
[edited by - hogosha on September 2, 2003 10:23:59 PM]