Sunday, September 25, 2011

Figure 5


$40 off Craftsman 5 Drawer Homeowner Tool Center with Riser and Parts Bins $99.99 on sale 10/2-10/8
Sears Deal of the Day: Thule Car Top Carrier, Quest
Wholesale Fleece Blankets
400950_BuddhaGroove.com-Culture Infused Living: Home Accents, Jewelry, Accessories from around the world!
400948_Culture Infused Living: Home Accents, Jewelry, and accessories from around the world. CulturalElemen
504427_Save up to 75% on batteries and accessories at Brooklyn Battery Works!
504080_10% OFF Orders of $75 or More from Journelle.com! Use Promo Code: NOV11 (Valid 11/1 - 11/30/11)
502239_Brand names, bargain prices at shoezoo.com. If you don't love your new shoes, return them for free!

400949_GaneshMall.com-Culture Infused Living: Home Accents, Jewelry, and accessories from around the world!


Figure 5: The airplane
Controls:
w -> zoom in
s -> zoom out
d -> fly left
g -> fly right
if idle, rotate
r -> go up
f -> go down

The second window displays the coordinates
=================planes.h===========
void normalizeAndDraw(float vPoints[][3])
{
float vNormal[3];
normalize(vNormal, vPoints[0], vPoints[1], vPoints[2]);
glNormal3fv(vNormal);
glVertex3fv(vPoints[0]);
glVertex3fv(vPoints[1]);
glVertex3fv(vPoints[2]);
}
void drawPlane(float xRot, float yRot, float x, float y)
{
glPushMatrix();
glRotatef(xRot, 1.0f, 0.0f, 0.0f);
glRotatef(yRot, 0.0f, 1.0f, 0.0f);


glBegin(GL_TRIANGLES);
//------ Nose -------------
// White
glColor3ub(255, 255, 255);
glVertex3f(0.0f, 0.0f, 60.0f);
glVertex3f(-x, 0.0f, 30.0f);
glVertex3f(x,0.0f,30.0f);
//
glColor3ub(200,100,200);
glVertex3f(x,0.0f,30.0f);
glVertex3f(0.0f, y, 30.0f);
glVertex3f(0.0f, 0.0f, 60.0f);
// Red
glColor3ub(255,0,0);
glVertex3f(0.0f, 0.0f, 60.0f);
glVertex3f(0.0f, y, 30.0f);
glVertex3f(-x,0.0f,30.0f);
// Body of the Plane
glColor3ub(0,255,0);
glVertex3f(-x,0.0f,30.0f);
glVertex3f(0.0f, y, 30.0f);
glVertex3f(0.0f, 0.0f, -56.0f);

glColor3ub(100,255,0);
glVertex3f(0.0f, 0.0f, -56.0f);
glVertex3f(0.0f, y, 30.0f);
glVertex3f(x,0.0f,30.0f);

glColor3ub(0, 255, 255);
glVertex3f(x,0.0f,30.0f);
glVertex3f(-x, 0.0f, 30.0f);
glVertex3f(0.0f, 0.0f, -56.0f);
//-------------- Left wing
// triangle for bottom of wing
glColor3ub(128,128,128);
glVertex3f(0.0f,2.0f,27.0f);
glVertex3f(-(x+45), 2.0f, -8.0f);
glVertex3f(x+45, 2.0f, -8.0f);

glColor3ub(180,64,64);
glVertex3f(x+45, 2.0f, -8.0f);
glVertex3f(0.0f, 7.0f, -8.0f);
glVertex3f(0.0f,2.0f,27.0f);

glColor3ub(192,192,192);
glVertex3f(x+45, 2.0f, -8.0f);
glVertex3f(-(x+45), 2.0f, -8.0f);
glVertex3f(0.0f,7.0f,-8.0f);

// Other wing top section
glColor3ub(180,64,64);
glVertex3f(0.0f,2.0f,27.0f);
glVertex3f(0.0f, 7.0f, -8.0f);
glVertex3f(-(x+45), 2.0f, -8.0f);

//------------------- Tail section
// Bottom of back fin
glColor3ub(255,128,255);
glVertex3f(-(x+15), -0.50f, -57.0f);
glVertex3f(x+15, -0.50f, -57.0f);
glVertex3f(0.0f,-0.50f,-40.0f);

// top of left side
glColor3ub(255,128,0);
glVertex3f(0.0f,-0.5f,-40.0f);
glVertex3f(x+15, -0.5f, -57.0f);
glVertex3f(0.0f, 4.0f, -57.0f);

// top of right side
glColor3ub(255,128,0);
glVertex3f(0.0f, 4.0f, -57.0f);
glVertex3f(-(x+15), -0.5f, -57.0f);
glVertex3f(0.0f,-0.5f,-40.0f);

// back of bottom of tail
glColor3ub(255,255,255);
glVertex3f((x+15),-0.5f,-57.0f);
glVertex3f(-(x+15), -0.5f, -57.0f);
glVertex3f(0.0f, 4.0f, -57.0f);

// Top of Tail section left
//glColor3ub(255,0,0);
glVertex3f(0.0f,0.5f,-40.0f);
glVertex3f((18-x), 0.5f, -57.0f);
glVertex3f(0.0f, 25.0f, -65.0f);

glColor3ub(255,0,0);
glVertex3f(0.0f, 25.0f, -65.0f);
glVertex3f(-(18-x), 0.5f, -57.0f);
glVertex3f(0.0f,0.5f,-40.0f);

// Back of horizontal section
glColor3ub(128,128,128);
glVertex3f((18-x),0.5f,-57.0f);
glVertex3f(-(18-x), 0.5f, -57.0f);
glVertex3f(0.0f, 25.0f, -65.0f);

glEnd(); //

glPopMatrix();
glutSwapBuffers();// Display the results
}
void drawRotatingPlane()
{
drawPlane(0, 15, 30, 0);
}
void drawShadow2(int xRot, int yRot, int x, int y)
{
glPushMatrix();
glRotatef(xRot, 1.0f, 0.0f, 0.0f);
glRotatef(yRot, 0.0f, 1.0f, 0.0f);

glColor3ub(0,0,0);
glBegin(GL_TRIANGLES);
//------ Nose -------------
// White
//glColor3ub(255, 255, 255);
glVertex3f(0.0f, 0.0f, 60.0f);
glVertex3f(-x, 0.0f, 30.0f);
glVertex3f(x,0.0f,30.0f);
//
//glColor3ub(200,100,200);
glVertex3f(x,0.0f,30.0f);
glVertex3f(0.0f, y, 30.0f);
glVertex3f(0.0f, 0.0f, 60.0f);
// Red
//glColor3ub(255,0,0);
glVertex3f(0.0f, 0.0f, 60.0f);
glVertex3f(0.0f, y, 30.0f);
glVertex3f(-x,0.0f,30.0f);
// Body of the Plane
//glColor3ub(0,255,0);
glVertex3f(-x,0.0f,30.0f);
glVertex3f(0.0f, y, 30.0f);
glVertex3f(0.0f, 0.0f, -56.0f);

//glColor3ub(100,255,0);
glVertex3f(0.0f, 0.0f, -56.0f);
glVertex3f(0.0f, y, 30.0f);
glVertex3f(x,0.0f,30.0f);

//glColor3ub(0, 255, 255);
glVertex3f(x,0.0f,30.0f);
glVertex3f(-x, 0.0f, 30.0f);
glVertex3f(0.0f, 0.0f, -56.0f);
//-------------- Left wing
// triangle for bottom of wing
// glColor3ub(128,128,128);
glVertex3f(0.0f,2.0f,27.0f);
glVertex3f(-(x+45), 2.0f, -8.0f);
glVertex3f(x+45, 2.0f, -8.0f);

//glColor3ub(180,64,64);
glVertex3f(x+45, 2.0f, -8.0f);
glVertex3f(0.0f, 7.0f, -8.0f);
glVertex3f(0.0f,2.0f,27.0f);

//glColor3ub(192,192,192);
glVertex3f(x+45, 2.0f, -8.0f);
glVertex3f(-(x+45), 2.0f, -8.0f);
glVertex3f(0.0f,7.0f,-8.0f);

// Other wing top section
//glColor3ub(180,64,64);
glVertex3f(0.0f,2.0f,27.0f);
glVertex3f(0.0f, 7.0f, -8.0f);
glVertex3f(-(x+45), 2.0f, -8.0f);

//------------------- Tail section
// Bottom of back fin
//glColor3ub(255,128,255);
glVertex3f(-(x+15), -0.50f, -57.0f);
glVertex3f(x+15, -0.50f, -57.0f);
glVertex3f(0.0f,-0.50f,-40.0f);

// top of left side
//glColor3ub(255,128,0);
glVertex3f(0.0f,-0.5f,-40.0f);
glVertex3f(x+15, -0.5f, -57.0f);
glVertex3f(0.0f, 4.0f, -57.0f);

// top of right side
//glColor3ub(255,128,0);
glVertex3f(0.0f, 4.0f, -57.0f);
glVertex3f(-(x+15), -0.5f, -57.0f);
glVertex3f(0.0f,-0.5f,-40.0f);

// back of bottom of tail
//glColor3ub(255,255,255);
glVertex3f((x+15),-0.5f,-57.0f);
glVertex3f(-(x+15), -0.5f, -57.0f);
glVertex3f(0.0f, 4.0f, -57.0f);

// Top of Tail section left
//glColor3ub(255,0,0);
glVertex3f(0.0f,0.5f,-40.0f);
glVertex3f((18-x), 0.5f, -57.0f);
glVertex3f(0.0f, 25.0f, -65.0f);

//glColor3ub(255,0,0);
glVertex3f(0.0f, 25.0f, -65.0f);
glVertex3f(-(18-x), 0.5f, -57.0f);
glVertex3f(0.0f,0.5f,-40.0f);

// Back of horizontal section
//glColor3ub(128,128,128);
glVertex3f((18-x),0.5f,-57.0f);
glVertex3f(-(18-x), 0.5f, -57.0f);
glVertex3f(0.0f, 25.0f, -65.0f);

glEnd(); //

glPopMatrix();
glutSwapBuffers();// Display the results
}
void drawShadow()
{
glColor3ub(0,0,0);//black color for shadow
// Nose Cone - Points straight down
// Set material color
glBegin(GL_TRIANGLES);
glNormal3f(0.0f, -1.0f, 0.0f);
glNormal3f(0.0f, -1.0f, 0.0f);
glVertex3f(0.0f, 0.0f, 60.0f);
glVertex3f(-15.0f, 0.0f, 30.0f);
glVertex3f(15.0f,0.0f,30.0f);
// Verticies for this panel
{
float vPoints[3][3] = {{ 15.0f, 0.0f, 30.0f},
{ 0.0f, 15.0f, 30.0f},
{ 0.0f, 0.0f, 60.0f}};
// Calculate the normal for the plane
normalizeAndDraw(vPoints);
}
{
float vPoints[3][3] = {{ 0.0f, 0.0f, 60.0f },
{ 0.0f, 15.0f, 30.0f },
{ -15.0f, 0.0f, 30.0f }};
normalizeAndDraw(vPoints);
}
// Body of the Plane
{
float vPoints[3][3] = {{ -15.0f, 0.0f, 30.0f },
{ 0.0f, 15.0f, 30.0f },
{ 0.0f, 0.0f, -56.0f }};
normalizeAndDraw(vPoints);
}
{
float vPoints[3][3] = {{ 0.0f, 0.0f, -56.0f },
{ 0.0f, 15.0f, 30.0f },
{ 15.0f,0.0f,30.0f }};
normalizeAndDraw(vPoints);
}
glNormal3f(0.0f, -1.0f, 0.0f);
glVertex3f(15.0f,0.0f,30.0f);
glVertex3f(-15.0f, 0.0f, 30.0f);
glVertex3f(0.0f, 0.0f, -56.0f);
//----------------- Left wing
// Large triangle for bottom of wing
{
float vPoints[3][3] = {{ 0.0f,2.0f,27.0f },
{ -60.0f, 2.0f, -8.0f },
{ 60.0f, 2.0f, -8.0f }};
normalizeAndDraw(vPoints);
}
{
float vPoints[3][3] = {{ 60.0f, 2.0f, -8.0f},
{0.0f, 7.0f, -8.0f},
{0.0f,2.0f,27.0f }};
normalizeAndDraw(vPoints);
}
{
float vPoints[3][3] = {{60.0f, 2.0f, -8.0f},
{-60.0f, 2.0f, -8.0f},
{0.0f,7.0f,-8.0f }};
normalizeAndDraw(vPoints);
}
{
float vPoints[3][3] = {{0.0f,2.0f,27.0f},
{0.0f, 7.0f, -8.0f},
{-60.0f, 2.0f, -8.0f}};
normalizeAndDraw(vPoints);
}
//------------------------ Tail section
// Bottom of back fin
glNormal3f(0.0f, -1.0f, 0.0f);
glVertex3f(-30.0f, -0.50f, -57.0f);
glVertex3f(30.0f, -0.50f, -57.0f);
glVertex3f(0.0f,-0.50f,-40.0f);
{
float vPoints[3][3] = {{ 0.0f,-0.5f,-40.0f },
{30.0f, -0.5f, -57.0f},
{0.0f, 4.0f, -57.0f }};
normalizeAndDraw(vPoints);
}
{
float vPoints[3][3] = {{ 0.0f, 4.0f, -57.0f },
{ -30.0f, -0.5f, -57.0f },
{ 0.0f,-0.5f,-40.0f }};
normalizeAndDraw(vPoints);
}
{
float vPoints[3][3] = {{ 30.0f,-0.5f,-57.0f },
{ -30.0f, -0.5f, -57.0f },
{ 0.0f, 4.0f, -57.0f }};
normalizeAndDraw(vPoints);
}
{
float vPoints[3][3] = {{ 0.0f,0.5f,-40.0f },
{ 3.0f, 0.5f, -57.0f },
{ 0.0f, 25.0f, -65.0f }};
normalizeAndDraw(vPoints);
}
{
float vPoints[3][3] = {{ 0.0f, 25.0f, -65.0f },
{ -3.0f, 0.5f, -57.0f},
{ 0.0f,0.5f,-40.0f }};
normalizeAndDraw(vPoints);
}
{
float vPoints[3][3] = {{ 3.0f,0.5f,-57.0f },
{ -3.0f, 0.5f, -57.0f },
{ 0.0f, 25.0f, -65.0f }};
normalizeAndDraw(vPoints);
}
glEnd();
}
====================MatrixOperations.h=========

void crossProduct(float* result, const float* u, const float* v)
{
result[0] = u[1]*v[2] - v[1]*u[2];
result[1] = -u[0]*v[2] + v[0]*u[2];
result[2] = u[0]*v[1] - v[0]*u[1];
}
void normalize(float* result, const float* point1, const float* point2,
const float *point3)
{
float v1[3],v2[3]; // Temporary vectors

// Calculate two vectors from the three points. Assumes counter clockwise
// winding!
v1[0] = point1[0] - point2[0];
v1[1] = point1[1] - point2[1];
v1[2] = point1[2] - point2[2];

v2[0] = point2[0] - point3[0];
v2[1] = point2[1] - point3[1];
v2[2] = point2[2] - point3[2];

// Take the cross product of the two vectors to get
// the normal vector.
crossProduct(result, v1, v2);
}
float getVectorLengthSquared(const float* u)
{
return (u[0] * u[0]) + (u[1] * u[1]) + (u[2] * u[2]);
}
float getVectorLength(const float* u)
{
return float(sqrt(double(getVectorLengthSquared(u))));
}
void scaleVector3(float v[], float scale)
{
v[0] *= scale; v[1] *= scale; v[2] *= scale;
}
void normalizeVector(float u[])
{
scaleVector3(u, 1.0f / getVectorLength(u));
}
void getPlaneEquation(float* planeEq, const float* p1, const float* p2, const float* p3)
{
// Get two vectors... do the cross product
float v1[3], v2[3];

// V1 = p3 - p1
v1[0] = p3[0] - p1[0];
v1[1] = p3[1] - p1[1];
v1[2] = p3[2] - p1[2];

// V2 = P2 - p1
v2[0] = p2[0] - p1[0];
v2[1] = p2[1] - p1[1];
v2[2] = p2[2] - p1[2];


crossProduct(planeEq, v1, v2);
normalizeVector(planeEq);
// Back substitute to get D
planeEq[3] = -(planeEq[0] * p3[0] + planeEq[1] * p3[1] + planeEq[2] * p3[2]);
}
void makePlaneShadowMatrix(float* projectionMatrix, const float* planeEq, const float* vLightPos)
{
// These just make the code below easier to read. They will be
// removed by the optimizer.
float a = planeEq[0];
float b = planeEq[1];
float c = planeEq[2];
float d = planeEq[3];

float dx = -vLightPos[0];
float dy = -vLightPos[1];
float dz = -vLightPos[2];

// Now build the projectionMatrixection matrix
projectionMatrix[0] = b * dy + c * dz;
projectionMatrix[1] = -a * dy;
projectionMatrix[2] = -a * dz;
projectionMatrix[3] = 0.0;

projectionMatrix[4] = -b * dx;
projectionMatrix[5] = a * dx + c * dz;
projectionMatrix[6] = -b * dz;
projectionMatrix[7] = 0.0;

projectionMatrix[8] = -c * dx;
projectionMatrix[9] = -c * dy;
projectionMatrix[10] = a * dx + b * dy;
projectionMatrix[11] = 0.0;

projectionMatrix[12] = -d * dx;
projectionMatrix[13] = -d * dy;
projectionMatrix[14] = -d * dz;
projectionMatrix[15] = a * dx + b * dy + c * dz;
// Shadow matrix ready
}

