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;
- int ang11 = 90, ang12 = 0, ang21 = 90, ang22 = 0;
- void init(void) {
- glClearColor(0.0, 0.0, 0.0, 0.0);
- }
- void display(void) {
- glClear(GL_COLOR_BUFFER_BIT);
- glPushMatrix();
- //Esfera na origem
- glTranslatef(0.0, 0.0, 0.0);
- glutWireSphere(0.3, 10, 10);
- //pinca 1
- glPushMatrix();
- glTranslatef(1.0, 0.0, 0.0);
- glPushMatrix();
- glRotatef((GLfloat) ang11, 0.0, 0.0, 1.0);
- glScalef(0.5, 4.0, 1.0);
- glutWireCube(0.5);
- glPopMatrix();
- glPushMatrix();
- glTranslatef(1.0, 1.0, 0.0);
- glRotatef((GLfloat)ang12, 0.0, 0.0, 1.0);
- glScalef(0.5, 4.0, 1.0);
- glutWireCube(0.5);
- glPopMatrix();
- //Retornando a origem
- glPopMatrix();
- //pinca 2
- glPushMatrix();
- glTranslatef(0.0, 1.0, 0.0);
- glPushMatrix();
- glRotatef((GLfloat)ang21, 0.0, 0.0, 1.0);
- glScalef(4.0, 0.5, 1.0);
- glutWireCube(0.5);
- glPopMatrix();
- glPushMatrix();
- glTranslatef(1.0, 1.0, 0.0);
- glRotatef((GLfloat)ang22, 0.0, 0.0, 1.0);
- glScalef(4.0, 0.5, 1.0);
- glutWireCube(0.5);
- glPopMatrix();
- //Retornando a origem
- 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 'o':
- ang11 = (ang11 + 1) % 360;
- ang12 = (ang12 + 1) % 360;
- ang21 = (ang21 - 1) % 360;
- ang22 = (ang22 - 1) % 360;
- glutPostRedisplay();
- break;
- case 'O':
- ang11 = (ang11 - 1) % 360;
- ang12 = (ang12 - 1) % 360;
- ang21 = (ang21 + 1) % 360;
- ang22 = (ang22 + 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