550 position3d.setCoordinate(static_cast<Axis>(3 - axisX - axisY), getDepthValue()); |
550 position3d.setCoordinate(static_cast<Axis>(3 - axisX - axisY), getDepthValue()); |
551 return position3d; |
551 return position3d; |
552 } |
552 } |
553 } |
553 } |
554 |
554 |
555 // ============================================================================= |
555 /* |
556 // |
556 * Inverse operation for the above - convert a 3D position to a 2D screen position. |
557 // Inverse operation for the above - convert a 3D position to a 2D screen position. Don't ask me how this code manages |
557 */ |
558 // to work, I don't even know. |
558 QPoint GLRenderer::convert3dTo2d(const Vertex& position3d) const |
559 // |
|
560 QPoint GLRenderer::convert3dTo2d(const Vertex& position3d) |
|
561 { |
559 { |
562 if (camera() == FreeCamera) |
560 if (camera() == FreeCamera) |
563 { |
561 { |
564 return {0, 0}; |
562 return {0, 0}; |
565 } |
563 } |
568 const CameraInfo* camera = &g_cameraInfo[this->camera()]; |
566 const CameraInfo* camera = &g_cameraInfo[this->camera()]; |
569 Axis axisX = camera->localX; |
567 Axis axisX = camera->localX; |
570 Axis axisY = camera->localY; |
568 Axis axisY = camera->localY; |
571 int signX = camera->negatedX ? -1 : 1; |
569 int signX = camera->negatedX ? -1 : 1; |
572 int signY = camera->negatedY ? -1 : 1; |
570 int signY = camera->negatedY ? -1 : 1; |
573 GLfloat matrix[16]; |
571 int rx = (((position3d[axisX] * signX) + m_virtualWidth + panning(X)) * m_width) / (2 * m_virtualWidth); |
574 double x = position3d.x(); |
572 int ry = (((position3d[axisY] * signY) - m_virtualHeight + panning(Y)) * m_height) / (2 * m_virtualHeight); |
575 double y = position3d.y(); |
|
576 double z = position3d.z(); |
|
577 glGetFloatv (GL_MODELVIEW_MATRIX, matrix); |
|
578 Vertex transformed = {(matrix[0] * x) + (matrix[1] * y) + (matrix[2] * z) + matrix[3], |
|
579 (matrix[4] * x) + (matrix[5] * y) + (matrix[6] * z) + matrix[7], |
|
580 (matrix[8] * x) + (matrix[9] * y) + (matrix[10] * z) + matrix[11]}; |
|
581 int rx = (((transformed[axisX] * signX) + m_virtualWidth + panning (X)) * m_width) / (2 * m_virtualWidth); |
|
582 int ry = (((transformed[axisY] * signY) - m_virtualHeight + panning (Y)) * m_height) / (2 * m_virtualHeight); |
|
583 return {rx, -ry}; |
573 return {rx, -ry}; |
584 } |
574 } |
585 } |
575 } |
586 |
576 |
587 QPen GLRenderer::textPen() const |
577 QPen GLRenderer::textPen() const |