Skip to content

Instantly share code, notes, and snippets.

@Darthfett
Created November 12, 2011 19:46
Show Gist options
  • Save Darthfett/1361010 to your computer and use it in GitHub Desktop.
Save Darthfett/1361010 to your computer and use it in GitHub Desktop.
GLfloat LightPos[] = { 10.0f, 0.0f, 0.0f, 1.0f};
void setupProjectionMatrix() {
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewport(0,0,WindowWidth,WindowHeight);
gluPerspective(FieldOfView, AspectRatio, NearPlane, FarPlane);
glMatrixMode(GL_MODELVIEW);
}
void display() { // GL Display Func
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity(); // We're in MODELVIEW
gluLookAt(0, 0, 10, 0, 0, 0, 0, 1, 0);
glRotatef(-15, 1, 0, 0); // Put Camera Angle up toward the ceiling
glTranslatef(0, -boundBoxMin.y / 2, 0); // Put Camera Position below the ceiling
ceiling->draw(true, true, MaterialType == MATERIAL_TYPE_DESIGN); // Draw (with display lists, draw children, draw with individual materials)
glutSwapBuffers();
}
void computeFrame() { // Ran while idle (at a somewhat constant rate, depends upon frame rate)
ceiling->update();
if (LEFT_Down) {
LightAngle -= 2;
}
if (RIGHT_Down) {
LightAngle += 2;
}
if (UP_Down) {
LightHeight += .2;
}
if (DOWN_Down) {
LightHeight -= .2;
}
LightAngle = MAX2(0, MIN2(360, LightAngle)); // Make light angle in range [0, 360]
LightHeight = MAX2(-10, MIN2(2, LightHeight)); // Make light height in range [-10, 2]
if (LEFT_Down || RIGHT_Down || UP_Down || DOWN_Down) {
//cout << "Angle: " << LightAngle << " Height: " << LightHeight << endl; // This is displaying a properly updating height and angle
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glTranslatef(0, LightHeight, 0);
glRotatef(LightAngle, 0, 1, 0);
glLightfv(GL_LIGHT0, GL_POSITION, LightPos);
setupProjectionMatrix();
glutPostRedisplay();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment