#define _USE_MATH_DEFINES #include #include #include #include #include #include #include #include using namespace glm; using namespace std; #define MOVING_CONST 0.1 #define ROTATION_CONST 3.14f / 180.f #define LOOK_MOVEMENT_CONST 0.1f #define PI 3.1415 /*--------------------------------------------------*/ char title[] = "Prozor"; int FPS = 60; vec3 CameraPosition(0.0, 1.0, -10.0); vec3 LookAt_vector(0.0, 0.0, 1.0); vec3 LookUp_vector(0.0, 1.0, 0.0); vector coordinateSystem; const int circle_dots = 50; const float height = 480; const float ratio = 16.f / 9.f; double upDownAngle = 0; int currentSpeed = 1; float arrowRotate = 0.f; mat4x4 ind = mat4x4(1); vec3 operator* (mat4x4 mat, vec3 vec) { vec4 v(vec.x, vec.y, vec.z, 1.f); v = mat * v; return vec3(v.x, v.y, v.z); } vector operator* (mat4x4 mat, vector vectors) { for (int i = 0; i < vectors.size(); i++) vectors[i] = mat * vectors[i]; return vectors; } //o GLUT_BITMAP_TIMES_ROMAN_24 //o GLUT_BITMAP_TIMES_ROMAN_10 //o GLUT_BITMAP_HELVETICA_18 void RenderString(float x, float y, void* font, double r, double g, double b) { glColor3f(r, g, b); glRasterPos2f(x, y); char s[100]; sprintf_s(s, "x = %.2lf\ny = %.2lf\nz = %.2lf", CameraPosition.x, CameraPosition.y, CameraPosition.z); glutBitmapString(font, (const unsigned char*)s); } /*--------------------------------------------------*/ void createCoordinates() { coordinateSystem.resize(4); coordinateSystem[0] = vec3(0.0, 0.0, 0.0); coordinateSystem[1] = vec3(1.0, 0.0, 0.0); coordinateSystem[2] = vec3(0.0, 1.0, 0.0); coordinateSystem[3] = vec3(0.0, 0.0, 1.0); mat4 MT; MT = translate(vec3(0.0, -0.75, 0.0)); coordinateSystem = MT * coordinateSystem; } void drawCoordinates() { glLineWidth(2.0); glBegin(GL_LINES); // X axis glColor3f(1.0f, 0.0f, 0.0f); // Red glVertex3d(coordinateSystem[0].x, coordinateSystem[0].y, coordinateSystem[0].z); glVertex3d(coordinateSystem[1].x, coordinateSystem[1].y, coordinateSystem[1].z); // Y axis glColor3f(0.0f, 1.0f, 0.0f); // Green glVertex3d(coordinateSystem[0].x, coordinateSystem[0].y, coordinateSystem[0].z); glVertex3d(coordinateSystem[2].x, coordinateSystem[2].y, coordinateSystem[2].z); // Z axis glColor3f(0.0f, 0.0f, 1.0f); // Blue glVertex3d(coordinateSystem[0].x, coordinateSystem[0].y, coordinateSystem[0].z); glVertex3d(coordinateSystem[3].x, coordinateSystem[3].y, coordinateSystem[3].z); glEnd(); } vector FormMirror(float rad) { vector vertices = {}; int numOfLines = 6; for (int i = 0; i < numOfLines; i++) { vertices.push_back(vec3(0, 0, 0)); // back vertices.push_back(vec3(rad*cos(i * 2 * PI / numOfLines), rad*sin(i * 2 * PI / numOfLines), 0)); vertices.push_back(vec3(rad*cos((i+1) * 2 * PI / numOfLines), rad*sin((i+1) * 2 * PI / numOfLines), 0)); vertices.push_back(vec3(0, 0, 0.1)); // front vertices.push_back(vec3(rad*cos(i * 2 * PI / numOfLines), rad*sin(i * 2 * PI / numOfLines), 0.1)); vertices.push_back(vec3(rad*cos((i + 1) * 2 * PI / numOfLines), rad*sin((i + 1) * 2 * PI / numOfLines), 0.1)); vertices.push_back(vec3(rad*cos(i * 2 * PI / numOfLines), rad*sin(i * 2 * PI / numOfLines), 0)); vertices.push_back(vec3(rad*cos(i * 2 * PI / numOfLines), rad*sin(i * 2 * PI / numOfLines), 0.1)); vertices.push_back(vec3(rad*cos((i + 1) * 2 * PI / numOfLines), rad*sin((i + 1) * 2 * PI / numOfLines), 0)); vertices.push_back(vec3(rad*cos((i+1) * 2 * PI / numOfLines), rad*sin((i+1) * 2 * PI / numOfLines), 0)); vertices.push_back(vec3(rad*cos(i * 2 * PI / numOfLines), rad*sin(i * 2 * PI / numOfLines), 0.1)); vertices.push_back(vec3(rad*cos((i + 1) * 2 * PI / numOfLines), rad*sin((i + 1) * 2 * PI / numOfLines), 0.1)); } return vertices; } void DrawVertices(vector verts, float r, float g, float b) { glColor3f(r,g,b); glBegin(GL_TRIANGLES); for (auto v : verts) { glVertex3f(v.x, v.y, v.z); } glEnd(); } void FormFullMirror() { vector verts = {}; mat4x4 final; vector mirrorF; verts = FormMirror(0.5); // center DrawVertices(verts, 0, 0, 0); verts = FormMirror(0.5); // inner final = translate(ind, vec3(0.8, 0.45, 0)); mirrorF = final * verts; DrawVertices(mirrorF, 0.8, 0.8, 0); verts = FormMirror(0.5); final = translate(ind, vec3(-0.8, 0.45, 0)); mirrorF = final * verts; DrawVertices(mirrorF, 0.8, 0.8, 0); verts = FormMirror(0.5); final = translate(ind, vec3(0.8, -0.45, 0)); mirrorF = final * verts; DrawVertices(mirrorF, 0.8, 0.8, 0); verts = FormMirror(0.5); final = translate(ind, vec3(-0.8, -0.45, 0)); mirrorF = final * verts; DrawVertices(mirrorF, 0.8, 0.8, 0); verts = FormMirror(0.5); final = translate(ind, vec3(0, 0.9, 0)); mirrorF = final * verts; DrawVertices(mirrorF, 0.8, 0.8, 0); verts = FormMirror(0.5); final = translate(ind, vec3(0, -0.9, 0)); mirrorF = final * verts; DrawVertices(mirrorF, 0.8, 0.8, 0); verts = FormMirror(0.5); // outter final = translate(ind, vec3(1.6, 0, 0)); mirrorF = final * verts; DrawVertices(mirrorF, 0.8, 0.8, 0); verts = FormMirror(0.5); final = translate(ind, vec3(-1.6, 0, 0)); mirrorF = final * verts; DrawVertices(mirrorF, 0.8, 0.8, 0); verts = FormMirror(0.5); final = translate(ind, vec3(1.6, 0.9, 0)); mirrorF = final * verts; DrawVertices(mirrorF, 0.8, 0.8, 0); verts = FormMirror(0.5); final = translate(ind, vec3(1.6, -0.9, 0)); mirrorF = final * verts; DrawVertices(mirrorF, 0.8, 0.8, 0); verts = FormMirror(0.5); final = translate(ind, vec3(-1.6, 0.9, 0)); mirrorF = final * verts; DrawVertices(mirrorF, 0.8, 0.8, 0); verts = FormMirror(0.5); final = translate(ind, vec3(-1.6, -0.9, 0)); mirrorF = final * verts; DrawVertices(mirrorF, 0.8, 0.8, 0); verts = FormMirror(0.5); final = translate(ind, vec3(0, 1.8, 0)); mirrorF = final * verts; DrawVertices(mirrorF, 0.8, 0.8, 0); verts = FormMirror(0.5); final = translate(ind, vec3(0, -1.8, 0)); mirrorF = final * verts; DrawVertices(mirrorF, 0.8, 0.8, 0); verts = FormMirror(0.5); final = translate(ind, vec3(0.8, 1.35, 0)); mirrorF = final * verts; DrawVertices(mirrorF, 0.8, 0.8, 0); verts = FormMirror(0.5); final = translate(ind, vec3(0.8, -1.35, 0)); mirrorF = final * verts; DrawVertices(mirrorF, 0.8, 0.8, 0); verts = FormMirror(0.5); final = translate(ind, vec3(-0.8, 1.35, 0)); mirrorF = final * verts; DrawVertices(mirrorF, 0.8, 0.8, 0); verts = FormMirror(0.5); final = translate(ind, vec3(-0.8, -1.35, 0)); mirrorF = final * verts; DrawVertices(mirrorF, 0.8, 0.8, 0); verts = FormMirror(0.6); // outter black final = translate(ind, vec3(1.6, 0, 0.1)); mirrorF = final * verts; DrawVertices(mirrorF, 0, 0, 0); verts = FormMirror(0.6); final = translate(ind, vec3(-1.6, 0, 0.1)); mirrorF = final * verts; DrawVertices(mirrorF, 0, 0, 0); verts = FormMirror(0.6); final = translate(ind, vec3(1.6, 0.9, 0.1)); mirrorF = final * verts; DrawVertices(mirrorF, 0, 0, 0); verts = FormMirror(0.6); final = translate(ind, vec3(1.6, -0.9, 0.1)); mirrorF = final * verts; DrawVertices(mirrorF, 0, 0, 0); verts = FormMirror(0.6); final = translate(ind, vec3(-1.6, 0.9, 0.1)); mirrorF = final * verts; DrawVertices(mirrorF, 0, 0, 0); verts = FormMirror(0.6); final = translate(ind, vec3(-1.6, -0.9, 0.1)); mirrorF = final * verts; DrawVertices(mirrorF, 0, 0, 0); verts = FormMirror(0.6); final = translate(ind, vec3(0, 1.8, 0.1)); mirrorF = final * verts; DrawVertices(mirrorF, 0, 0, 0); verts = FormMirror(0.6); final = translate(ind, vec3(0, -1.8, 0.1)); mirrorF = final * verts; DrawVertices(mirrorF, 0, 0, 0); verts = FormMirror(0.6); final = translate(ind, vec3(0.8, 1.35, 0.1)); mirrorF = final * verts; DrawVertices(mirrorF, 0, 0, 0); verts = FormMirror(0.6); final = translate(ind, vec3(0.8, -1.35, 0.1)); mirrorF = final * verts; DrawVertices(mirrorF, 0, 0, 0); verts = FormMirror(0.6); final = translate(ind, vec3(-0.8, 1.35, 0.1)); mirrorF = final * verts; DrawVertices(mirrorF, 0, 0, 0); verts = FormMirror(0.6); final = translate(ind, vec3(-0.8, -1.35, 0.1)); mirrorF = final * verts; DrawVertices(mirrorF, 0, 0, 0); verts = FormMirror(0.6); // inner black final = translate(ind, vec3(0.8, 0.45, 0.1)); mirrorF = final * verts; DrawVertices(mirrorF, 0, 0, 0); verts = FormMirror(0.6); final = translate(ind, vec3(-0.8, 0.45, 0.1)); mirrorF = final * verts; DrawVertices(mirrorF, 0, 0, 0); verts = FormMirror(0.6); final = translate(ind, vec3(0.8, -0.45, 0.1)); mirrorF = final * verts; DrawVertices(mirrorF, 0, 0, 0); verts = FormMirror(0.6); final = translate(ind, vec3(-0.8, -0.45, 0.1)); mirrorF = final * verts; DrawVertices(mirrorF, 0, 0, 0); verts = FormMirror(0.6); final = translate(ind, vec3(0, 0.9, 0.1)); mirrorF = final * verts; DrawVertices(mirrorF, 0, 0, 0); verts = FormMirror(0.6); final = translate(ind, vec3(0, -0.9, 0.1)); mirrorF = final * verts; DrawVertices(mirrorF, 0, 0, 0); } vector FormFront(float bot, float top) { vector vertices = {}; int numOfLines = 6; for (int i = 0; i < numOfLines; i++) { vertices.push_back(vec3(0, 0, 0)); // back vertices.push_back(vec3(bot*cos(i * 2 * PI / numOfLines), bot*sin(i * 2 * PI / numOfLines), 0)); vertices.push_back(vec3(bot*cos((i + 1) * 2 * PI / numOfLines), bot*sin((i + 1) * 2 * PI / numOfLines), 0)); vertices.push_back(vec3(0, 0, -0.5)); // front vertices.push_back(vec3(top*cos(i * 2 * PI / numOfLines), top*sin(i * 2 * PI / numOfLines), -0.5)); vertices.push_back(vec3(top*cos((i + 1) * 2 * PI / numOfLines), top*sin((i + 1) * 2 * PI / numOfLines), -0.5)); vertices.push_back(vec3(bot*cos(i * 2 * PI / numOfLines), bot*sin(i * 2 * PI / numOfLines), 0)); vertices.push_back(vec3(top*cos(i * 2 * PI / numOfLines), top*sin(i * 2 * PI / numOfLines), -0.5)); vertices.push_back(vec3(bot*cos((i + 1) * 2 * PI / numOfLines), bot*sin((i + 1) * 2 * PI / numOfLines), 0)); vertices.push_back(vec3(bot*cos((i + 1) * 2 * PI / numOfLines), bot*sin((i + 1) * 2 * PI / numOfLines), 0)); vertices.push_back(vec3(top*cos(i * 2 * PI / numOfLines), top*sin(i * 2 * PI / numOfLines), -0.5)); vertices.push_back(vec3(top*cos((i + 1) * 2 * PI / numOfLines), top*sin((i + 1) * 2 * PI / numOfLines), -0.5)); } return vertices; } vector FromSolarSails(float rad) { vector vertices = {}; int numOfLines = 6; for (int i = 0; i < numOfLines; i++) { vertices.push_back(vec3(0, 0, 0)); // back vertices.push_back(vec3(rad*cos(i * 2 * PI / numOfLines),0, rad*sin(i * 2 * PI / numOfLines))); vertices.push_back(vec3(rad*cos((i + 1) * 2 * PI / numOfLines),0, rad*sin((i + 1) * 2 * PI / numOfLines))); vertices.push_back(vec3(0, 0, 0.1)); // front vertices.push_back(vec3(rad*cos(i * 2 * PI / numOfLines),0.1, rad*sin(i * 2 * PI / numOfLines))); vertices.push_back(vec3(rad*cos((i + 1) * 2 * PI / numOfLines),0.1, rad*sin((i + 1) * 2 * PI / numOfLines))); vertices.push_back(vec3(rad*cos(i * 2 * PI / numOfLines),0, rad*sin(i * 2 * PI / numOfLines))); vertices.push_back(vec3(rad*cos(i * 2 * PI / numOfLines),0.1, rad*sin(i * 2 * PI / numOfLines))); vertices.push_back(vec3(rad*cos((i + 1) * 2 * PI / numOfLines),0, rad*sin((i + 1) * 2 * PI / numOfLines))); vertices.push_back(vec3(rad*cos((i + 1) * 2 * PI / numOfLines),0, rad*sin((i + 1) * 2 * PI / numOfLines))); vertices.push_back(vec3(rad*cos(i * 2 * PI / numOfLines),0.1, rad*sin(i * 2 * PI / numOfLines))); vertices.push_back(vec3(rad*cos((i + 1) * 2 * PI / numOfLines),0.1, rad*sin((i + 1) * 2 * PI / numOfLines))); } return vertices; } vector FormSolarSails1(float rad) { vector vertices = {}; vertices.push_back(vec3(0.5, 0, rad)); vertices.push_back(vec3(0.5, 0, -rad)); vertices.push_back(vec3(rad+0.5, 0, 0)); vertices.push_back(vec3(-0.5, 0, rad)); vertices.push_back(vec3(-0.5, 0, -rad)); vertices.push_back(vec3(-rad-0.5, 0, 0)); vertices.push_back(vec3(0.5, 0, rad)); vertices.push_back(vec3(0.5, 0, -rad)); vertices.push_back(vec3(-0.5, 0, -rad)); vertices.push_back(vec3(-0.5, 0, -rad)); vertices.push_back(vec3(-0.5, 0, rad)); vertices.push_back(vec3(0.5, 0, rad)); return vertices; } vector FromStand(float rad) { vector vertices = {}; int numOfLines = 3; for (int i = 0; i < numOfLines; i++) { vertices.push_back(vec3(0, 0, 0)); // bot vertices.push_back(vec3(rad*cos(i * 2 * PI / numOfLines),0, rad*sin(i * 2 * PI / numOfLines))); vertices.push_back(vec3(rad*cos((i + 1) * 2 * PI / numOfLines),0, rad*sin((i + 1) * 2 * PI / numOfLines))); vertices.push_back(vec3(0, 3, 0)); // top vertices.push_back(vec3(rad*cos(i * 2 * PI / numOfLines),3 , rad*sin(i * 2 * PI / numOfLines))); vertices.push_back(vec3(rad*cos((i + 1) * 2 * PI / numOfLines),3 , rad*sin((i + 1) * 2 * PI / numOfLines))); vertices.push_back(vec3(rad*cos(i * 2 * PI / numOfLines),0, rad*sin(i * 2 * PI / numOfLines))); vertices.push_back(vec3(rad*cos(i * 2 * PI / numOfLines),3, rad*sin(i * 2 * PI / numOfLines))); vertices.push_back(vec3(rad*cos((i + 1) * 2 * PI / numOfLines), 0, rad*sin((i + 1) * 2 * PI / numOfLines))); vertices.push_back(vec3(rad*cos((i + 1) * 2 * PI / numOfLines),0, rad*sin((i + 1) * 2 * PI / numOfLines))); vertices.push_back(vec3(rad*cos(i * 2 * PI / numOfLines),3, rad*sin(i * 2 * PI / numOfLines))); vertices.push_back(vec3(rad*cos((i + 1) * 2 * PI / numOfLines),3, rad*sin((i + 1) * 2 * PI / numOfLines))); } return vertices; } void display(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(80.f, 16.f / 9.f, 0.1f, 50.f); gluLookAt( CameraPosition.x, CameraPosition.y, CameraPosition.z, LookAt_vector.x, LookAt_vector.y, LookAt_vector.z, LookUp_vector.x, LookUp_vector.y, LookUp_vector.z ); drawCoordinates(); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); //glMatrixMode(GL_PROJECTION); //glLoadIdentity(); FormFullMirror(); vector front1 = FormFront(0.35, 0.2); DrawVertices(front1, 0.3,0.2,0); front1 = FormMirror(0.35); vector frontF = translate(ind, vec3(0, 0, -3.5)) * front1; DrawVertices(frontF, 0,0,0); vector behind = FormMirror(2.5); vector behindF = translate(ind, vec3(0, 0, 0.3)) * behind; DrawVertices(behindF, 0.8,0.8,0.8); vector Sail = FormSolarSails1(3.5); vector SailF = translate(ind, vec3(0, -2.5, 0)) * Sail; DrawVertices(SailF, 0.5, 0.5, 0.5); Sail = FormSolarSails1(3.5); SailF = translate(ind, vec3(0, -2.7, 0)) * Sail; DrawVertices(SailF, 0.4, 0.4, 0.4); Sail = FormSolarSails1(3.5); SailF = translate(ind, vec3(0, -2.9, 0)) * Sail; DrawVertices(SailF, 0.3, 0.3, 0.3); Sail = FormSolarSails1(3.5); SailF = translate(ind, vec3(0, -3.1, 0)) * Sail; DrawVertices(SailF, 0.2, 0, 0.2); vector stand = FromStand(0.3); vector standF = translate(ind, vec3(0, -3, 0.3)) * stand; DrawVertices(standF, 0, 0, 0); glBegin(GL_QUADS); glVertex3f(-0.02, 2.3, 0); glVertex3f(0.02, 2.3, 0); glVertex3f(-0.02, 0.3, -3.5); glVertex3f(0.02, 0.3, -3.5); glEnd(); glBegin(GL_QUADS); glVertex3f(2.02, -1.12, 0); glVertex3f(1.98, -1.08, 0); glVertex3f(0.32, 0.02, -3.5); glVertex3f(0.28, -0.02, -3.5); glEnd(); glBegin(GL_QUADS); glVertex3f(-2.02, -1.12, 0); glVertex3f(-1.98, -1.08, 0); glVertex3f(-0.32, 0.02, -3.5); glVertex3f(-0.28, -0.02, -3.5); glEnd(); glutSwapBuffers(); } void timer(int v) { glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt( CameraPosition.x, CameraPosition.y, CameraPosition.z, LookAt_vector.x, LookAt_vector.y, LookAt_vector.z, LookUp_vector.x, LookUp_vector.y, LookUp_vector.z ); glutTimerFunc(1000 / FPS, timer, v); glutPostRedisplay(); } void reshape(GLsizei width, GLsizei height) { if (height * ratio <= width) width = ratio * height; else height = width / ratio; glViewport(0, 0, width, height); } void PrintVector(vec3 vec) { printf("%.2f %.2f %.2f\n", vec.x, vec.y, vec.z); } void MoveForward() { mat4x4 mt; vec3 v = LookAt_vector - CameraPosition; v = normalize(v); v.y = 0.f; v = v * (currentSpeed * (float)MOVING_CONST); mt = translate(mat4x4(1.f), v); LookAt_vector = mt * LookAt_vector; CameraPosition = mt * CameraPosition; } void MoveBackward() { mat4x4 mt; vec3 v = LookAt_vector - CameraPosition; v.y = 0.f; v = normalize(v); v = -v * (currentSpeed * (float)MOVING_CONST); mt = translate(mat4x4(1.f), v); LookAt_vector = mt * LookAt_vector; CameraPosition = mt * CameraPosition; } void MoveLeft() { mat4x4 mt; vec3 f = LookAt_vector - CameraPosition; vec3 w = cross(LookUp_vector, f); w = normalize(w); w = w * (currentSpeed * (float)MOVING_CONST); mt = translate(mat4x4(1.f), w); CameraPosition = mt * CameraPosition; LookAt_vector = mt * LookAt_vector; } void MoveRight() { mat4x4 mt; vec3 f = LookAt_vector - CameraPosition; vec3 w = cross(LookUp_vector, f); w = normalize(w); w = -w * (currentSpeed * (float)MOVING_CONST); mt = translate(mat4x4(1.f), w); CameraPosition = mt * CameraPosition; LookAt_vector = mt * LookAt_vector; } void TurnLeft() { mat4x4 mt, identityMat, mt1, mt2, mtr; identityMat = mat4x4(1.f); mt1 = translate(identityMat, vec3(CameraPosition.x, CameraPosition.y, CameraPosition.z)); mtr = rotate(identityMat, ROTATION_CONST, vec3(0.f, 1.f, 0.f)); mt2 = translate(identityMat, vec3(-CameraPosition.x, -CameraPosition.y, -CameraPosition.z)); mt = mt1 * mtr * mt2; LookAt_vector = mt * LookAt_vector; arrowRotate += ROTATION_CONST; } void TurnRight() { mat4x4 mt, identityMat, mt1, mt2, mtr; identityMat = mat4x4(1.f); mt1 = translate(identityMat, vec3(CameraPosition.x, CameraPosition.y, CameraPosition.z)); mtr = rotate(identityMat, -ROTATION_CONST, vec3(0.f, 1.f, 0.f)); mt2 = translate(identityMat, vec3(-CameraPosition.x, -CameraPosition.y, -CameraPosition.z)); mt = mt1 * mtr * mt2; LookAt_vector = mt * LookAt_vector; arrowRotate -= ROTATION_CONST; } void TurnUp() { mat4x4 mt, mt1, mt2, mtr; vec3 f = LookAt_vector - CameraPosition; vec3 w = cross(f, LookUp_vector); w = normalize(w); if (upDownAngle + ROTATION_CONST < (float)M_PI_2) { mt1 = transpose(translate(mat4x4(1.f), vec3(-CameraPosition.x, -CameraPosition.y, -CameraPosition.z))); mtr = rotate(mat4x4(1.f), ROTATION_CONST, w); mt2 = transpose(translate(mat4x4(1.f), vec3(CameraPosition.x, CameraPosition.y, CameraPosition.z))); mt = mt2 * mtr * mt1; LookAt_vector = mt * LookAt_vector; //LookUp_vector = mt * LookUp_vector; upDownAngle += ROTATION_CONST; } } void TurnDown() { mat4x4 mt, mt1, mt2, mtr; vec3 f = LookAt_vector - CameraPosition; vec3 w = cross(f, LookUp_vector); w = normalize(w); if (upDownAngle - ROTATION_CONST > (float)-M_PI_2) { mt1 = transpose(translate(mat4x4(1.f), vec3(-CameraPosition.x, -CameraPosition.y, -CameraPosition.z))); mtr = rotate(mat4x4(1.f), -ROTATION_CONST, w); mt2 = transpose(translate(mat4x4(1.f), vec3(CameraPosition.x, CameraPosition.y, CameraPosition.z))); mt = mt2 * mtr * mt1; LookAt_vector = mt * LookAt_vector; //LookUp_vector = mt * LookUp_vector; upDownAngle -= ROTATION_CONST; } } void SpeedUp() { if (currentSpeed < 5) ++currentSpeed; } void SpeedDown() { if (currentSpeed > 0) --currentSpeed; } void initGL(void) { glClearColor(1.0f, 1.0f, 1.0f, 1.0f); glShadeModel(GL_FLAT); glEnable(GL_DEPTH_TEST); } void mousePress(int button, int state, int x, int y) { switch (button) { case GLUT_LEFT_BUTTON: if (state == GLUT_DOWN) { //FUNKCIJA } break; case GLUT_RIGHT_BUTTON: if (state == GLUT_DOWN) { //FUNKCIJA } break; default: break; } } void keyPress(unsigned char key, int x, int y) { switch (key) { case 27: //ESC key exit(0); break; case 'w': MoveForward(); break; case 's': MoveBackward(); break; case 'a': //FUNCTION MoveLeft(); break; case 'd': //FUNCTION MoveRight(); break; case 'u': SpeedUp(); break; case 'j': SpeedDown(); break; case 52: TurnLeft(); break; case 54: TurnRight(); break; case 50: TurnDown(); break; case 56: TurnUp(); break; } } /*--------------------------------------------------*/ int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH | GLUT_STENCIL); glutInitWindowSize(height * ratio, height); glutInitWindowPosition(150, 50); glutCreateWindow(title); createCoordinates(); glutDisplayFunc(display); glutTimerFunc(100, timer, 0); glutReshapeFunc(reshape); glutMouseFunc(mousePress); glutKeyboardFunc(keyPress); initGL(); glutMainLoop(); return 0; }