=================
// Airplane.cpp : Defines the entry point for the console application.
//author: Cheikh Drame
//project3
//class: Computer Graphics with OpenGL
//year Fall2009
//school: Queens College
/*
//
//
*/
/*
//Author: Cheikh Drame
//To support, please do one of the following
//- Visit irap123.com many times a day
//- Join irap123.com
//- Buy my app irap123 (rhyming dictionary) available for android, and iphone. On windows phone, it is called iLyrics. If you not you can get the desktop version at www.irap123.com/apps/webstore/
//- Include irap123.com in your blogs, forums, facebook walls, email footers, comments
//- send a donation at my paypal address at cbdsigned.vevo@gmail.com
//- Buy a story at http://shop.pparzygnat.com
*/

#include "stdafx.h"
#include
#include
#include "MatrixOperations.h"
#include "planes.h"
#include


// Rotation amounts
static float xRotation = 0.0f;
static float yRotation = 0.0f;
static float specialRotation=0.0f;
static float specialYrotation=145;



int width, height;
// Transformation matrix to project shadow
float shadowMat[16];
float zoom=1;
static int idleCheck=101, add=5;
int background=1; //0 for daytime, 1 for night time, 2 for rainbow time
GLfloat specReference[] = { 1.0f, 1.0f, 1.0f, 1.0f };
GLfloat diffLight[] = { 0.7f, 0.7f, 0.7f, 1.0f };
GLfloat specular[] = { 1.0f, 1.0f, 1.0f, 1.0f};
GLfloat ambLight[] = { 0.3f, 0.3f, 0.3f, 1.0f };
GLfloat lightPosition[] = { -170.0f, 150.0f, -30.0f, 0.0f };
int xPos=15, yPos=15;

