Untitled

mail@pastecode.io avatar
unknown
c_cpp
a year ago
2.0 kB
7
Indexable
Never
#include <GL/glut.h>
#include <cstdlib>
#include <cctype>
#include <cstdio>

#define SCREEN_X 500
#define SCREEN_Y 500

using namespace std;

float rx = 0, rz = 0;

float abertura = 40.0, znear = 1, zfar = 20, aspect = 1;
GLUquadricObj *quadratic;

void init() {
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(abertura, aspect, znear, zfar);
    glMatrixMode(GL_MODELVIEW);

    glClearColor(0, 0, 0, 1);

    glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);

    glEnable(GL_DEPTH_TEST);
    quadratic = gluNewQuadric();
}

void display() {
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity( );

    gluPerspective(abertura, aspect, znear, zfar);

    glMatrixMode(GL_MODELVIEW);

    glLoadIdentity();
    gluLookAt(4, 0, 15,
              0, 0, 0,
              0, 1, 0);

    glRotatef((GLfloat) rx, 0.0f, 1.0f, 0.0f);
    glRotatef((GLfloat) rz, 1.0f, 0.0f, 0.0f);
    glClear(GL_COLOR_BUFFER_BIT);

    glPushMatrix();
    glColor3f(1,0,0);
    gluCylinder(quadratic, 1.0, 1, 5, 30, 30);
    glPopMatrix();

    glutSwapBuffers();
}

void keyboard(unsigned char key, int x, int y) {
    key = tolower(key);
    switch (key) {
        case 27:
            exit(0);
        case '+':
            abertura += 1;

    }
}

void MotionFunc(int x, int y) {
    float dx, dy;
    rx = x;
    rz = y;
}

void MouseFunc(int botao, int estado, int x, int y) {

}

int main(int argc, char **argv) {
    glutInit(&argc, argv);

    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);

    glutInitWindowSize(SCREEN_X, SCREEN_Y);
    glutInitWindowPosition(450, 10);
    glutCreateWindow("Motor");

    glutDisplayFunc(display);
    glutMotionFunc(MotionFunc);
    glutMouseFunc(MouseFunc);
    glutIdleFunc(display);
    glutKeyboardFunc(keyboard);

    init();

    glutMainLoop();
    return 0;
}