src/gl/partrenderer.cpp

changeset 18
918b6c0f8b5b
parent 17
a5111f4e6412
child 21
0133e565e072
equal deleted inserted replaced
17:a5111f4e6412 18:918b6c0f8b5b
17 } 17 }
18 this->initializeLighting(); 18 this->initializeLighting();
19 this->initialized = true; 19 this->initialized = true;
20 this->rotation = QQuaternion::fromAxisAndAngle({1, 0, 0}, 30); 20 this->rotation = QQuaternion::fromAxisAndAngle({1, 0, 0}, 30);
21 this->rotation *= QQuaternion::fromAxisAndAngle({0, 1, 0}, 330); 21 this->rotation *= QQuaternion::fromAxisAndAngle({0, 1, 0}, 330);
22 }
23
24 // https://stackoverflow.com/a/12943456
25 static void perspectiveGL(GLdouble fovY, GLdouble aspect, GLdouble zNear, GLdouble zFar)
26 {
27 //fH = tan( (fovY / 2) / 180 * pi ) * zNear;
28 const GLdouble fH = std::tan(fovY / 360 * pi) * zNear;
29 const GLdouble fW = fH * aspect;
30 glFrustum(-fW, fW, -fH, fH, zNear, zFar);
31 } 22 }
32 23
33 /* 24 /*
34 * Pads a 3×3 matrix into a 4×4 one by adding cells from the identity matrix. 25 * Pads a 3×3 matrix into a 4×4 one by adding cells from the identity matrix.
35 */ 26 */
61 } 52 }
62 53
63 void PartRenderer::resizeGL(int width, int height) 54 void PartRenderer::resizeGL(int width, int height)
64 { 55 {
65 constexpr GLfloat near = 1.0f; 56 constexpr GLfloat near = 1.0f;
66 constexpr GLfloat far = 1.0e+05f; 57 constexpr GLfloat far = 1e+05f;
67 glViewport (0, 0, width, height); 58 glViewport (0, 0, width, height);
68 glMatrixMode(GL_PROJECTION); 59 glMatrixMode(GL_PROJECTION);
69 glLoadIdentity(); 60 glLoadIdentity();
70 ::perspectiveGL(45.0f, static_cast<double>(width) / static_cast<double>(height), near, far); 61 gluPerspective(45.0f, static_cast<double>(width) / static_cast<double>(height), near, far);
71 glMatrixMode(GL_MODELVIEW); 62 glMatrixMode(GL_MODELVIEW);
72 } 63 }
73 64
74 // https://www.codemiles.com/c-opengl-examples/drawing-teapot-using-opengl-t9010.html?mobile=on 65 // https://www.codemiles.com/c-opengl-examples/drawing-teapot-using-opengl-t9010.html?mobile=on
75 void PartRenderer::paintGL() 66 void PartRenderer::paintGL()
76 { 67 {
68 switch (this->renderStyle)
69 {
70 case gl::RenderStyle::Normal:
71 case gl::RenderStyle::BfcRedGreen:
72 case gl::RenderStyle::RandomColors:
73 break;
74 case gl::RenderStyle::Wireframe:
75 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
76 break;
77 }
77 glMatrixMode(GL_MODELVIEW); 78 glMatrixMode(GL_MODELVIEW);
78 // clear the drawing buffer. 79 // clear the drawing buffer.
79 glClear(GL_COLOR_BUFFER_BIT); 80 glClear(GL_COLOR_BUFFER_BIT);
80 // clear the identity matrix. 81 // clear the identity matrix.
81 glLoadIdentity(); 82 glLoadIdentity();
114 this->rotation = versor * this->rotation; 115 this->rotation = versor * this->rotation;
115 this->update(); 116 this->update();
116 } 117 }
117 this->lastMousePosition = pointToPointF(event->pos()); 118 this->lastMousePosition = pointToPointF(event->pos());
118 } 119 }
120
121 void PartRenderer::setRenderStyle(const gl::RenderStyle newStyle)
122 {
123 this->renderStyle = newStyle;
124 this->update();
125 }
126

mercurial