From 842822d2c8f4132a313656fe1d84daa5ff3435d2 Mon Sep 17 00:00:00 2001 From: TanmayMachkar Date: Thu, 7 Dec 2023 10:26:55 +0530 Subject: [PATCH] 3d cube assgn added --- Assignment C-6b (3D Cube).cpp | 94 +++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 Assignment C-6b (3D Cube).cpp 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(); +} + +