41 #include "glCompiler.h" |
41 #include "glCompiler.h" |
42 #include "primitives.h" |
42 #include "primitives.h" |
43 #include "documentmanager.h" |
43 #include "documentmanager.h" |
44 #include "grid.h" |
44 #include "grid.h" |
45 |
45 |
46 const LDFixedCamera g_FixedCameras[6] = |
46 const CameraInfo g_cameraInfo[NumCameras] = |
47 { |
47 { |
48 {{ 1, 0, 0 }, X, Z, false, false, false }, // top |
48 {{ 1, 0, 0 }, X, Z, false, false, false }, // top |
49 {{ 0, 0, 0 }, X, Y, false, true, false }, // front |
49 {{ 0, 0, 0 }, X, Y, false, true, false }, // front |
50 {{ 0, 1, 0 }, Z, Y, true, true, false }, // left |
50 {{ 0, 1, 0 }, Z, Y, true, true, false }, // left |
51 {{ -1, 0, 0 }, X, Z, false, true, true }, // bottom |
51 {{ -1, 0, 0 }, X, Z, false, true, true }, // bottom |
52 {{ 0, 0, 0 }, X, Y, true, true, true }, // back |
52 {{ 0, 0, 0 }, X, Y, true, true, true }, // back |
53 {{ 0, -1, 0 }, Z, Y, false, true, true }, // right |
53 {{ 0, -1, 0 }, Z, Y, false, true, true }, // right |
|
54 {{ 1, 0, 0 }, X, Z, false, false, false }, // free (defensive dummy data) |
54 }; |
55 }; |
55 |
56 |
56 ConfigOption (QColor BackgroundColor = "#FFFFFF") |
57 ConfigOption (QColor BackgroundColor = "#FFFFFF") |
57 ConfigOption (QColor MainColor = "#A0A0A0") |
58 ConfigOption (QColor MainColor = "#A0A0A0") |
58 ConfigOption (float MainColorAlpha = 1.0) |
59 ConfigOption (float MainColorAlpha = 1.0) |
97 m_thinBorderPen.setWidth (1); |
98 m_thinBorderPen.setWidth (1); |
98 setAcceptDrops (true); |
99 setAcceptDrops (true); |
99 connect (m_toolTipTimer, SIGNAL (timeout()), this, SLOT (slot_toolTipTimer())); |
100 connect (m_toolTipTimer, SIGNAL (timeout()), this, SLOT (slot_toolTipTimer())); |
100 |
101 |
101 // Init camera icons |
102 // Init camera icons |
102 for (Camera cam = EFirstCamera; cam < ENumCameras; ++cam) |
103 for (Camera cam = EFirstCamera; cam < NumCameras; ++cam) |
103 { |
104 { |
104 const char* cameraIconNames[ENumCameras] = |
105 const char* cameraIconNames[NumCameras] = |
105 { |
106 { |
106 "camera-top", "camera-front", "camera-left", |
107 "camera-top", "camera-front", "camera-left", |
107 "camera-bottom", "camera-back", "camera-right", |
108 "camera-bottom", "camera-back", "camera-right", |
108 "camera-free" |
109 "camera-free" |
109 }; |
110 }; |
139 int i = 0; |
140 int i = 0; |
140 |
141 |
141 for (CameraIcon& info : m_cameraIcons) |
142 for (CameraIcon& info : m_cameraIcons) |
142 { |
143 { |
143 // MATH |
144 // MATH |
144 int x1 = (m_width - (info.camera != EFreeCamera ? 48 : 16)) + ((i % 3) * 16) - 1; |
145 int x1 = (m_width - (info.camera != FreeCamera ? 48 : 16)) + ((i % 3) * 16) - 1; |
145 int y1 = ((i / 3) * 16) + 1; |
146 int y1 = ((i / 3) * 16) + 1; |
146 |
147 |
147 info.sourceRect = QRect (0, 0, 16, 16); |
148 info.sourceRect = QRect (0, 0, 16, 16); |
148 info.targetRect = QRect (x1, y1, 16, 16); |
149 info.targetRect = QRect (x1, y1, 16, 16); |
149 info.hitRect = QRect ( |
150 info.hitRect = QRect ( |
391 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE); |
392 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE); |
392 |
393 |
393 glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
394 glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
394 glEnable (GL_DEPTH_TEST); |
395 glEnable (GL_DEPTH_TEST); |
395 |
396 |
396 if (camera() != EFreeCamera) |
397 if (camera() != FreeCamera) |
397 { |
398 { |
398 glMatrixMode (GL_PROJECTION); |
399 glMatrixMode (GL_PROJECTION); |
399 glPushMatrix(); |
400 glPushMatrix(); |
400 |
401 |
401 glLoadIdentity(); |
402 glLoadIdentity(); |
402 glOrtho (-m_virtualWidth, m_virtualWidth, -m_virtualHeight, m_virtualHeight, -100.0f, 100.0f); |
403 glOrtho (-m_virtualWidth, m_virtualWidth, -m_virtualHeight, m_virtualHeight, -100.0f, 100.0f); |
403 glTranslatef (panning (X), panning (Y), 0.0f); |
404 glTranslatef (panning (X), panning (Y), 0.0f); |
404 |
405 |
405 if (camera() != EFrontCamera and camera() != EBackCamera) |
406 if (camera() != FrontCamera and camera() != BackCamera) |
406 { |
407 { |
407 glRotatef (90.0f, g_FixedCameras[camera()].glrotate[0], |
408 glRotatef (90.0f, g_cameraInfo[camera()].glrotate[0], |
408 g_FixedCameras[camera()].glrotate[1], |
409 g_cameraInfo[camera()].glrotate[1], |
409 g_FixedCameras[camera()].glrotate[2]); |
410 g_cameraInfo[camera()].glrotate[2]); |
410 } |
411 } |
411 |
412 |
412 // Back camera needs to be handled differently |
413 // Back camera needs to be handled differently |
413 if (camera() == EBackCamera) |
414 if (camera() == BackCamera) |
414 { |
415 { |
415 glRotatef (180.0f, 1.0f, 0.0f, 0.0f); |
416 glRotatef (180.0f, 1.0f, 0.0f, 0.0f); |
416 glRotatef (180.0f, 0.0f, 0.0f, 1.0f); |
417 glRotatef (180.0f, 0.0f, 0.0f, 1.0f); |
417 } |
418 } |
418 } |
419 } |
529 // This converts a 2D point on the screen to a 3D point in the model. If 'snap' |
530 // This converts a 2D point on the screen to a 3D point in the model. If 'snap' |
530 // is true, the 3D point will snap to the current grid. |
531 // is true, the 3D point will snap to the current grid. |
531 // |
532 // |
532 Vertex GLRenderer::convert2dTo3d (const QPoint& pos2d, bool snap) const |
533 Vertex GLRenderer::convert2dTo3d (const QPoint& pos2d, bool snap) const |
533 { |
534 { |
534 if (camera() == EFreeCamera) |
535 if (camera() == FreeCamera) |
535 return Origin; |
536 return Origin; |
536 |
537 |
537 Vertex pos3d; |
538 Vertex pos3d; |
538 const LDFixedCamera* cam = &g_FixedCameras[camera()]; |
539 const CameraInfo* cam = &g_cameraInfo[camera()]; |
539 Axis axisX = cam->localX; |
540 Axis axisX = cam->localX; |
540 Axis axisY = cam->localY; |
541 Axis axisY = cam->localY; |
541 int signX = cam->negatedX ? -1 : 1; |
542 int signX = cam->negatedX ? -1 : 1; |
542 int signY = cam->negatedY ? -1 : 1; |
543 int signY = cam->negatedY ? -1 : 1; |
543 |
544 |
569 // Inverse operation for the above - convert a 3D position to a 2D screen position. Don't ask me how this code manages |
570 // Inverse operation for the above - convert a 3D position to a 2D screen position. Don't ask me how this code manages |
570 // to work, I don't even know. |
571 // to work, I don't even know. |
571 // |
572 // |
572 QPoint GLRenderer::convert3dTo2d (const Vertex& pos3d) |
573 QPoint GLRenderer::convert3dTo2d (const Vertex& pos3d) |
573 { |
574 { |
574 if (camera() == EFreeCamera) |
575 if (camera() == FreeCamera) |
575 return QPoint (0, 0); |
576 return QPoint (0, 0); |
576 |
577 |
577 const LDFixedCamera* cam = &g_FixedCameras[camera()]; |
578 const CameraInfo* cam = &g_cameraInfo[camera()]; |
578 const Axis axisX = cam->localX; |
579 const Axis axisX = cam->localX; |
579 const Axis axisY = cam->localY; |
580 const Axis axisY = cam->localY; |
580 const int negXFac = cam->negatedX ? -1 : 1; |
581 const int negXFac = cam->negatedX ? -1 : 1; |
581 const int negYFac = cam->negatedY ? -1 : 1; |
582 const int negYFac = cam->negatedY ? -1 : 1; |
582 GLfloat matrix[16]; |
583 GLfloat matrix[16]; |
636 painter.drawText ((width() - textSize.width()) / 2, height() - textSize.height(), textSize.width(), |
637 painter.drawText ((width() - textSize.width()) / 2, height() - textSize.height(), textSize.width(), |
637 textSize.height(), Qt::AlignCenter, text); |
638 textSize.height(), Qt::AlignCenter, text); |
638 } |
639 } |
639 #endif |
640 #endif |
640 |
641 |
641 if (camera() != EFreeCamera and not isPicking()) |
642 if (camera() != FreeCamera and not isPicking()) |
642 { |
643 { |
643 // Paint the overlay image if we have one |
644 // Paint the overlay image if we have one |
644 const LDGLOverlay& overlay = currentDocumentData().overlays[camera()]; |
645 const LDGLOverlay& overlay = currentDocumentData().overlays[camera()]; |
645 |
646 |
646 if (overlay.image) |
647 if (overlay.image) |
827 panning (X) += 0.03f * dx * (zoom() / 7.5f); |
828 panning (X) += 0.03f * dx * (zoom() / 7.5f); |
828 panning (Y) -= 0.03f * dy * (zoom() / 7.5f); |
829 panning (Y) -= 0.03f * dy * (zoom() / 7.5f); |
829 m_panning = true; |
830 m_panning = true; |
830 m_isCameraMoving = true; |
831 m_isCameraMoving = true; |
831 } |
832 } |
832 else if (left and camera() == EFreeCamera) |
833 else if (left and camera() == FreeCamera) |
833 { |
834 { |
834 rotation (X) = rotation (X) + dy; |
835 rotation (X) = rotation (X) + dy; |
835 rotation (Y) = rotation (Y) + dx; |
836 rotation (Y) = rotation (Y) + dx; |
836 clampAngle (rotation (X)); |
837 clampAngle (rotation (X)); |
837 clampAngle (rotation (Y)); |
838 clampAngle (rotation (Y)); |
1102 |
1103 |
1103 // ============================================================================= |
1104 // ============================================================================= |
1104 // |
1105 // |
1105 void GLRenderer::getRelativeAxes (Axis& relX, Axis& relY) const |
1106 void GLRenderer::getRelativeAxes (Axis& relX, Axis& relY) const |
1106 { |
1107 { |
1107 const LDFixedCamera* cam = &g_FixedCameras[camera()]; |
1108 const CameraInfo* cam = &g_cameraInfo[camera()]; |
1108 relX = cam->localX; |
1109 relX = cam->localX; |
1109 relY = cam->localY; |
1110 relY = cam->localY; |
1110 } |
1111 } |
1111 |
1112 |
1112 // ============================================================================= |
1113 // ============================================================================= |
1113 // |
1114 // |
1114 Axis GLRenderer::getRelativeZ() const |
1115 Axis GLRenderer::getRelativeZ() const |
1115 { |
1116 { |
1116 const LDFixedCamera* cam = &g_FixedCameras[camera()]; |
1117 const CameraInfo* cam = &g_cameraInfo[camera()]; |
1117 return (Axis) (3 - cam->localX - cam->localY); |
1118 return (Axis) (3 - cam->localX - cam->localY); |
1118 } |
1119 } |
1119 |
1120 |
1120 // ============================================================================= |
1121 // ============================================================================= |
1121 // |
1122 // |
1208 else if (info.height == 0) |
1209 else if (info.height == 0) |
1209 info.height = (info.width * image->height()) / image->width(); |
1210 info.height = (info.width * image->height()) / image->width(); |
1210 |
1211 |
1211 Axis localX = getCameraAxis (false, camera); |
1212 Axis localX = getCameraAxis (false, camera); |
1212 Axis localY = getCameraAxis (true, camera); |
1213 Axis localY = getCameraAxis (true, camera); |
1213 int signX = g_FixedCameras[camera].negatedX ? -1 : 1; |
1214 int signX = g_cameraInfo[camera].negatedX ? -1 : 1; |
1214 int signY = g_FixedCameras[camera].negatedY ? -1 : 1; |
1215 int signY = g_cameraInfo[camera].negatedY ? -1 : 1; |
1215 |
1216 |
1216 info.v0 = info.v1 = Origin; |
1217 info.v0 = info.v1 = Origin; |
1217 info.v0.setCoordinate (localX, -(info.offsetX * info.width * signX) / image->width()); |
1218 info.v0.setCoordinate (localX, -(info.offsetX * info.width * signX) / image->width()); |
1218 info.v0.setCoordinate (localY, (info.offsetY * info.height * signY) / image->height()); |
1219 info.v0.setCoordinate (localY, (info.offsetY * info.height * signY) / image->height()); |
1219 info.v1.setCoordinate (localX, info.v0[localX] + info.width); |
1220 info.v1.setCoordinate (localX, info.v0[localX] + info.width); |
1247 |
1248 |
1248 // ============================================================================= |
1249 // ============================================================================= |
1249 // |
1250 // |
1250 void GLRenderer::setDepthValue (double depth) |
1251 void GLRenderer::setDepthValue (double depth) |
1251 { |
1252 { |
1252 if (camera() < EFreeCamera) |
1253 if (camera() < FreeCamera) |
1253 currentDocumentData().depthValues[camera()] = depth; |
1254 currentDocumentData().depthValues[camera()] = depth; |
1254 } |
1255 } |
1255 |
1256 |
1256 // ============================================================================= |
1257 // ============================================================================= |
1257 // |
1258 // |
1258 double GLRenderer::getDepthValue() const |
1259 double GLRenderer::getDepthValue() const |
1259 { |
1260 { |
1260 if (camera() < EFreeCamera) |
1261 if (camera() < FreeCamera) |
1261 return currentDocumentData().depthValues[camera()]; |
1262 return currentDocumentData().depthValues[camera()]; |
1262 else |
1263 else |
1263 return 0.0; |
1264 return 0.0; |
1264 } |
1265 } |
1265 |
1266 |
1267 // |
1268 // |
1268 QString GLRenderer::cameraName (Camera camera) const |
1269 QString GLRenderer::cameraName (Camera camera) const |
1269 { |
1270 { |
1270 switch (camera) |
1271 switch (camera) |
1271 { |
1272 { |
1272 case ETopCamera: return tr ("Top Camera"); |
1273 case TopCamera: return tr ("Top Camera"); |
1273 case EFrontCamera: return tr ("Front Camera"); |
1274 case FrontCamera: return tr ("Front Camera"); |
1274 case ELeftCamera: return tr ("Left Camera"); |
1275 case LeftCamera: return tr ("Left Camera"); |
1275 case EBottomCamera: return tr ("Bottom Camera"); |
1276 case BottomCamera: return tr ("Bottom Camera"); |
1276 case EBackCamera: return tr ("Back Camera"); |
1277 case BackCamera: return tr ("Back Camera"); |
1277 case ERightCamera: return tr ("Right Camera"); |
1278 case RightCamera: return tr ("Right Camera"); |
1278 case EFreeCamera: return tr ("Free Camera"); |
1279 case FreeCamera: return tr ("Free Camera"); |
1279 default: break; |
1280 default: break; |
1280 } |
1281 } |
1281 |
1282 |
1282 return ""; |
1283 return ""; |
1283 } |
1284 } |
1602 Vertex const& GLRenderer::position3D() const |
1603 Vertex const& GLRenderer::position3D() const |
1603 { |
1604 { |
1604 return m_position3D; |
1605 return m_position3D; |
1605 } |
1606 } |
1606 |
1607 |
1607 const LDFixedCamera& GLRenderer::cameraInfo (Camera camera) const |
1608 const CameraInfo& GLRenderer::cameraInfo (Camera camera) const |
1608 { |
1609 { |
1609 if (camera >= EFirstCamera and camera <= ELastFixedCamera) |
1610 if (camera >= EFirstCamera and camera <= ELastFixedCamera) |
1610 return g_FixedCameras[camera]; |
1611 return g_cameraInfo[camera]; |
1611 else |
1612 else |
1612 return g_FixedCameras[0]; |
1613 return g_cameraInfo[0]; |
1613 } |
1614 } |
1614 |
1615 |
1615 bool GLRenderer::mouseHasMoved() const |
1616 bool GLRenderer::mouseHasMoved() const |
1616 { |
1617 { |
1617 return m_totalMouseMove >= 10; |
1618 return m_totalMouseMove >= 10; |