Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as C++ by Samm ( 14 years ago )
#include <freeglut.h>

#define ESCAPE 27


int windowHandle;
int win;
GLfloat cranex;
GLfloat craney;
GLfloat cranez;
GLfloat rotatey;
GLfloat rotatedeg;
GLfloat Gatey;
GLfloat Zoom;

/* The function called when our window is resized (which shouldn't happen, because we're fullscreen) */

void resizeScene(int width, int height)
{
// Prevent A Divide By Zero If The Window Is Too Small

if(height == 0)
{
height=1;
}

// Reset The Current Viewport And Perspective Transformation

glViewport(0, 0, width, height);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();

gluPerspective(45.0f, (GLfloat) width / (GLfloat) height, 0.1f, 100.0f);
glMatrixMode(GL_MODELVIEW);
}

//============================================DRAWING=================================================

void craneleftclaw()
{

//*~~~~~~~~~BOX THING~~~~~~~~~*
//back
glBegin(GL_QUADS);
glColor3f(0.3,0,0);
glVertex3f(-2,-12,-5);
glVertex3f(-1,-12,-5);
glVertex3f(-1,-16,-5);
glVertex3f(-2,-16,-5);
glEnd();
//front
glBegin(GL_QUADS);
glColor3f(0.3,0,0);
glVertex3f(-2,-12,0.0);
glVertex3f(-1,-12,0);
glVertex3f(-1,-16,0);
glVertex3f(-2,-16,0);
glEnd();

//*~~~~~~~~~~~~~~~~LOWER TRIANGLE~~~~~~~~~~~~~~~~~~~~~~* 


//back
glBegin(GL_TRIANGLES);
glColor3f(0,0.6,0);
glVertex3f(-6,-12,-5);
glVertex3f(-2,-12,-5);
glVertex3f(-2,-16,-5);
glEnd();
//front
glBegin(GL_TRIANGLES);
glColor3f(0.3,0.6,0);
glVertex3f(-6,-12,0);
glVertex3f(-2,-12,0);
glVertex3f(-2,-16,0);
glEnd();

//*~~~~~~~~~~~~~~~~UPPER TRIANGLE~~~~~~~~~~~~~~~~~~~~~~*

//right
glBegin(GL_QUADS);
glColor3f(0.7,0.6,0.6);
glVertex3f(-2,-8,0);
glVertex3f(-2,-8,-5);
glVertex3f(-2,-12,-5);
glVertex3f(-2,-12,0);
glEnd();

//back
glBegin(GL_TRIANGLES);
glColor3f(0,1,0);
glVertex3f(-2,-8,-5);
glVertex3f(-2,-12,-5);
glVertex3f(-6,-12,-5);
glEnd();

//left
glBegin(GL_QUADS);
glColor3f(0.7,0.6,0.4);
glVertex3f(-2,-8,0);
glVertex3f(-2,-8,-5);
glColor3f(0.6,0.3,0);
glVertex3f(-6,-12,-5);
glColor3f(0.6,0.3,0);
glVertex3f(-6,-12,0);
glEnd();

//front
glBegin(GL_TRIANGLES);
glColor3f(0.7,0.6,0.4);
glVertex3f(-2,-8,0);
glColor3f(0.6,0.3,0);
glVertex3f(-2,-12,0);
glColor3f(0.3,0.0,0);
glVertex3f(-6,-12,0);
glEnd();


}
void cranerightclaw()
{
//*~~~~~~~~~~~~~~~~~~~~BOX THING~~~~~~~~~~~~~~~~~~~~~~~*
//back
glBegin(GL_QUADS);
glColor3f(0.3,0,0);
glVertex3f(2,-12,-5);
glVertex3f(1,-12,-5);
glVertex3f(1,-16,-5);
glVertex3f(2,-16,-5);
glEnd();
//front
glBegin(GL_QUADS);
glColor3f(0.3,0,0);
glVertex3f(2,-12,0.0);
glVertex3f(1,-12,0);
glVertex3f(1,-16,0);
glVertex3f(2,-16,0);
glEnd();
//*~~~~~~~~~~~~~~~~~~~~LOWER TRIANGLE~~~~~~~~~~~~~~~~~~~~*

//back
glBegin(GL_TRIANGLES);
glColor3f(0,0.6,0);
glVertex3f(6,-12,-5);
glVertex3f(2,-12,-5);
glVertex3f(2,-16,-5);
glEnd();
//front
glBegin(GL_TRIANGLES);
glColor3f(0.3,0.6,0);
glVertex3f(6,-12,0);
glVertex3f(2,-12,0);
glVertex3f(2,-16,0);
glEnd();
//*~~~~~~~~~~~~~~~~~~~~~~~~~UPPER TRIANGLE~~~~~~~~~~~~~~~~~~~~~~~~~~*

//right
glBegin(GL_QUADS);
glColor3f(0.7,0.6,0.6);
glVertex3f(2,-8,0);
glVertex3f(2,-8,-5);
glVertex3f(2,-12,-5);
glVertex3f(2,-12,0);
glEnd();
//back
glBegin(GL_TRIANGLES);
glColor3f(0,1,0);
glVertex3f(2,-8,-5);
glVertex3f(2,-12,-5);
glVertex3f(6,-12,-5);
glEnd();

//left
glBegin(GL_QUADS);
glColor3f(0.7,0.6,0.4);
glVertex3f(2,-8,0);
glVertex3f(2,-8,-5);
glColor3f(0.6,0.3,0);
glVertex3f(6,-12,-5);
glColor3f(0.6,0.3,0);
glVertex3f(6,-12,0);
glEnd();
//front
glBegin(GL_TRIANGLES);
glColor3f(0.7,0.6,0.4);
glVertex3f(2,-8,0);
glColor3f(0.6,0.3,0);
glVertex3f(2,-12,0);
glColor3f(0.3,0.0,0);
glVertex3f(6,-12,0);
glEnd();
}

void cranebody()
{

//back
glBegin(GL_QUADS);
glColor3f(0,1,1);
glVertex3f(-2.0f, 0.0f, -5.0f);
glVertex3f(2.0f, 0.0f, -5.0f);
glVertex3f(2.0f, -8.0f, -5.0f);
glVertex3f(-2.0f, -8.0f, -5.0f);
glEnd();

//lower
glBegin(GL_QUADS);
glColor3f(0,0,1);
glVertex3f(-2,-8,0);
glVertex3f(2,-8,0);
glVertex3f(2,-8,-5);
glVertex3f(-2,-8,-5);
glEnd();

//right
glBegin(GL_QUADS);
glColor3f(1,1,0);
glVertex3f(2,0,0);
glVertex3f(2,-8,0);
glVertex3f(2,-8,-5);
glVertex3f(2,0,-5);
glEnd();

//left
glBegin(GL_QUADS);
glColor3f(0.7,0.6,0.4);
glVertex3f(-2,0,0);
glVertex3f(-2,-8,0);
glColor3f(1,1,1);
glVertex3f(-2,-8,-5);
glColor3f(0.7,0.6,0.4);
glVertex3f(-2,0,-5);
glEnd();


//upper
glBegin(GL_QUADS);
glColor3f(0.7,0.6,0.4);
glVertex3f(-2,0,0);
glVertex3f(-2,0,-5);
glColor3f(1,1,1);
glVertex3f(2,0,-5);
glVertex3f(2,0,0);
glEnd();


//front
glBegin(GL_QUADS);
glColor3f(0.7,0.6,0.4);
glVertex3f(-2.0f, 0.0f, 0.0f);
glVertex3f(2.0f, 0.0f, 0.0f);
glVertex3f(2.0f, -8.0f, 0.0f);
glColor3f(1,1,1);
glVertex3f(-2.0f, -8.0f, 0.0f);
glEnd();

}

void base()
{
glPushMatrix();
glTranslatef(0,-25,0);
glBegin(GL_LINES);
glVertex3f(15,-15,-15);
glVertex3f(-15,-15,-15);
glVertex3f(-15,-15,15);
glVertex3f(15,-15,15);
glEnd();
glPopMatrix();
}


//=======================================ANIMATIONS,COMMANDS,CHECKS======================================
//Makes the toy "falldown"
void ToyFallingDown();
{
if (win==1)
     toy1--;
else if (win==2)
     toy2--;
else if (win==3)
     toy3--;
}

