src/glrenderer.cpp

changeset 1151
0eddb5bcf25b
parent 1146
bb728c124d47
child 1157
1d6d244bdabd
equal deleted inserted replaced
1150:262345e53050 1151:0eddb5bcf25b
35 #include "documentmanager.h" 35 #include "documentmanager.h"
36 #include "grid.h" 36 #include "grid.h"
37 37
38 const QPen GLRenderer::thinBorderPen {QColor {0, 0, 0, 208}, 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin}; 38 const QPen GLRenderer::thinBorderPen {QColor {0, 0, 0, 208}, 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin};
39 39
40 // Transformation matrices for the fixed cameras.
41 const GLRotationMatrix GLRenderer::topCameraMatrix = GLRotationMatrix {};
42 const GLRotationMatrix GLRenderer::frontCameraMatrix = {{1, 0, 0, 0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1}};
43 const GLRotationMatrix GLRenderer::leftCameraMatrix = {{0, -1, 0, 0, 0, 0, 1, 0, -1, 0, 0, 0, 0, 0, 0, 1}};
44 const GLRotationMatrix GLRenderer::bottomCameraMatrix = {{1, 0, 0, 0, 0, -1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1}};
45 const GLRotationMatrix GLRenderer::backCameraMatrix = {{-1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1}};
46 const GLRotationMatrix GLRenderer::rightCameraMatrix = {{0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1}};
47
48 // Conversion matrix from LDraw to OpenGL coordinates.
49 const GLRotationMatrix GLRenderer::ldrawToGLAdapterMatrix = {{1, 0, 0, 0, 0, 0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 1}};
50
40 /* 51 /*
41 * Constructs a GL renderer. 52 * Constructs a GL renderer.
42 */ 53 */
43 GLRenderer::GLRenderer(const Model* model, QWidget* parent) : 54 GLRenderer::GLRenderer(const Model* model, QWidget* parent) :
44 QGLWidget {parent}, 55 QGLWidget {parent},
45 HierarchyElement {parent}, 56 HierarchyElement {parent},
46 m_model {model}, 57 m_model {model},
47 m_cameras { 58 m_cameras {
48 {"Top camera", {1, 0, 0, X, Z, false, false, false}}, // top 59 {"Top camera", {topCameraMatrix, X, Z, false, false, false}}, // top
49 {"Front camera", {0, 0, 1, X, Y, false, true, false}}, // front 60 {"Front camera", {frontCameraMatrix, X, Y, false, true, false}}, // front
50 {"Left camera", {0, 1, 0, Z, Y, true, true, false}}, // left 61 {"Left camera", {leftCameraMatrix, Z, Y, true, true, false}}, // left
51 {"Bottom camera", {-1, 0, 0, X, Z, false, true, true}}, // bottom 62 {"Bottom camera", {bottomCameraMatrix, X, Z, false, true, true}}, // bottom
52 {"Back camera", {0, 0, -1, X, Y, true, true, true}}, // back 63 {"Back camera", {backCameraMatrix, X, Y, true, true, true}}, // back
53 {"Right camera", {0, -1, 0, Z, Y, false, true, true}}, // right 64 {"Right camera", {rightCameraMatrix, Z, Y, false, true, true}}, // right
54 {"Free camera", GLCamera::FreeCamera}, // free 65 {"Free camera", GLCamera::FreeCamera}, // free
55 } 66 }
56 { 67 {
57 m_camera = (Camera) m_config->camera(); 68 m_camera = (Camera) m_config->camera();
58 m_compiler = new GLCompiler (this); 69 m_compiler = new GLCompiler (this);
378 389
379 glLoadIdentity(); 390 glLoadIdentity();
380 const QSizeF& virtualSize = currentCamera().virtualSize(); 391 const QSizeF& virtualSize = currentCamera().virtualSize();
381 glOrtho(-virtualSize.width(), virtualSize.width(), -virtualSize.height(), virtualSize.height(), -100.0f, 100.0f); 392 glOrtho(-virtualSize.width(), virtualSize.width(), -virtualSize.height(), virtualSize.height(), -100.0f, 100.0f);
382 glTranslatef(panning (X), panning (Y), 0.0f); 393 glTranslatef(panning (X), panning (Y), 0.0f);
383 394 glMultMatrixf(currentCamera().transformationMatrix());
384 if (camera() != Camera::Front and camera() != Camera::Back) 395 glMultMatrixf(ldrawToGLAdapterMatrix);
385 glRotatef(90.0f, currentCamera().glRotate(X), currentCamera().glRotate(Y), 0);
386
387 // Back camera needs to be handled differently
388 if (camera() == Camera::Back)
389 {
390 glRotatef(180.0f, 1.0f, 0.0f, 0.0f);
391 glRotatef(180.0f, 0.0f, 0.0f, 1.0f);
392 }
393 } 396 }
394 else 397 else
395 { 398 {
396 glMatrixMode(GL_MODELVIEW); 399 glMatrixMode(GL_MODELVIEW);
397 glPushMatrix(); 400 glPushMatrix();

mercurial