38 |
39 |
39 static const struct staticCameraMeta { |
40 static const struct staticCameraMeta { |
40 const char glrotate[3]; |
41 const char glrotate[3]; |
41 const Axis axisX, axisY; |
42 const Axis axisX, axisY; |
42 const bool negX, negY; |
43 const bool negX, negY; |
43 } g_staticCameras[6] = { { { 1, 0, 0 }, X, Z, false, false }, { { 0, 0, 0 }, X, Y, false, true }, { { 0, 1, 0 }, Z, Y, true, true }, { { -1, 0, 0 }, X, Z, false, true }, { { 0, 0, 0 }, X, Y, true, true }, { { 0, -1, 0 }, Z, Y, false, true }, |
44 } g_staticCameras[6] = { |
|
45 {{ 1, 0, 0 }, X, Z, false, false }, |
|
46 {{ 0, 0, 0 }, X, Y, false, true }, |
|
47 {{ 0, 1, 0 }, Z, Y, true, true }, |
|
48 {{ -1, 0, 0 }, X, Z, false, true }, |
|
49 {{ 0, 0, 0 }, X, Y, true, true }, |
|
50 {{ 0, -1, 0 }, Z, Y, false, true }, |
44 }; |
51 }; |
45 |
52 |
46 cfg (str, gl_bgcolor, "#CCCCD9"); |
53 cfg (str, gl_bgcolor, "#CCCCD9"); |
47 cfg (str, gl_maincolor, "#707078"); |
54 cfg (str, gl_maincolor, "#707078"); |
48 cfg (float, gl_maincolor_alpha, 1.0); |
55 cfg (float, gl_maincolor_alpha, 1.0); |
75 }; |
82 }; |
76 |
83 |
77 const struct GLAxis { |
84 const struct GLAxis { |
78 const QColor col; |
85 const QColor col; |
79 const vertex vert; |
86 const vertex vert; |
80 } g_GLAxes[3] = { { QColor (255, 0, 0), vertex (10000, 0, 0) }, { QColor (128, 192, 0), vertex (0, 10000, 0) }, { QColor (0, 160, 192), vertex (0, 0, 10000) }, |
87 } g_GLAxes[3] = { |
|
88 { QColor (255, 0, 0), vertex (10000, 0, 0) }, |
|
89 { QColor (80, 192, 0), vertex (0, 10000, 0) }, |
|
90 { QColor (0, 160, 192), vertex (0, 0, 10000) }, |
81 }; |
91 }; |
82 |
92 |
83 // ============================================================================= |
93 // ============================================================================= |
84 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
94 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
85 // ============================================================================= |
95 // ============================================================================= |
406 glMatrixMode (GL_MODELVIEW); |
416 glMatrixMode (GL_MODELVIEW); |
407 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); |
417 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); |
408 } |
418 } |
409 |
419 |
410 // ============================================================================= |
420 // ============================================================================= |
|
421 // This converts a 2D point on the screen to a 3D point in the model. If 'snap' |
|
422 // is true, the 3D point will snap to the current grid. |
|
423 // ============================================================================= |
411 vertex GLRenderer::coordconv2_3 (const QPoint& pos2d, bool snap) const { |
424 vertex GLRenderer::coordconv2_3 (const QPoint& pos2d, bool snap) const { |
412 assert (camera() != Free); |
425 assert (camera() != Free); |
413 |
426 |
414 vertex pos3d; |
427 vertex pos3d; |
415 const staticCameraMeta* cam = &g_staticCameras[m_camera]; |
428 const staticCameraMeta* cam = &g_staticCameras[m_camera]; |
429 |
442 |
430 cx *= negXFac; |
443 cx *= negXFac; |
431 cy *= negYFac; |
444 cy *= negYFac; |
432 |
445 |
433 str tmp; |
446 str tmp; |
434 pos3d = g_origin; |
447 // Create the vertex from the coordinates |
435 pos3d[axisX] = tmp.sprintf ("%.3f", cx).toDouble(); |
448 pos3d[axisX] = tmp.sprintf ("%.3f", cx).toDouble(); |
436 pos3d[axisY] = tmp.sprintf ("%.3f", cy).toDouble(); |
449 pos3d[axisY] = tmp.sprintf ("%.3f", cy).toDouble(); |
437 pos3d[3 - axisX - axisY] = depthValue(); |
450 pos3d[3 - axisX - axisY] = depthValue(); |
438 return pos3d; |
451 return pos3d; |
439 } |
452 } |
440 |
453 |
|
454 // ============================================================================= |
|
455 // Inverse operation for the above - convert a 3D position to a 2D screen |
|
456 // position |
441 // ============================================================================= |
457 // ============================================================================= |
442 QPoint GLRenderer::coordconv3_2 (const vertex& pos3d) const { |
458 QPoint GLRenderer::coordconv3_2 (const vertex& pos3d) const { |
443 GLfloat m[16]; |
459 GLfloat m[16]; |
444 const staticCameraMeta* cam = &g_staticCameras[m_camera]; |
460 const staticCameraMeta* cam = &g_staticCameras[m_camera]; |
445 const Axis axisX = cam->axisX; |
461 const Axis axisX = cam->axisX; |
604 // Tool tips |
620 // Tool tips |
605 if (m_drawToolTip) { |
621 if (m_drawToolTip) { |
606 if (m_cameraIcons[m_toolTipCamera].destRect.contains (m_pos) == false) |
622 if (m_cameraIcons[m_toolTipCamera].destRect.contains (m_pos) == false) |
607 m_drawToolTip = false; |
623 m_drawToolTip = false; |
608 else { |
624 else { |
609 QPen bord = m_thinBorderPen; |
|
610 bord.setBrush (Qt::black); |
|
611 |
|
612 const ushort margin = 2; |
|
613 ushort x0 = m_pos.x(), |
|
614 y0 = m_pos.y(); |
|
615 |
|
616 str label = fmt (fmtstr, tr (g_CameraNames[m_toolTipCamera])); |
625 str label = fmt (fmtstr, tr (g_CameraNames[m_toolTipCamera])); |
617 |
626 QToolTip::showText (m_globalpos, label); |
618 const ushort textWidth = metrics.width (label), |
|
619 textHeight = metrics.height(), |
|
620 fullWidth = textWidth + (2 * margin), |
|
621 fullHeight = textHeight + (2 * margin); |
|
622 |
|
623 QRect area (m_pos.x(), m_pos.y(), fullWidth, fullHeight); |
|
624 |
|
625 if (x0 + fullWidth > m_width) |
|
626 x0 -= fullWidth; |
|
627 |
|
628 if (y0 + fullHeight > m_height) |
|
629 y0 -= fullHeight; |
|
630 |
|
631 paint.setBrush (QColor (0, 128, 255, 208)); |
|
632 paint.setPen (bord); |
|
633 paint.drawRect (x0, y0, fullWidth, fullHeight); |
|
634 |
|
635 paint.setBrush (Qt::black); |
|
636 paint.drawText (QPoint (x0 + margin, y0 + margin + metrics.ascent()), label); |
|
637 } |
627 } |
638 } |
628 } |
639 } |
629 } |
640 |
630 |
641 // Message log |
631 // Message log |
957 clampAngle (m_rotY); |
947 clampAngle (m_rotY); |
958 } |
948 } |
959 |
949 |
960 // Start the tool tip timer |
950 // Start the tool tip timer |
961 if (!m_drawToolTip) |
951 if (!m_drawToolTip) |
962 m_toolTipTimer->start (1000); |
952 m_toolTipTimer->start (500); |
963 |
953 |
964 // Update 2d position |
954 // Update 2d position |
965 m_pos = ev->pos(); |
955 m_pos = ev->pos(); |
|
956 m_globalpos = ev->globalPos(); |
966 |
957 |
967 // Calculate 3d position of the cursor |
958 // Calculate 3d position of the cursor |
968 m_hoverpos = (camera() != Free) ? coordconv2_3 (m_pos, true) : g_origin; |
959 m_hoverpos = (camera() != Free) ? coordconv2_3 (m_pos, true) : g_origin; |
969 |
960 |
970 // Update rect vertices since m_hoverpos may have changed |
961 // Update rect vertices since m_hoverpos may have changed |