//Makes Crane GO Down
void CraneGoDown();
{
do while (craney!=0)
     {
     craney--;
     }
}

//Makes Crane Go Up
void CraneGoUp();
{
do while (craney!=5)
     {
     craney++;
     }
}

void Check1();
{
 if (toy1x == cranex && toy1z == cranez)
     {
     toy1x=cranex;
     toy1y=craney;
     toy1z=cranez;
     }
 else if (toy2x == cranex && toy2z == cranez)
     {
     toy2x=cranex;
     toy2y=craney;
     toy2z=cranez;
     }
 else if (toy3x == cranex && toy3z == cranez)
     {
     toy3x=cranex;
     toy3y=craney;
     toy3z=cranez;
     }
}


void showScene()
{

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();



// Write your 3D stuff below this line! 
glPushMatrix();
glTranslatef(0,0,-40);
base();
glPopMatrix();

glTranslatef(0,0,-40);
glRotatef(45,1,1,0);

glTranslatef(cranex,craney,cranez);
cranebody();
craneleftclaw();
cranerightclaw();

/*

don't wait!
start processing buffered OpenGL routines

*/

glFlush();

// Need to swap buffer to show latest render

glutSwapBuffers();
}

/*

Prepare everything for viewing

*/

void initMyComponents(int width, int height)
{
GLfloat aspectRatio;

// select clearing (background) color

glClearColor(0.0, 0.0, 0.0, 0.0);

// initialize viewing values

// Clear both screen and depth buffer

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glMatrixMode(GL_PROJECTION);

// Reset The Projection Matrix

glLoadIdentity();

// No need for this advanced clipping function from the red book.

//glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);

// Calculate The Aspect Ratio Of The Window

aspectRatio = (GLfloat) width / (GLfloat) height;
gluPerspective(45.0f, aspectRatio, 0.1f, 100.0f);
glMatrixMode(GL_MODELVIEW);
}

void keyPressed(unsigned char key, int x, int y)
{
/* avoid thrashing this procedure. Uncomment the line if using gcc */

//usleep(100);

/* If escape is pressed, kill everything. */

if (key == ESCAPE)
{
/* shut down our window */

glutDestroyWindow(windowHandle);

/* exit the program...normal termination. */
}


do
{
//MOVES THE CRANE
//x-axis
if (key=='d')
{
cranex-=1;
turn-=1;
}
if (key=='a')
{
cranex+=1;
turn-=1;
}

//Z-axis
if (key == 'w')
{
cranez+=1;
turn-=1;
}
if(key == 's')
{
cranez-=1;
turn-=1;
}
}
while (turn!=0);


if (key == 'm')
{
rotatey+=1;
}
if (key == 'n')
{
rotatey-=1;
}
if (key=='j')
{
rotatedeg+=10;
}
if (key=='k')
{
rotatedeg-=10;
}
if(key==',')
{
Gatey+=1;
}
if(key=='.')
{
Gatey-=1;
}
if(key=='[')
{
Zoom-=10;
}
if(key==']')
{
Zoom+=10;
}
}

/*

Declare initial window size, position, and display mode
(single buffer and RGBA). Open window with "hello"
in its title bar. Call initialization routines.
Register callback function to display graphics.
Enter main loop and process events.

*/

int main(int argc, char** argv)
{
glutInit(&argc;, argv);
rotatey=1;
cranex=-5;
craney=5;
rotatedeg=45;
turn=10;
win=0;

// Do double-buffer for smoother rendering and animation.

glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH);
glutInitWindowSize(640, 480);
//glutInitWindowPosition(100, 100);
glutInitWindowPosition(0, 0);
windowHandle = glutCreateWindow("Your OpenGL Program");

initMyComponents(640, 480);

/* Register the function called when the keyboard is pressed. */

glutKeyboardFunc(&keyPressed;);

// Show in full screen. Can be used later by uncommenting.

//glutFullScreen();

// Draw the scenery

glutDisplayFunc(&showScene;);
glutReshapeFunc(&resizeScene;);
glutIdleFunc(&showScene;);
glutMainLoop();



return 0;
}

 

Revise this Paste

Parent: 47769
Children: 47771
Your Name: Code Language: