Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<windows.h>
- #include <iostream>
- #include <stdlib.h>
- #include <GL/glut.h>
- using namespace std;
- static int posXcorpo = 0, posZcorpo = 0, posYcorpo = 0, cabeca=0;
- void init(void) {
- glClearColor(0.0, 0.0, 0.0, 0.0);
- }
- void display(void) {
- glClear(GL_COLOR_BUFFER_BIT);
- glColor3f(0.9f, 0.9f, 0.9f);
- glPushMatrix();
- /*Plataforma servindo como chΓ£o*/
- glColor3f(1.0, 1.0, 1.0);
- glBegin(GL_QUADS);
- glVertex3f(-3.0, -3.0, 0.0);
- glVertex3f(3.0, -3.0, 0.0);
- glVertex3f(3.0, -1.0, 0.0);
- glVertex3f(-3.0, -1.0, 0.0);
- glEnd();
- glFlush();
- /* origem do corpo */
- glTranslatef(0.0, 0.0, 0.0);
- glTranslatef(posXcorpo, posYcorpo, posZcorpo);
- glPushMatrix();
- glScalef(2.0, 2.0, 1.5);
- glutWireCube(1.0);
- glPopMatrix();
- /* origem da cabeca */
- glRotatef((GLfloat)cabeca, 0.0, 1.0, 0.0);
- glTranslatef(0.0, 1.38, 0.0);
- glPushMatrix();
- glScalef(2.4, 2.4, 1.0);
- glutWireCube(0.3);
- glPopMatrix();
- /* origem da ombro direito */
- glTranslatef(0.0, 0.0, 0.0);
- glTranslatef(1.25, -2.3, 0.2);
- glTranslatef(0.0, 1.5, 0.0);
- glPushMatrix();
- glScalef(1.0, 1.0, 1.0);
- glutSolidSphere(0.3,20,20);
- glPopMatrix();
- /* origem da ombro esquerdo */
- glTranslatef(0.0, 0.0, 0.0);
- glTranslatef(-2.3, -0.25, 0.2);
- //glTranslatef(0.0, -1.5, 0.0);
- glPushMatrix();
- glScalef(1.0, 1.0, 1.0);
- glutSolidSphere(0.3, 20, 20);
- glPopMatrix();
- /* origem volta para o sistema de coordenadas original */
- glPopMatrix();
- glutSwapBuffers();
- }
- void reshape(int w, int h) {
- glViewport(0, 0, (GLsizei)w, (GLsizei)h);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- gluPerspective(65.0, (GLfloat)w / (GLfloat)h, 1.0, 20.0);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glTranslatef(0.0, 0.0, -5.0);
- }
- void keyboard(unsigned char key, int x, int y) {
- switch (key) {
- case 'x':
- posXcorpo = (posXcorpo + 1) % 360;
- glutPostRedisplay();
- break;
- case 'X':
- posXcorpo = (posXcorpo - 1) % 360;
- glutPostRedisplay();
- break;
- case 'z':
- posZcorpo = (posZcorpo + 1) % 360;
- glutPostRedisplay();
- break;
- case 'Z':
- posZcorpo = (posZcorpo - 1) % 360;
- glutPostRedisplay();
- break;
- case 'y':
- posYcorpo = (posYcorpo + 1) % 360;
- glutPostRedisplay();
- break;
- case 'Y':
- posYcorpo = (posYcorpo - 1) % 360;
- glutPostRedisplay();
- break;
- case 27:
- exit(0);
- break;
- default:
- break;
- }
- }
- int main(int argc, char** argv) {
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
- glutInitWindowSize(800, 600);
- 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