#include <iostream>
#include <stdlib.h>
#include<GL/gl.h>
#include <GL/glut.h>
#include<math.h>
#include<cstring>
#include <stdio.h>
#include <string.h>
using namespace std;
// actual vector representing the camera's direction
float lx=-0.0f,ly=0.0f,lz=-0.5f;
// XZ position of the camera
float x=0.0f,z=60.0f;
// all variables initialized to 1.0, meaning
// the triangle will initially be white
float red=1.0f, blue=1.0f, green=1.0f;
// angle for rotating triangle
float angle = 0.0f;
void drawSnowMan()
{
glColor3f(1.0f, 1.0f, 1.0f);
// Draw Body
glTranslatef(0.0f ,0.75f, 0.0f);
glutSolidSphere(0.75f,20,20);
// Draw Head
glTranslatef(0.0f, 1.0f, 0.0f);
glutSolidSphere(0.25f,20,20);
// Draw Eyes
glPushMatrix();
glColor3f(0.0f,0.0f,0.0f);
glTranslatef(0.05f, 0.10f, 0.18f);
glutSolidSphere(0.05f,10,10);
glTranslatef(-0.1f, 0.0f, 0.0f);
glutSolidSphere(0.05f,10,10);
glPopMatrix();
// Draw Nose
glColor3f(1.0f, 0.5f , 0.5f);
glRotatef(0.0f,1.0f, 0.0f, 0.0f);
glutSolidCone(0.08f,0.5f,10,2);
}
void changeSize(int w, int h)
{
// Prevent a divide by zero, when window is too short
// (you cant make a window of zero width).
if (h == 0)
h = 1;
float ratio = w * 1.0 / h;
// Use the Projection Matrix
glMatrixMode(GL_PROJECTION);
// Reset Matrix
glLoadIdentity();
// Set the viewport to be the entire window
glViewport(0, 0, w, h);
// Set the correct perspective.
gluPerspective(30.0f, ratio, 0.1f, 100.0f);
// Get Back to the Modelview
glMatrixMode(GL_MODELVIEW);
}
void renderScene(void)
{
// Clear Color and Depth Buffers
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Reset transformations
glLoadIdentity();
// Set the camera
/*gluLookAt( x, 1.0f, z,
x+lx, 1.0f, z+lz,
0.0f, 1.0f, 0.0f);*/
// Set the camera by Mzs
gluLookAt( x, 1.0f, z,
x+lx, 1.0f, z+lz,
0.0f, 1.0f, 0.0f);
// Draw ground
glColor3f(0.0f, 0.8f, 0.0f);
glBegin(GL_QUADS);
glVertex3f(-100.0f, 0.0f, -100.0f);
glVertex3f(-100.0f, 0.0f, 100.0f);
glVertex3f( 100.0f, 0.0f, 100.0f);
glVertex3f( 100.0f, 0.0f, -100.0f);
glEnd();
// Draw 36 SnowMen
/*for(int i = -3; i < 3; i++)
for(int j=-3; j < 3; j++) {
glPushMatrix();
glTranslatef(i*10.0,0,j * 10.0);
drawSnowMan();
glPopMatrix();*/
//Draw AIUB
glPushMatrix();
//glColor3f(1.0,0.0,0.0);
//glTranslatef(0,0,0);
//glutWireCube(1); // building
glLineWidth(3.0f);
glBegin(GL_LINES);
//X-Axis
glColor3ub(255,0,0);
glVertex3f(0,0,0);
glVertex3f(1,0,0);
//Y-Axis -UP
glColor3ub(255,255,0);
glVertex3f(0,0,0);
glVertex3f(0,1,0);
//Z-Axis - To wards Camera
glColor3ub(0,0,255);
glVertex3f(0,0,0);
glVertex3f(0,0,1);
glEnd();
glBegin(GL_POLYGON);
// \\ FRONT
glColor3ub(255,0,0);
glVertex3f(0,15,0);
glVertex3f(-8,13,0);
glVertex3f(-8,12.2,0);
glVertex3f(8,12.2,0);
glVertex3f(8,13,0);
glVertex3f(0,15,0);
glEnd();
glBegin(GL_POLYGON);
// \\ RARE
glColor3ub(255,0,0);
glVertex3f(0,15,-20);
glVertex3f(-8,13,-20);
glVertex3f(-8,12.2,-20);
glVertex3f(8,12.2,-20);
glVertex3f(8,13,-20);
glVertex3f(0,15,-20);
glEnd();
glBegin(GL_POLYGON);
// \\Z CHAL
glColor3ub(0,0,255);
glVertex3f(0,15,0);
glVertex3f(-8,13,0);
glVertex3f(-8,13,-20);
glVertex3f(0,15,-20);
glEnd();
glBegin(GL_POLYGON);
// \\Z CHAL
glColor3ub(0,120,255);
glVertex3f(0,15,0);
glVertex3f(8,13,0);
glVertex3f(8,13,-20);
glVertex3f(0,15,-20);
glEnd();
//glRotatef(_angle1, 1.0, 0.0, 0.0);
//glTranslatef(-0.5, -0.5, -0.5);
//-------------
glBegin(GL_POLYGON);
//LEG
glColor3ub(255,0,0);
glVertex3f(-7.8,13,0);
glVertex3f(-7.8,0,0);
glVertex3f(-7.5,0,0);
glVertex3f(-7.5,13,0);
glEnd();
glBegin(GL_POLYGON);
//ZZ LEG
glColor3ub(255,0,120);
glVertex3f(-7.8,13,-20);
glVertex3f(-7.8,0,-20);
glVertex3f(-7.5,0,-20);
glVertex3f(-7.5,13,-20);
glEnd();
glBegin(GL_POLYGON);
//LEG
glColor3ub(255,0,0);
glVertex3f(7.5,13,0);
glVertex3f(7.5,0,0);
glVertex3f(7.8,0,0);
glVertex3f(7.8,13,0);
glEnd();
glBegin(GL_POLYGON);
//ZZ LEG
glColor3ub(255,120,0);
glVertex3f(7.5,13,-20);
glVertex3f(7.5,0,-20);
glVertex3f(7.8,0,-20);
glVertex3f(7.8,13,-20);
glEnd();
//------------- FLOOR ROW
glBegin(GL_POLYGON);
//
glColor3ub(255,0,0);
glVertex3f(-7.5,9,0);
glVertex3f(-7.5,8.8,0);
glVertex3f(7.5,8.8,0);
glVertex3f(7.5,9,0);
glEnd();
glBegin(GL_POLYGON);
//
glColor3ub(255,0,0);
glVertex3f(-7.5,4.2,0);
glVertex3f(-7.5,4.0,0);
glVertex3f(7.5,4.0,0);
glVertex3f(7.5,4.2,0);
glEnd();
glPopMatrix();
glutSwapBuffers();
}
void processNormalKeys(unsigned char key, int x, int y)
{
if (key == 27)
exit(0);
}
void processSpecialKeys(int key, int xx, int yy)
{
//float fraction = 0.1f;
float fraction = 0.5f;
switch (key) {
case GLUT_KEY_LEFT :
//angle -= 0.01f;
angle -= 0.1f;
lx = sin(angle);
lz = -cos(angle);
break;
case GLUT_KEY_RIGHT :
//angle += 0.01f;
angle += 0.1f;
lx = sin(angle);
lz = -cos(angle);
break;
case GLUT_KEY_UP :
x += lx * fraction;
z += lz * fraction;
break;
case GLUT_KEY_DOWN :
x -= lx * fraction;
z -= lz * fraction;
break;
}
cout<<" ----------------------------------- "<<endl;
cout<<"Angle : "<<angle<<endl;
cout<<"Fraction : "<<fraction<<endl;
cout<<"X: "<<x<<endl;
//cout<<"Y: "<<y<<endl;
cout<<"Z: "<<z<<endl;
cout<<"lx: "<<lx<<endl;
//cout<<"ly: "<<ly<<endl;
cout<<"lz: "<<lz<<endl;
cout<<" ----------------------------------- "<<endl;
}
int main(int argc, char **argv)
{
// init GLUT and create window
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(100,100);
glutInitWindowSize(1180,620);
glutCreateWindow("Lighthouse3D - GLUT Tutorial");
// register callbacks
glutDisplayFunc(renderScene);
glutReshapeFunc(changeSize);
glutIdleFunc(renderScene);
glutKeyboardFunc(processNormalKeys);
glutSpecialFunc(processSpecialKeys);
// OpenGL init
glEnable(GL_DEPTH_TEST);
// enter GLUT event processing cycle
glutMainLoop();
return 1;
}