src/gl/partrenderer.cpp

changeset 28
c92c1daf735f
parent 27
c57fb7a5ffa3
child 30
1536f23cfab7
equal deleted inserted replaced
27:c57fb7a5ffa3 28:c92c1daf735f
15 * You should have received a copy of the GNU General Public License 15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */ 17 */
18 18
19 #include <GL/glut.h> 19 #include <GL/glut.h>
20 #include <glm/ext/matrix_transform.hpp>
21 #include <glm/ext/matrix_clip_space.hpp>
20 #include <QMouseEvent> 22 #include <QMouseEvent>
21 #include <QMessageBox> 23 #include <QMessageBox>
22 #include "partrenderer.h" 24 #include "partrenderer.h"
23 25
24 PartRenderer::PartRenderer(Model* model, DocumentManager* documents, const ColorTable& colorTable, QWidget* parent) : 26 PartRenderer::PartRenderer(Model* model, DocumentManager* documents, const ColorTable& colorTable, QWidget* parent) :
83 glEnable(GL_DEPTH_TEST); 85 glEnable(GL_DEPTH_TEST);
84 } 86 }
85 87
86 void PartRenderer::resizeGL(int width, int height) 88 void PartRenderer::resizeGL(int width, int height)
87 { 89 {
88 constexpr GLdouble near = 1.0; 90 glViewport(0, 0, width, height);
89 constexpr GLdouble far = 1e+05; 91 this->projectionMatrix = glm::perspective(
90 glViewport (0, 0, width, height); 92 glm::radians(90.0f),
91 glMatrixMode(GL_PROJECTION); 93 static_cast<float>(width) / static_cast<float>(height),
92 glLoadIdentity(); 94 0.1f,
93 gluPerspective(45.0, static_cast<double>(width) / static_cast<double>(height), near, far); 95 100.f);
94 glMatrixMode(GL_MODELVIEW);
95 } 96 }
96 97
97 static GLenum getGlTypeForArrayClass(const gl::ArrayClass vboClass) 98 static GLenum getGlTypeForArrayClass(const gl::ArrayClass vboClass)
98 { 99 {
99 switch (vboClass) 100 switch (vboClass)
147 break; 148 break;
148 case gl::RenderStyle::Wireframe: 149 case gl::RenderStyle::Wireframe:
149 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); 150 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
150 break; 151 break;
151 } 152 }
152 this->compiler->setUniform("CameraTransformation", rotationMatrix); 153 this->compiler->setUniform("CameraTransformation", gl::toQMatrix(this->projectionMatrix * this->viewMatrix));
153 // Lines need to be rendered last so that anti-aliasing does not interfere with polygon rendering. 154 // Lines need to be rendered last so that anti-aliasing does not interfere with polygon rendering.
154 renderVao(gl::ArrayClass::Triangles); 155 renderVao(gl::ArrayClass::Triangles);
155 renderVao(gl::ArrayClass::Quads); 156 renderVao(gl::ArrayClass::Quads);
156 renderVao(gl::ArrayClass::Lines); 157 renderVao(gl::ArrayClass::Lines);
157 glDisable(GL_POLYGON_OFFSET_FILL); 158 glDisable(GL_POLYGON_OFFSET_FILL);
193 const QQuaternion versor = QQuaternion::fromAxisAndAngle( 194 const QQuaternion versor = QQuaternion::fromAxisAndAngle(
194 QVector3D{static_cast<float>(move.y()), static_cast<float>(move.x()), 0.0f}, 195 QVector3D{static_cast<float>(move.y()), static_cast<float>(move.x()), 0.0f},
195 0.6f * static_cast<float>(std::hypot(move.x(), move.y())) 196 0.6f * static_cast<float>(std::hypot(move.x(), move.y()))
196 ); 197 );
197 this->rotation = versor * this->rotation; 198 this->rotation = versor * this->rotation;
199 QVector3D cameraPosition = this->rotation.rotatedVector({0, 0, 4.5});
200 glm::vec3 cameraPosition_glm = {cameraPosition.x(), cameraPosition.y(), cameraPosition.z()};
201 this->viewMatrix = glm::lookAt(cameraPosition_glm, {0, 0, 0}, {0, -1, 0});
198 this->update(); 202 this->update();
199 } 203 }
200 this->lastMousePosition = pointToPointF(event->pos()); 204 this->lastMousePosition = pointToPointF(event->pos());
201 } 205 }
202 206

mercurial