diff --git a/Assignment C-6b (3D Cube).cpp b/Assignment C-6b (3D Cube).cpp new file mode 100644 index 0000000..c5ddac4 --- /dev/null +++ b/Assignment C-6b (3D Cube).cpp @@ -0,0 +1,94 @@ +#include + +void mydisplay() +{ + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glLoadIdentity(); //resets modelview matrix + +glTranslatef(0.0,0.0,-10.0); +//glScalef(2.0,2.0,0.0); +//glRotatef(20.0,1.0,0.0,0.0); +glRotatef(-45.0,0.0,1.0,0.0); + + + + glBegin(GL_QUADS); + //front (red) + glColor3f(1.0,0.0,0.0); + glVertex3f(-1.0,1.0,1.0); + glVertex3f(-1.0,-1.0,1.0); + glVertex3f(1.0,-1.0,1.0); + glVertex3f(1.0,1.0,1.0); + + //back (green) + glColor3f(0.0,1.0,0.0); + glVertex3f(1.0,1.0,-1.0); + glVertex3f(1.0,-1.0,-1.0); + glVertex3f(-1.0,-1.0,-1.0); + glVertex3f(-1.0,1.0,-1.0); + + //right (blue) + glColor3f(0.0,0.0,1.0); + glVertex3f(1.0,1.0,1.0); + glVertex3f(1.0,-1.0,1.0); + glVertex3f(1.0,-1.0,-1.0); + glVertex3f(1.0,1.0,-1.0); + + //left (yellow) + glColor3f(1.0,1.0,0.0); + glVertex3f(-1.0,1.0,-1.0); + glVertex3f(-1.0,-1.0,-1.0); + glVertex3f(-1.0,-1.0,1.0); + glVertex3f(-1.0,1.0,1.0); + + //top (cyan) + glColor3f(0.0,1.0,1.0); + glVertex3f(-1.0,1.0,-1.0); + glVertex3f(-1.0,1.0,1.0); + glVertex3f(1.0,1.0,1.0); + glVertex3f(1.0,1.0,-1.0); + + //bottom (magenta) + glColor3f(1.0,0.0,1.0); + glVertex3f(-1.0,-1.0,-1.0); + glVertex3f(-1.0,-1.0,1.0); + glVertex3f(1.0,-1.0,1.0); + glVertex3f(1.0,-1.0,-1.0); + + glEnd(); + + glFlush(); +} + +void init() +{ + glClearColor(0.0,0.0,0.0,1.0); + glEnable(GL_DEPTH_TEST); +} + +void reshape(int w, int h) +{ + glViewport(0,0,w,h); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); //resets projection matrix + gluPerspective(60,1,2.0,50.0); + // glOrtho(-5,5,-5,5,-5,5); + glMatrixMode(GL_MODELVIEW); + +} + + +int main(int argc,char** argv) +{ + glutInit(&argc,argv); + glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH); + glutInitWindowPosition(100,100); + glutInitWindowSize(500,500); + glutCreateWindow("3D transformations"); + glutDisplayFunc(mydisplay); + glutReshapeFunc(reshape); + init(); + glutMainLoop(); +} + +