Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Run.h"
- #include <string>
- Closet* closet = new Closet();
- // For testing purpose
- Shelf shelf;
- Drawer drawer;
- Hanger hanger;
- DrawFloor drawFloor;
- Estado estado;
- SetClosetMeasures setClosetMeasures;
- SelectComponent selectComponents;
- DrawUtils drawUtils;
- InputUtils inputUtils;
- /*******************************
- *** init opengl model ***
- *******************************/
- void Init(void)
- {
- srand((unsigned)time(NULL));
- estado.menuActivo = GL_FALSE;
- estado.camera.eye.x = 40;
- estado.camera.eye.y = 40;
- estado.camera.eye.z = 40;
- estado.camera.up.x = 0;
- estado.camera.up.y = 0;
- estado.camera.up.z = 0;
- estado.ortho = GL_TRUE;
- estado.camera.fov = 60;
- estado.camera.dir_long = 0;
- estado.camera.dir_lat = 0;
- closet->xMouse = closet->yMouse = -1;
- glClearColor(0.0, 0.0, 0.0, 0.0);
- glEnable(GL_POINT_SMOOTH);
- glEnable(GL_LINE_SMOOTH);
- glEnable(GL_POLYGON_SMOOTH);
- glEnable(GL_DEPTH_TEST);
- }
- /*******************************
- *** callbacks de janela ***
- *******************************/
- void Reshape(int width, int height)
- {
- glViewport(0, 0, (GLint)width, (GLint)height);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- if (estado.ortho)
- {
- if (width < height)
- glOrtho(-20, 20, -20 * (GLdouble)height / width, 20 * (GLdouble)height / width, -100, 100);
- else
- glOrtho(-20 * (GLdouble)width / height, 20 * (GLdouble)width / height, -20, 20, -100, 100);
- }
- else
- gluPerspective(estado.camera.fov, (GLfloat)width / height, 1, 100);
- glMatrixMode(GL_MODELVIEW);
- }
- void setCamera(Camera *cam) {
- Pos center;
- glRotatef(-90, 0, 0, 1);
- //glRotatef(180, 0, 1,0);
- //posicao de do olho
- cam->eye.x = -cos(cam->dir_long) * cos(cam->dir_lat);
- cam->eye.y = sin(cam->dir_lat);
- cam->eye.z = sin(cam->dir_long) * cos(cam->dir_lat);
- //onde queremos olhar
- center.x = cam->eye.x - cos(cam->dir_long) * cos(cam->dir_lat);
- center.y = cam->eye.y + sin(cam->dir_lat);
- center.z = cam->eye.z + sin(cam->dir_long) * cos(cam->dir_lat);
- /*
- center.x = 0;
- center.y = 0.5;
- center.z = 0;*/
- /*
- cam->eye.x = center.x - cos(cam->dir_long);
- cam->eye.y = center.y + 0.5;
- cam->eye.z = center.z + sin(cam->dir_long);*/
- //O Z nao ta a deixar dar a volta para cima
- gluLookAt(cam->eye.x, cam->eye.y, cam->eye.z, center.x, center.y, center.z, 0, 1, 0);
- }
- /*******************************
- *** callbacks de desenho ***
- *******************************/
- void Draw(void)
- {
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glLoadIdentity();
- /*gluLookAt(estado.camera.eye.x, estado.camera.eye.y, estado.camera.eye.z, \
- estado.camera.center.x, estado.camera.center.y, estado.camera.center.z, \
- estado.camera.up.x, estado.camera.up.y, estado.camera.up.z);*/
- setCamera(&estado.camera);
- /*Draw here*/
- glColor3f(0.5f, 0.5f, 0.5f);
- drawFloor.draw(25);
- glPushMatrix();
- //Draw closet
- closet->draw();
- //t.draw();
- //Draw Shelf in the middle of the closet
- //shelf.draw(closet->getWidth() - 2 * closet->getThickness(), closet->getHeight(), closet->getHeight());
- //Draw Shelf in the middle of the closet
- //drawer.open();
- //drawer.close();
- //drawer.draw(closet->getWidth() - 2 * closet->getThickness(),( closet->getHeight() - 2 * closet->getThickness()) *0.4, closet->getDepth() - 2 * closet->getThickness());
- // Draw hanger
- /*hanger.setModules(0);
- hanger.setVertical_pos(1);
- hanger.draw(closet->getWidth() - 2 * closet->getThickness(), (closet->getHeight() - 2 * closet->getThickness()) *0.4, closet->getDepth() - 2 * closet->getThickness());*/
- //Draw components
- closet->drawComponents();
- /*Draw here*/
- glPopMatrix();
- glFlush();
- if (estado.doubleBuffer)
- glutSwapBuffers();
- }
- /*******************************
- *** callbacks timer/idle ***
- *******************************/
- void Timer(int value)
- {
- glutTimerFunc(DELAY, Timer, 0);
- if (estado.menuActivo) return;
- glutPostRedisplay();
- }
- /*******************************
- *** callbacks de teclado ***
- *******************************/
- void Key(unsigned char key, int x, int y)
- {
- switch (key) {
- case 27:
- exit(1);
- case '1':
- setClosetMeasures.readMeasures(closet);
- inputUtils.printMenu();
- break;
- case '2':
- selectComponents.addComponent(closet);
- inputUtils.printMenu();
- break;
- case '3':
- selectComponents.removeComponent(closet);
- inputUtils.printMenu();
- break;
- case '4':
- estado.ortho = !estado.ortho;
- Reshape(glutGet(GLUT_WINDOW_WIDTH), glutGet(GLUT_WINDOW_HEIGHT));
- break;
- }
- }
- void KeyUp(unsigned char key, int x, int y)
- {
- switch (key) {
- }
- }
- void SpecialKey(int key, int x, int y)
- {
- switch (key) {
- }
- }
- void SpecialKeyUp(int key, int x, int y)
- {
- switch (key) {
- }
- }
- void mouseMotion(int x, int y) {
- int dif = x - closet->xMouse;
- estado.camera.dir_lat -= dif * RAD(EYE_ROTACAO);
- //latitude
- dif = y - closet->yMouse;
- estado.camera.dir_long -= dif * RAD(EYE_ROTACAO);
- //limitar dir_lat a +-rad(45)
- //if()
- //atualizar coordenadas do rato
- closet->xMouse = x;
- closet->yMouse = y;
- }
- void mouseNavigate(int button, int state, int x, int y)
- {
- //se o mouse2 carregado
- if (button == GLUT_RIGHT_BUTTON) {
- if (state == GLUT_DOWN) {
- closet->xMouse = x;
- closet->yMouse = y;
- //registar callback de movimento do rato
- glutMotionFunc(mouseMotion);
- }
- else glutMotionFunc(NULL);
- }
- }
- /*******************************
- *** run the program ***
- *******************************/
- int main(int argc, char **argv)
- {
- char str[] = " makefile MAKEFILE Makefile ";
- estado.doubleBuffer = 1;
- glutInit(&argc, argv);
- glutInitWindowPosition(0, 0);
- glutInitWindowSize(640, 480);
- glutInitDisplayMode(((estado.doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE) | GLUT_RGB | GLUT_DEPTH);
- if (glutCreateWindow("Closet Designer") == GL_FALSE)
- exit(1);
- Init();
- inputUtils.printMenu();
- // Registar callbacks do GLUT
- // callbacks de janelas/desenho
- glutReshapeFunc(Reshape);
- glutDisplayFunc(Draw);
- // Callbacks de teclado
- glutKeyboardFunc(Key);
- glutKeyboardUpFunc(KeyUp);
- glutSpecialFunc(SpecialKey);
- glutSpecialUpFunc(SpecialKeyUp);
- // Callbacks do rato
- glutMouseFunc(mouseNavigate);
- // callbacks timer/idle
- glutTimerFunc(DELAY, Timer, 0);
- // COMECAR...
- glutMainLoop();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement