PDA

View Full Version : flight simulator



incus
09-15-2002, 11:25 AM
hey i am having a problem with my flight simulator. when i move the camera the skybox gets all messed up!
here is the code for the camera movement:
void Camera ::

u,v,n are vectors which represent x,y,z

setModelViewMatrix(void) {
float m[16]; // the matrix that will be loaded.
Vector3 eVec(eye.x, eye.y,eye.z);
m[0] = u.x; m[4] = u.y; m[8] = u.z; m[12] = -eVec.dot(u);
m[1] = v.x; m[5] = v.y; m[9] = v.z; m[13] = -eVec.dot(v);
m[2] = n.x; m[6] = n.y; m[10] = n.z; m[14] = -eVec.dot(n);
m[3] = 0; m[7] = 0; m[11] = 0; m[15] = 1.0;
glMatrixMode(GL_MODELVIEW);
glLoadMatrixf(m);
}

void Camera :: set(Point3 Eye, Point3 look, Vector3 up) {
eye.set(Eye);
n.set(eye.x - look.x, eye.y - look.y, eye.z - look.z);
up.set (0,1,0);
up = up.cross(n);
u.set(up.x,up.y,up.z);
n.normalize(); u.normalize();
Vector3 temp;
temp = n.cross(u);
v.set(temp.x,temp.y,temp.z);
setModelViewMatrix();
}

void Camera :: slide(float delU, float delV, float delN) {
eye.x += delU * u.x + delV * v.x + delN * n.x;
eye.y += delU * u.y + delV * v.y + delN * n.y;
eye.z += delU * u.z + delV * v.z + delN * n.z;
setModelViewMatrix();
}

void Camera :: roll(float angle) {
float cs = cos (3.14159265/180 * angle);
float sn = sin (3.14159265/180 * angle);
Vector3 t = u;
u.set(cs*t.x - sn*v.x, cs*t.y - sn*v.y, cs*t.z - sn*v.x);
v.set(sn*t.x + cs*v.x, sn*t.y + cs*v.y, sn*t.z + cs*v.x);
setModelViewMatrix();
}

void Camera :: pitch(float angle) {
float cs = cos (3.14159265/180 * angle);
float sn = sin (3.14159265/180 * angle);
Vector3 t = n;
n.set(cs*t.x - sn*v.x, cs*t.y - sn*v.y, cs*t.z - sn*v.x);
v.set(sn*t.x + cs*v.x, sn*t.y + cs*v.y, sn*t.z + cs*v.x);
setModelViewMatrix();
}

and here is the skybox code:


glDisable(GL_TEXTURE_2D);
glEnable(GL_TEXTURE_2D);

glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glDisable(GL_TEXTURE_GEN_S);
glDisable(GL_TEXTURE_GEN_T);
glPolygonMode(GL_FRONT, GL_FILL);
glDisable(GL_BLEND);
glDisable(GL_ALPHA_TEST);
glDisable(GL_DEPTH_TEST);
glDepthMask(GL_FALSE);
glDisable(GL_LIGHTING);


// Vector3 eVec(theCamera.eye.x,theCamera.eye.y,theCamera.eye .z);

GLdouble mv[16];
glGetDoublev(GL_MODELVIEW_MATRIX, mv);
// mv[12] = -eVec.dot(theCamera.u); mv[13] = -eVec.dot(theCamera.v); mv[14] = -eVec.dot(theCamera.n);
mv[12] = 0; mv[13] = 0; mv[14] = 0;
glPushMatrix();
glLoadMatrixd(mv);


// glMatrixMode(GL_TEXTURE);

glBindTexture(GL_TEXTURE_2D, skyBoxTexture[SKYBOX_FRONT].name);

glBegin(GL_QUADS);

glTexCoord2i(0, 0);
glVertex3f(-10, -10, -10);

glTexCoord2i(1, 0);
glVertex3f(10, -10, -10);

glTexCoord2i(1, 1);
glVertex3f(10, 10, -10);

glTexCoord2i(0, 1);
glVertex3f(-10, 10, -10);

glEnd();


glBindTexture(GL_TEXTURE_2D, skyBoxTexture[SKYBOX_BACK].name);

glBegin(GL_QUADS);

glTexCoord2i(0, 0);
glVertex3f(10, -10, 10);

glTexCoord2i(1, 0);
glVertex3f(-10, -10, 10);

glTexCoord2i(1, 1);
glVertex3f(-10, 10, 10);

glTexCoord2i(0, 1);
glVertex3f(10, 10, 10);

glEnd();


glBindTexture(GL_TEXTURE_2D, skyBoxTexture[SKYBOX_LEFT].name);

glBegin(GL_QUADS);

glTexCoord2i(0, 0);
glVertex3f(10, -10, -10);

glTexCoord2i(1, 0);
glVertex3f(10, -10, 10);

glTexCoord2i(1, 1);
glVertex3f(10, 10, 10);

glTexCoord2i(0, 1);
glVertex3f(10, 10, -10);

glEnd();


glBindTexture(GL_TEXTURE_2D, skyBoxTexture[SKYBOX_RIGHT].name);

glBegin(GL_QUADS);

glTexCoord2i(0, 0);
glVertex3f(-10, -10, 10);

glTexCoord2i(1, 0);
glVertex3f(-10, -10, -10);

glTexCoord2i(1, 1);
glVertex3f(-10, 10, -10);

glTexCoord2i(0, 1);
glVertex3f(-10, 10, 10);

glEnd();


glBindTexture(GL_TEXTURE_2D, skyBoxTexture[SKYBOX_UP].name);

glBegin(GL_QUADS);

glTexCoord2i(0, 0);
glVertex3f(-10, 10, 10);

glTexCoord2i(1, 0);
glVertex3f(-10, 10, -10);

glTexCoord2i(1, 1);
glVertex3f(10, 10, -10);

glTexCoord2i(0, 1);
glVertex3f(10, 10, 10);

glEnd();


glBindTexture(GL_TEXTURE_2D, skyBoxTexture[SKYBOX_DOWN].name);

glBegin(GL_QUADS);

glTexCoord2i(0, 0);
glVertex3f(10, -10, 10);

glTexCoord2i(1, 0);
glVertex3f(10, -10, -10);

glTexCoord2i(1, 1);
glVertex3f(-10, -10, -10);

glTexCoord2i(0, 1);
glVertex3f(-10, -10, 10);

glEnd();


glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
glEnable(GL_CULL_FACE);
glEnable(GL_LIGHTING);

glFlush();

glutSwapBuffers();

glPopMatrix(); // put it back how we found it
}

does anyone see what i am doing wrong and why. i think the problem is the fact that the camera is moving and the box is not but i tries to move the box with it as well and it did not. any suggestions are appreciated.
Incus

[This message has been edited by incus (edited 09-15-2002).]