GLfloat pos[]={-2,4,55,1}, amb[]={0.3,0.3,0.3,1.0};
GLfloat front_amb_diff[]={0.7,0.5,0.1,1.0};
GLfloat back_amb_diff[]={0.4,0.7,0.1,1.0};
GLfloat spe[]={0.25,0.25,0.25,1.0};
GLfloat theta=0,dt=0.5, axs[3][3]={ {1,0,0}, {0,1,0},{0,0,1} };
int axis=0; //0:x, 1:y, 2:z, 3:light around z


void idle(int);
// Called to draw scene
void display(void)
{
// Clear the window with current clearing color
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

if(background==1){//availabe only at night time
glPushMatrix();
//glColor3f(1,1,1);
glTranslatef(-250, 205, 0); //
glutSolidSphere(15, 10, 10); //the sun
glPopMatrix();
//glColor3f(1,0,0);
glPushMatrix();
glTranslatef(200, 205, 0);
glutSolidSphere(5, 10, 10);//a far away planet
glPopMatrix();
}

glBegin(GL_QUADS);
glColor3ub(10,102,0);
glVertex3f(400, -150, -200);
glVertex3f(-400, -150, -200);
glColor3ub(0,10,0);
glVertex3f(-400, -150, 200);
glVertex3f(400, -150, 200);
glEnd();
// Save the matrix state and do the rotations
glPushMatrix();
// Draw jet at new orientation, put light in correct position
// before rotating the jet
glEnable(GL_LIGHTING);
glLightfv(GL_LIGHT0,GL_POSITION,lightPosition);
glRotatef(xRotation, 1.0f, 0.0f, 0.0f);//------
glRotatef(yRotation, 0.0f, 1.0f, 0.0f);//----------
// Restore original matrix state
glPopMatrix();
// Get ready to draw the shadow and the ground
// First disable lighting and save the projection state
glDisable(GL_DEPTH_TEST);
glDisable(GL_LIGHTING);
glPushMatrix();
// Multiply by shadow projection matrix
glMultMatrixf((GLfloat *)shadowMat);
// Now rotate the jet around in the new flattend space
glRotatef(xRotation, 1.0f, 0.0f, 0.0f);//------------
glRotatef(yRotation, 0.0f, 1.0f, 0.0f);//--------------
//glTranslatef(lightPosition[0],lightPosition[1], lightPosition[2]);
glEnable(GL_DEPTH_TEST);//-----------
glScalef(zoom, zoom, zoom);
// Pass true to indicate drawing shadow
//drawShadow2(xRotation, yRotation, xPos, yPos); //--------------------------------draw the shadow of the plane ----------
drawShadow();
// Restore the projection to normal
glPopMatrix();
// Draw the light source
glPushMatrix();
glTranslatef(lightPosition[0],lightPosition[1], lightPosition[2]);
glEnable(GL_DEPTH_TEST);
glScalef(zoom, zoom, zoom);
drawPlane(xRotation, yRotation, xPos, yPos);//------------------ draws the airplane ---------------
glPopMatrix();
glFlush();
glutSwapBuffers();
}
void keyboard(int key, int x, int y)
{
switch(key)
{
case GLUT_KEY_UP:
xRotation-= 5.0; break;
case GLUT_KEY_DOWN:
xRotation += 5.0; break;
case GLUT_KEY_LEFT:
yRotation -= 5.0; break;
case GLUT_KEY_RIGHT:
yRotation += 5.0; break;

}
idleCheck=0; add=0;
std::cout<<"xRotation: "< glutPostRedisplay();
}
void keyboard2(unsigned char key, int x, int y)
{
switch(key)
{
case 'w'://incrase the plane size
if(zoom<1.5) zoom+=0.1;
std::cout<<"zoom: "< break;
case 's'://decrease the plane size
if(zoom>0.4) zoom-=0.1;
std::cout<<"zoom: "< break;
case 'd'://left
if( (lightPosition[1]-1)>-260)
lightPosition[0]-=3;
xRotation=10; yRotation=285;
std::cout<<"going left: "< break;
case 'r'://up
if( (lightPosition[1]+1)<=168)
lightPosition[1]+=3;
std::cout<<"going up: "< break;
case 'g'://forward, right
xRotation=0; yRotation=105;
lightPosition[0]+=3;
std::cout<<"going right: "< break;
case 'f'://down
if( (lightPosition[1]-1)>-59)
lightPosition[1]-=3;
std::cout<<"going down: "< break;
}
idleCheck=0; add=0;
glutPostRedisplay();
}
void reshape(int w, int h)
{ GLfloat fAspect;
width=w; height=h;
// Prevent a divide by zero
if(h == 0) h = 1;
// Set Viewport to window dimensions
glViewport(0, 0, w, h);
// Reset coordinate system
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
fAspect = (GLfloat)w/(GLfloat)h;
gluPerspective(60.0f, fAspect, 200.0, 500.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
// Move out Z axis so we can see everything
glTranslatef(0.0f, 0.0f, -400.0f);
glLightfv(GL_LIGHT0,GL_POSITION,lightPosition);
}
void idle(int time)
{

yRotation+=add;
++idleCheck;
glutTimerFunc(100,idle, 1);
glutPostRedisplay();
if(idleCheck>30) add=5;

}
void processMenu(int value)
{
switch(value)
{
case 0: // day time
glClearColor(0.0f, 0.0f, 1.0f, 1.0f );
background=0;
break;
case 1: //night time
glClearColor(0.0f, 0.0f, 0.0f, 1.0f );
background=1;
break;
case 2: // unknown
glClearColor(0.8f, 0.7f, 0.4f, 1.0f );
background=2;
break;
}
}
int main(int argc, char* argv[])
{
std::cout<<"Use Arrow Keys to rotate the plane.\n";
std::cout<<"Use the 'w' to increase the plane size\n";
std::cout<<"Use the 's' to decrease the plane size\n";
std::cout<<"Use 'd' to advance the plane\n";
std::cout<<"Use 'g' to back up the plane\n";
std::cout<<"Use 'r' to go up\n";
std::cout<<"Use 'f' to go down\n";
std::cout<<"Right click to change the background to daytime, night time, and unknown\n";

width=800; height=600;
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(width, height);
glutCreateWindow("Airplane show: irap123.com");
glEnable(GL_DEPTH_TEST);
//------------------------------
// Any three points on the ground (counter clockwise order)
float points[3][3] = {{ -30.0f, -149.0f, -20.0f },
{ -30.0f, -149.0f, 20.0f },
{ 40.0f, -149.0f, 20.0f }};
// Setup and enable light 0
glLightfv(GL_LIGHT0,GL_AMBIENT,ambLight);
glLightfv(GL_LIGHT0,GL_DIFFUSE,diffLight);
glLightfv(GL_LIGHT0,GL_SPECULAR,specular);
glLightfv(GL_LIGHT0,GL_POSITION,lightPosition);
glEnable(GL_LIGHT0);

//
//glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, front_amb_diff);//
glMaterialfv(GL_BACK, GL_AMBIENT_AND_DIFFUSE, back_amb_diff);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, spe);
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 75);
glLightfv(GL_LIGHT0, GL_AMBIENT, amb);
glLightfv(GL_LIGHT0, GL_POSITION, pos);

// All materials hereafter have full specular reflectivity
// with a high shine
glMaterialfv(GL_FRONT, GL_SPECULAR,specReference);
glMateriali(GL_FRONT,GL_SHININESS,128);
// black background
glClearColor(0.0f, 0.0f, 0.0f, 1.0f );
// Get the plane equation from three points on the ground
float vPlaneEquation[4];
getPlaneEquation(vPlaneEquation, points[0], points[1], points[2]);
// Calculate projection matrix to draw shadow on the ground
makePlaneShadowMatrix(shadowMat, vPlaneEquation, lightPosition);
glEnable(GL_NORMALIZE);//keeps the color when the plane moves

glutCreateMenu(processMenu);
glutAddMenuEntry("Day time", 0);
glutAddMenuEntry("Night time", 1);
glutAddMenuEntry("Unknown Time", 2);
glutAttachMenu(GLUT_RIGHT_BUTTON);
glutReshapeFunc(reshape);
glutSpecialFunc(keyboard);
glutKeyboardFunc(keyboard2);
glutDisplayFunc(display);
glutTimerFunc(3000, idle, 1);

glutMainLoop();

return 0;
}

No comments:

Post a Comment