Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <GL/glut.h> //for all OpenGL functionality
- //#include "stdafx.h"
- // Define initial values for components
- static int body = 0, right = 0,left=0,rudder=0;
- int font=(int)GLUT_BITMAP_8_BY_13;
- void init(void)
- {
- glClearColor (0.0, 0.0, 0.0, 0.0);
- }
- // convenience function for displaying strings
- void renderBitmapString(float x, float y, void *font,char *string)
- {
- char *c;
- glRasterPos3f(x, y,0.0);
- for (c=string; *c != '\0'; c++) {
- glutBitmapCharacter(font, *c);
- }
- }
- void display(void)
- {
- glClear (GL_COLOR_BUFFER_BIT);
- glColor3f (1.0, 1.0, 0.0);
- // Directions
- renderBitmapString(-3,5.3,(void *)font,"Satellite Animation v1.0");
- renderBitmapString(-3,5,(void *)font,"press b to rotate body");
- renderBitmapString(-3,4.7,(void *)font,"press r - rotate flaps");
- renderBitmapString(-3,4.4,(void *)font,"press l - rotate left flaps");
- renderBitmapString(-3,4.1,(void *)font,"press m - rotate left rudder");
- renderBitmapString(-3,3.8,(void *)font,"press a - rotate all components");
- glColor3f (1.0, 1.0, 1.0);
- // Create the body
- // Push and Pop are used to nest levels of control for the geometric transformation
- // This nesting allows for controlling transformation on the entire object and subcomponents
- glPushMatrix();
- // The Body
- glPushMatrix();
- // Rotate about the x-axis
- glRotatef ((GLfloat) body, 1.0, 0.0, 0.0);
- glutWireSphere (1.5,10, 10);
- // Create a Right Wing
- glPushMatrix();
- glRotatef ((GLfloat) right, 1.0, 0.0, 0.0);
- glPushMatrix();
- glTranslatef (3.0, 0.0, 0.0);
- glScalef (3.0, 0.1, 0.7);
- glutWireCube (1.0);
- glPopMatrix();
- // Create a Left Wing
- glPushMatrix();
- glRotatef ((GLfloat) left, 1.0, 0.0, 0.0); // X-axis rotation
- glTranslatef (-3.0, 0.0, 0.0);
- glPushMatrix();
- glScalef (3.0, 0.1, 0.7);
- glutWireCube (1.0);
- glPopMatrix();
- // Create rudder on Left wing
- glPushMatrix();
- glRotatef ((GLfloat) rudder, 0.0, 0.0, 1.0); // Z-axis rotation
- glPushMatrix();
- glScalef (0.1, 2.0, 0.7);
- glutWireCube (1.0);
- glPopMatrix();
- // For each Push we must have a pop
- glPopMatrix();
- glPopMatrix();
- glPopMatrix();
- glPopMatrix();
- glPopMatrix();
- glutSwapBuffers();
- }
- void reshape (int w, int h)
- {
- glViewport (0, 0, (GLsizei) w, (GLsizei) h);
- glMatrixMode (GL_PROJECTION);
- glLoadIdentity ();
- gluPerspective(100.0, (GLfloat) w/(GLfloat) h, 2.0, 80.0);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glTranslatef (0.0, 0.0, -5.0);
- }
- void keyboard (unsigned char key, int x, int y)
- {
- switch (key) {
- case 'b': /* b key rotates body */
- body = (body + 5) % 360;
- glutPostRedisplay();
- break;
- case 'r': /* r key rotates right wing */
- right = (right + 5) % 360;
- glutPostRedisplay();
- break;
- case 'l': /* l key rotates left wing */
- left = (left - 5) % 360;
- glutPostRedisplay();
- break;
- case 'm': /* m key rotates rudder on left wing */
- rudder = (rudder - 5) % 360;
- glutPostRedisplay();
- break;
- case 'a': /* a key performs all movements */
- body = (body - 5) % 360;
- right = (right - 5) % 360;
- left = (left - 5) % 360;
- rudder = (rudder - 5) % 360;
- glutPostRedisplay();
- break;
- default:
- break;
- }
- }
- int main(int argc, char** argv)
- {
- glutInit(&argc, argv);
- glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB);
- glutInitWindowSize (500, 500);
- glutInitWindowPosition (100, 100);
- glutCreateWindow (argv[0]);
- init ();
- glutDisplayFunc(display);
- glutReshapeFunc(reshape);
- glutKeyboardFunc(keyboard);
- glutMainLoop();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement