I have a great 3d solar system that i made and im wanting to be able to move around my 3d scene. I dont have any good way of doing this except changing the x,y,z pos when the user hits the arrow keys (your always looking at the same direction)
it would be nice to implement a fps type of camera to where the mouse pointer is where you want to look at.
this is the class im using with the call to gluLookAt, the eye i am using is global so i can modify it wherever i want in code. I can also get the x,y coords of the mouse position. I just dont know what to do with these coords.
any light on this subject would be very much appreciated, or some links to some good tutorials because i haven't found any.
and on another matter, how come i cant rotate my whole scene when i set the matrix mode to projection. it just rotates where the eye is.
here is my drawing function.
void DrawSun()
{
GLUquadricObj* q = gluNewQuadric();
glColor3f(0.98f, 0.91f, 0.17f);
glRotatef(threeDrot[0], 0, 1, 0);
gluSphere(q, 2.0, 50, 50);
gluDeleteQuadric(q);
}
void DrawMercury()
{
GLUquadricObj* q = gluNewQuadric();
glPushMatrix();
glColor3f(0.5, 0.5, 0.5);
glRotatef(threeDrot[1], 0, 1, 0);
glTranslatef(3.5, 0, 0);
glRotatef(planet_spin[0], 0, 1, 0);
glRotatef(-90, 1, 0, 0); //turn planets right side up
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture[0]);
q = gluNewQuadric();
gluQuadricTexture(q, GL_TRUE);
gluSphere(q, 0.2, 50, 50);
glDisable(GL_TEXTURE_2D);
glPopMatrix();
gluDeleteQuadric(q);
}
void DrawVenus()
{
GLUquadricObj* q = gluNewQuadric();
glPushMatrix();
glColor3f(1, 0.5, 0);
glRotatef(threeDrot[2], 0, 1, 0);
glTranslatef(5.0, 0, 0);
glRotatef(planet_spin[1], 0, 1, 0);
glRotatef(-90, 1, 0, 0); //turn planets right side up
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture[1]);
q = gluNewQuadric();
gluQuadricTexture(q, GL_TRUE);
gluSphere(q, 0.35, 50, 50);
glDisable(GL_TEXTURE_2D);
glPopMatrix();
gluDeleteQuadric(q);
}
void DrawEarth()
{
GLUquadricObj* q = gluNewQuadric();
glPushMatrix();
glColor3f(0.25f, 0.5f, 0.75f);
glRotatef(threeDrot[3], 0, 1, 0);
glTranslatef(7.0f, 0, 0);
glRotatef(planet_spin[2], 0, 1, 0);
glRotatef(-90, 1, 0, 0); //turn planets right side up
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture[2]);
q = gluNewQuadric();
gluQuadricTexture(q, GL_TRUE);
gluSphere(q, 0.4, 50, 50);
glDisable(GL_TEXTURE_2D);
glPopMatrix();
gluDeleteQuadric(q);
}
void DrawEarthMoon()
{
GLUquadricObj* q = gluNewQuadric();
glPushMatrix();
glColor3f(0.25f, 0.25f, 0.25f);
glRotatef(threeDrot[3], 0.0f, 1.0f, 0.0f);
glTranslatef(7.0f, 0, 0);
glRotatef(threeDrot[4], 0.2f, 1.0f, 0.0f);
glTranslatef(1.0f, 0, 0);
glRotatef(planet_spin[3], 0, 1, 0);
glRotatef(-90, 1, 0, 0); //turn planets right side up
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture[3]);
q = gluNewQuadric();
gluQuadricTexture(q, GL_TRUE);
gluSphere(q, 0.2f, 50, 50);
glDisable(GL_TEXTURE_2D);
glPopMatrix();
gluDeleteQuadric(q);
}
void DrawMars()
{
GLUquadricObj* q = gluNewQuadric();
glPushMatrix();
glColor3f(1.0f, 0.2f, 0.0f);
glRotatef(threeDrot[5], 0, 1, 0);
glTranslatef(9.0, 0, 0);
glRotatef(planet_spin[4], 0, 1, 0);
glRotatef(-90, 1, 0, 0); //turn planets right side up
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture[4]);
q = gluNewQuadric();
gluQuadricTexture(q, GL_TRUE);
gluSphere(q, 0.35, 50, 50);
glDisable(GL_TEXTURE_2D);
glPopMatrix();
gluDeleteQuadric(q);
}
void DrawJupiter()
{
GLUquadricObj* q = gluNewQuadric();
glPushMatrix();
glColor3f(1.0f, 0.5f, 0.5f);
glRotatef(threeDrot[6], 0, 1, 0);
glTranslatef(11.5, 0, 0);
glRotatef(planet_spin[5], 0, 1, 0);
glRotatef(-90, 1, 0, 0); //turn planets right side up
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture[5]);
q = gluNewQuadric();
gluQuadricTexture(q, GL_TRUE);
gluSphere(q, 0.75, 50, 50);
glDisable(GL_TEXTURE_2D);
glPopMatrix();
gluDeleteQuadric(q);
}
void DrawSaturn()
{
GLUquadricObj* q = gluNewQuadric();
glPushMatrix();
glColor3f(0.75f, 0.65f, 0.65f);
glRotatef(threeDrot[7], 0, 1, 0);
glTranslatef(16, 0, 0);
glRotatef(planet_spin[6], 0, 1, 0);
glRotatef(-90, 1, 0, 0); //turn planets right side up
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture[6]);
q = gluNewQuadric();
gluQuadricTexture(q, GL_TRUE);
gluSphere(q, 0.65, 50, 50);
glDisable(GL_TEXTURE_2D);
glPopMatrix();
gluDeleteQuadric(q);
}
void DrawUranus()
{
GLUquadricObj* q = gluNewQuadric();
glPushMatrix();
glColor3f(0.15f, 0.0f, 0.85f);
glRotatef(threeDrot[8], 0, 1, 0);
glTranslatef(21, 0, 0);
glRotatef(planet_spin[7], 0, 1, 0);
glRotatef(-90, 1, 0, 0); //turn planets right side up
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture[7]);
q = gluNewQuadric();
gluQuadricTexture(q, GL_TRUE);
gluSphere(q, 0.65, 50, 50);
glDisable(GL_TEXTURE_2D);
glPopMatrix();
gluDeleteQuadric(q);
}
void DrawNeptune()
{
GLUquadricObj* q = gluNewQuadric();
glPushMatrix();
glColor3f(0.15f, 0.0f, 1.0f);
glRotatef(threeDrot[9], 0, 1, 0);
glTranslatef(24, 0, 0);
glRotatef(planet_spin[8], 0, 1, 0);
glRotatef(-90, 1, 0, 0); //turn planets right side up
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture[8]);
q = gluNewQuadric();
gluQuadricTexture(q, GL_TRUE);
gluSphere(q, 0.60, 50, 50);
glDisable(GL_TEXTURE_2D);
glPopMatrix();
gluDeleteQuadric(q);
}
void DrawPluto()
{
GLUquadricObj* q = gluNewQuadric();
glPushMatrix();
glColor3f(0.15f, 0.15f, 0.15f);
glRotatef(threeDrot[10], 0, 1, 0);
glTranslatef(29, 0, 0);
glRotatef(planet_spin[9], 0, 1, 0);
glRotatef(-90, 1, 0, 0); //turn planets right side up
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture[9]);
q = gluNewQuadric();
gluQuadricTexture(q, GL_TRUE);
gluSphere(q, 0.15, 50, 50);
glDisable(GL_TEXTURE_2D);
glPopMatrix();
gluDeleteQuadric(q);
}
void DrawOrbits()
{
glPushMatrix();
glDisable(GL_LIGHT0);
glDisable(GL_LIGHT1);
DrawOrbit(3.5, 1);
DrawOrbit(5.0, 1);
DrawOrbit(7.0, 1);
DrawOrbit(9.0, 1);
DrawOrbit(11.5, 1);
DrawOrbit(16, 1);
DrawOrbit(21, 1);
DrawOrbit(24, 1);
DrawOrbit(29, 1);
glPopMatrix();
}
void ThreeDSolarSystem(VirtualEye eye, bool orbits)
{
GLfloat specref[] = { 1.0f, 1.0f, 1.0f, 1.0f };
GLfloat lightPos[] = { 0.0f, 0.0f, 0.0f, 1.0f };
GLfloat emissionSun[] = { 0.9f, 0.9f, 0.0f, 0.0f};
GLfloat nullv[] = { 0.0f, 0.0f, 0.0f, 1.0f};
glEnable(GL_LIGHT0);
gluLookAt(eye.eyePos[0], eye.eyePos[1], eye.eyePos[2],
eye.lookAt[0], eye.lookAt[1], eye.lookAt[2],
eye.up[0], eye.up[1], eye.up[2]);
glPushMatrix();
//set sun material and draw sun
glMaterialfv(GL_FRONT, GL_SPECULAR, specref);
glMateriali(GL_FRONT, GL_SHININESS, 3);
glMaterialfv(GL_FRONT, GL_EMISSION, emissionSun); //make sun glow
glLightfv(GL_LIGHT1, GL_POSITION, lightPos); //move light 1 under sun
DrawSun();
//save lighting and set other planets material
glPushAttrib(GL_LIGHTING_BIT);
glDisable(GL_LIGHT0);
glEnable(GL_LIGHT1); //turn on the sun
glMaterialfv(GL_FRONT, GL_SPECULAR, nullv);
glMaterialfv(GL_FRONT, GL_EMISSION, nullv);
//draw rest of the planets
DrawMercury();
DrawVenus();
DrawEarth();
DrawEarthMoon();
DrawMars();
DrawJupiter();
DrawSaturn();
DrawUranus();
DrawNeptune();
DrawPluto();
//do orbits or not?
if (orbits)
{
DrawOrbits();
}
}