Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <windows.h>
- #include <iostream>
- #include "glut.h"
- static int w = 0, h = 0;
- static float Angle = 0.0f;
- float scaleX = 100, scaleY = 100, scaleZ = 100;
- int x = 0, y = 0, z = 0;
- void Init(void) {
- glClearColor(0.8f, 0.9f, 0.9f, 1.0f);
- }
- void Update(void) {
- Angle += 0.05f;
- glClear(GL_COLOR_BUFFER_BIT);
- glLoadIdentity();
- gluLookAt(scaleX, scaleY, scaleZ, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);
- glRotatef((GLfloat)Angle, 0.0f, 1.0f, 0.0f);
- glTranslatef(x, y, z);
- glBegin(GL_TRIANGLES);
- //1
- glColor3f(0.9f, 0.2f, 0.5f);
- glVertex3f(-75.0f, 0.0f, -50.0f);
- glVertex3f(-75.0f, 0.0f, 50.0f);
- glVertex3f(75.0f, 0.0f, 50.0f);
- //2
- glColor3f(0.5f, 0.2f, 0.9f);
- glVertex3f(-75.0f, 0.0f, -50.0f);
- glVertex3f(75.0f, 0.0f, -50.0f);
- glVertex3f(75.0f, 0.0f, 50.0f);
- glEnd();
- glLineWidth(3.0f);
- //Green y
- glBegin(GL_LINE_STRIP);
- glColor3ub(0, 255, 0);
- glVertex3f(-75, 0, -50);
- glVertex3f(-75, 3000, -50);
- glEnd();
- //Red x
- glBegin(GL_LINE_STRIP);
- glColor3ub(255, 0, 0);
- glVertex3f(-75, 0, -50);
- glVertex3f(3000, 0, -50);
- glEnd();
- //Blue z
- glBegin(GL_LINE_STRIP);
- glColor3ub(0, 0, 255);
- glVertex3f(-75, 0, -50);
- glVertex3f(-75, 0, 300);
- glEnd();
- glLineWidth(10.0f);
- //Black
- glBegin(GL_LINE_STRIP);
- glColor3ub(0, 0, 0);
- glVertex3f(-75, 50, -30);
- glVertex3f(90, 50, -30);
- glEnd();
- //Blue
- glEnable(GL_LINE_STIPPLE);
- glLineStipple(2, 0x00FF);
- glColor3ub(0, 0, 255);
- glBegin(GL_LINE_LOOP);
- glVertex3f(-75, 70, -30);
- glVertex3f(90, 0, -30);
- glEnd();
- glDisable(GL_LINE_STIPPLE);
- ///////////////////////////
- glBegin(GL_POLYGON);
- glColor3f(255, 0, 0);
- glVertex3f(30, 0, 30);
- glVertex3f(30, 60, 30);
- glVertex3f(0, 60, 30);
- glVertex3f(0, 0, 30);
- glEnd();
- glBegin(GL_POLYGON);
- glColor3f(255, 0, 0);
- glVertex3f(30, 0, 0);
- glVertex3f(30, 60, 0);
- glVertex3f(0, 60, 0);
- glVertex3f(0, 0, 0);
- glEnd();
- glBegin(GL_POLYGON);
- glColor3f(255, 0, 0);
- glVertex3f(30, 0, 0);
- glVertex3f(30, 30, 0);
- glVertex3f(30, 30, 30);
- glVertex3f(30, 0, 30);
- glEnd();
- glBegin(GL_POLYGON);
- glColor3f(255, 0, 0);
- glVertex3f(0, 0, 30);
- glVertex3f(0, 60, 30);
- glVertex3f(0, 60, 0);
- glVertex3f(0, 0, 0);
- glEnd();
- glBegin(GL_POLYGON);
- glColor3f(255, 0, 0);
- glVertex3f(90, 60, 30);
- glVertex3f(90, 60, 0);
- glVertex3f(0, 60, 0);
- glVertex3f(0, 60, 30);
- glEnd();
- //
- glBegin(GL_POLYGON);
- glColor3f(255, 0, 0);
- glVertex3f(90, 30, 30);
- glVertex3f(90, 30, 0);
- glVertex3f(0, 30, 0);
- glVertex3f(0, 30, 30);
- glEnd();
- glBegin(GL_POLYGON);
- glColor3f(255, 0, 0);
- glVertex3f(90, 30, 30);
- glVertex3f(90, 60, 30);
- glVertex3f(90, 60, 0);
- glVertex3f(90, 30, 0);
- glEnd();
- glBegin(GL_POLYGON);
- glColor3f(255, 0, 0);
- glVertex3f(90, 30, 0);
- glVertex3f(90, 60, 0);
- glVertex3f(0, 60, 0);
- glVertex3f(0, 30, 0);
- glEnd();
- glBegin(GL_POLYGON);
- glColor3f(255, 0, 0);
- glVertex3f(90, 30, 30);
- glVertex3f(90, 60, 30);
- glVertex3f(0, 60, 30);
- glVertex3f(0, 30, 30);
- glEnd();
- glBegin(GL_POLYGON);
- glColor3f(255, 0, 0);
- glVertex3f(30, 0, 0);
- glVertex3f(30, 0, 30);
- glVertex3f(0, 0, 30);
- glVertex3f(0, 0, 0);
- glEnd();
- glFlush();
- glutSwapBuffers();
- }
- void Reshape(int width, int height) {
- w = width;
- h = height;
- glViewport(0, 0, w, h);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- gluPerspective(65.0f, w / h, 1.0f, 1000.0f);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- }
- void keyboard(unsigned char key, int xx, int yy)
- {
- std::cout << "Key pressed: " << key << std::endl;
- switch (key) {
- case 'a':
- std::cout << "!Rotate counter-clockwise" << std::endl;
- Angle += 5.0f;
- glutPostRedisplay();
- break;
- case 'd':
- std::cout << "Rotate Clockwise" << std::endl;
- Angle -= 5.0f;
- glutPostRedisplay();
- break;
- case 'w':
- std::cout << "Offset Left" << std::endl;
- x += 10;
- glutPostRedisplay();
- break;
- case 's':
- std::cout << "Offset Down" << std::endl;
- y += 10;
- glutPostRedisplay();
- break;
- case 'r':
- std::cout << "Zoom in X in 2 times" << std::endl;
- scaleX = 200;
- scaleY = 100;
- scaleZ = 100;
- glutPostRedisplay();
- break;
- case 'f':
- std::cout << "Y-scale reduction in 2 times" << std::endl;
- scaleX = 100;
- scaleY = 50;
- scaleZ = 100;
- glutPostRedisplay();
- break;
- case 'e':
- std::cout << "Normal" << std::endl;
- scaleX = 100;
- scaleY = 100;
- scaleZ = 100;
- glutPostRedisplay();
- break;
- default:
- break;
- }
- }
- int main(int argc, char *argv[]) {
- glutInit(&argc, argv);
- glutInitWindowSize(800, 600);
- glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
- glutCreateWindow("Computer Graphics #7");
- glutDisplayFunc(Update);
- glutReshapeFunc(Reshape);
- glutKeyboardFunc(keyboard);
- Init();
- glutMainLoop();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement