Hi ,
I am quite new to open GL.
Right now I am generating different view by changing glLookAt values.
Can some one help me to make it with the help of keyboard buttons or with menu.
for example for top view press ‘T’ , for angular view press ‘A’.
The below is my code…
…
#include<iostream>
#include<stdlib.h>
#include <glut.h>
using namespace std;
void init(void)
{
glClearColor (1.0, 1.0, 1.0, 0.0);
glShadeModel (GL_FLAT);
}
void display(void)
{
glClear (GL_COLOR_BUFFER_BIT);
glColor3f (1.0, 1,1.0);
glLoadIdentity (); /* clear the matrix /
/ viewing transformation */
//…
// for front view
//gluLookAt (0,0,12.0, 0.0, 0.0, 0.0, 0,1, 0);
// for Angular view
gluLookAt (-1, 10, 12.0, 2.0, 2.0, 3.0, 0.0, 1, 0.0);
//…
// for top veiw
//gluLookAt (0,15,0, 0.0,0.0, 0.0, 0.0,0, 1.0);
//…
glScalef (1,1,1); /* modeling transformation */
glBegin(GL_QUADS);
glColor3f (0,1,0);
glVertex3f(10,-0.5, 4.0);
glVertex3f(10, -0.5, -10.0);
glVertex3f(-10,-0.5, -10.0);
glVertex3f(-10,-0.5,4.0);
glEnd();
glPushMatrix();
glColor3f (1,0.5,0.0);
glTranslatef (5.0, 0.0, -0.5);
glutSolidCube(1.5);
glPopMatrix();
glPushMatrix();
glTranslatef (4.0, 1.0, -1.5);
glutSolidCube(1.5);
glPopMatrix();
glPushMatrix();
glTranslatef (3.0, 2.0, -2.5);
glutSolidCube(1.5);
glPopMatrix();
glPushMatrix();
glTranslatef (2.0, 3.0,-3.5);
glutSolidCube(1.5);
glPopMatrix();
glPushMatrix();
glColor3f (0.0, 1.0, 1.0);
glTranslatef (0.0, 0.0, 0.0);
glutSolidSphere(0.5,100,100);
glTranslatef (1.0, 0.0, 0.0);
glutSolidSphere(0.5,100,100);
glTranslatef (1.0, 0.0, 0.0);
glutSolidSphere(0.5,100,100);
glTranslatef (1.0, 0.0, 0.0);
glutSolidSphere(0.5,100,100);
glPopMatrix();
glPushMatrix();
glTranslatef (0.5,0.866, 0.0);
glutSolidSphere(0.5,100,100);
glPopMatrix();
glPushMatrix();
glTranslatef (1.5,0.866, 0.0);
glutSolidSphere(0.5,100,100);
glPopMatrix();
glPushMatrix();
glTranslatef (2.5,0.866, 0.0);
glutSolidSphere(0.5,100,100);
glPopMatrix();
glPushMatrix();
glTranslatef (1.0,1.732, 0.0);
glutSolidSphere(0.5,100,100);
glPopMatrix();
glPushMatrix();
glTranslatef (2.0,1.732, 0.0);
glutSolidSphere(0.5,100,100);
glPopMatrix();
glPushMatrix();
glTranslatef (1.5,2.598, 0.0);
glutSolidSphere(0.5,100,100);
glPopMatrix();
// THis is left side sphere balls building up
glPushMatrix();
glTranslatef (-1.0, 0.0, 0.0);
glColor3f (1,0,0.0);
glutSolidSphere(0.5,100,100);
glTranslatef (0.0, 0.0, -1.0);
glutSolidSphere(0.5,100,100);
glTranslatef (0.0, 0.0, -1.0);
glutSolidSphere(0.5,100,100);
glTranslatef (0.0, 0.0, -1.0);
glutSolidSphere(0.5,100,100);
glPopMatrix();
glPushMatrix();
glTranslatef (-1.0, 0.866, -0.5);
glutSolidSphere(0.5,100,100);
glPopMatrix();
glPushMatrix();
glTranslatef (-1.0, 0.866, -1.5);
glutSolidSphere(0.5,100,100);
glPopMatrix();
glPushMatrix();
glTranslatef (-1.0, 0.866, -2.5);
glutSolidSphere(0.5,100,100);
glPopMatrix();
glPushMatrix();
glTranslatef (-1.0, 1.732, -1);
glutSolidSphere(0.5,100,100);
glPopMatrix();
glPushMatrix();
glTranslatef (-1.0, 1.732, -2);
glutSolidSphere(0.5,100,100);
glPopMatrix();
glPushMatrix();
glTranslatef (-1.0, 2.598, -1.5);
glutSolidSphere(0.5,100,100);
glPopMatrix();
glutSwapBuffers();
glFlush ();
}
void reshape (int w, int h)
{
glViewport (0,0, (GLsizei) w, (GLsizei) h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glFrustum (-1.0, 1.0, -1.0, 1.0, 1.5, 20.0);
//glOrtho(-10,20,-10,10,10,-20);
//glOrtho(-15,20,0,0,-15,15);
//glFrustum (-1.0, 1.0, -1.5, 1.2, 1.5, 20.0);
glMatrixMode (GL_MODELVIEW);
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (500, 500);
glutInitWindowPosition (100, 100);
glutCreateWindow (argv[0]);
init ();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}