Added 3 new cubes and color changing
This commit is contained in:
+45
-17
@@ -5,10 +5,11 @@ using namespace std;
|
||||
|
||||
/* Prototypes */
|
||||
void obj_flag(void);
|
||||
void obj_cube(void);
|
||||
void obj_cube(float clr);
|
||||
void obj_cube2(void);
|
||||
|
||||
float rotation = 0;
|
||||
float color = 0;
|
||||
int width = 800;
|
||||
int height = 600;
|
||||
|
||||
@@ -23,14 +24,35 @@ void display()
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
gluLookAt(0, 0, -3,
|
||||
gluLookAt(0, 5, -5,
|
||||
0, 0, 0,
|
||||
0, 1, 0);
|
||||
|
||||
//Cube 1
|
||||
glRotatef(rotation, 0, 1, 0);
|
||||
glRotatef(rotation/2, 0, 0, 1);
|
||||
obj_cube(1.0f);
|
||||
glRotatef(rotation, 0, -1, 0);
|
||||
|
||||
obj_cube();
|
||||
//Cube 2
|
||||
glTranslatef(3.0f, 0, 0);
|
||||
glRotatef(rotation / 2, 0, 0, 1);
|
||||
obj_cube(1.0f);
|
||||
glRotatef(rotation / 2, 0, 0, -1);
|
||||
glTranslatef(-3.0, 0, 0);
|
||||
|
||||
//Cube 3
|
||||
glTranslatef(-3.0f, 0, 0);
|
||||
glRotatef(rotation / 2, 1, 0, 0);
|
||||
obj_cube(1.0f);
|
||||
glRotatef(rotation / 2, -1, 0, 0);
|
||||
glTranslatef(3.0f, 0, 0);
|
||||
|
||||
//Cube 4
|
||||
glTranslatef(0, 0, 3.0f);
|
||||
glRotatef(rotation / 2, 1, 1, 0);
|
||||
obj_cube(color);
|
||||
glRotatef(rotation / 2, -1, -1, 0);
|
||||
glTranslatef(0, 0, -3.0f);
|
||||
|
||||
glutSwapBuffers();
|
||||
}
|
||||
@@ -47,6 +69,11 @@ void keyboard(unsigned char key, int x, int y)
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void mousemoved(int x, int y)
|
||||
{
|
||||
color = (x / 100);
|
||||
}
|
||||
|
||||
void resize(int w, int h)
|
||||
{
|
||||
width = w;
|
||||
@@ -65,6 +92,7 @@ int main(int argc, char *argv[])
|
||||
glutDisplayFunc(display);
|
||||
glutIdleFunc(idle);
|
||||
glutKeyboardFunc(keyboard);
|
||||
glutMotionFunc(mousemoved);
|
||||
glutReshapeFunc(resize);
|
||||
|
||||
glutMainLoop();
|
||||
@@ -160,64 +188,64 @@ void obj_cube2()
|
||||
glEnd();
|
||||
}
|
||||
|
||||
void obj_cube()
|
||||
void obj_cube(float clr)
|
||||
{
|
||||
//Side 1 : Green
|
||||
glBegin(GL_QUADS);
|
||||
glColor3f(0.0f, 1.0f, 0.0f);
|
||||
glColor3f(0.0f, 1.0f / clr, 0.0f);
|
||||
glVertex3f(-1, -1, -1);
|
||||
glVertex3f(-1, 1, -1);
|
||||
glColor3f(0.5f, 1.0f, 0.5f);
|
||||
glColor3f(0.5f, 1.0f / clr, 0.5f);
|
||||
glVertex3f(1, 1, -1);
|
||||
glVertex3f(1, -1, -1);
|
||||
glEnd();
|
||||
|
||||
//Side 2 : Red
|
||||
glBegin(GL_QUADS);
|
||||
glColor3f(1.0f, 0.0f, 0.0f);
|
||||
glColor3f(1.0f / clr, 0.0f, 0.0f);
|
||||
glVertex3f(-1, -1, 1);
|
||||
glVertex3f(-1, 1, 1);
|
||||
glColor3f(1.0f, 0.5f, 0.5f);
|
||||
glColor3f(1.0f / clr, 0.5f, 0.5f);
|
||||
glVertex3f(1, 1, 1);
|
||||
glVertex3f(1, -1, 1);
|
||||
glEnd();
|
||||
|
||||
//Side 3 : Blue
|
||||
glBegin(GL_QUADS);
|
||||
glColor3f(0.0f, 0.0f, 1.0f);
|
||||
glColor3f(0.0f, 0.0f, 1.0f / clr);
|
||||
glVertex3f(-1, -1, -1);
|
||||
glVertex3f(-1, -1, 1);
|
||||
glColor3f(0.5f, 0.5f, 1.0f);
|
||||
glColor3f(0.5f, 0.5f, 1.0f / clr);
|
||||
glVertex3f(-1, 1, 1);
|
||||
glVertex3f(-1, 1, -1);
|
||||
glEnd();
|
||||
|
||||
//Side 4 : Yellow
|
||||
glBegin(GL_QUADS);
|
||||
glColor3f(1.0f, 1.0f, 0.0f);
|
||||
glColor3f(1.0f / clr, 1.0f / clr, 0.0f);
|
||||
glVertex3f(1, -1, -1);
|
||||
glVertex3f(1, -1, 1);
|
||||
glColor3f(1.0f, 1.0f, 0.5f);
|
||||
glColor3f(1.0f / clr, 1.0f / clr, 0.5f);
|
||||
glVertex3f(1, 1, 1);
|
||||
glVertex3f(1, 1, -1);
|
||||
glEnd();
|
||||
|
||||
//Side 5 : Purple
|
||||
glBegin(GL_QUADS);
|
||||
glColor3f(1.0f, 0.0f, 1.0f);
|
||||
glColor3f(1.0f / clr, 0.0f, 1.0f / clr);
|
||||
glVertex3f(-1, -1, -1);
|
||||
glVertex3f(-1, -1, 1);
|
||||
glColor3f(1.0f, 0.5f, 1.0f);
|
||||
glColor3f(1.0f / clr, 0.5f, 1.0f / clr);
|
||||
glVertex3f(1, -1, 1);
|
||||
glVertex3f(1, -1, -1);
|
||||
glEnd();
|
||||
|
||||
//Side 6 : Light blue
|
||||
glBegin(GL_QUADS);
|
||||
glColor3f(0.0f, 1.0f, 1.0f);
|
||||
glColor3f(0.0f, 1.0f / clr, 1.0f / clr);
|
||||
glVertex3f(-1, 1, -1);
|
||||
glVertex3f(-1, 1, 1);
|
||||
glColor3f(0.5f, 1.0f, 1.0f);
|
||||
glColor3f(0.5f, 1.0f / clr, 1.0f / clr);
|
||||
glVertex3f(1, 1, 1);
|
||||
glVertex3f(1, 1, -1);
|
||||
glEnd();
|
||||
|
||||
Reference in New Issue
Block a user