src/GLRenderer.cc

changeset 689
397870c6ed38
parent 688
2f4dcc323a85
child 690
9e9c52ca955e
equal deleted inserted replaced
688:2f4dcc323a85 689:397870c6ed38
118 // ============================================================================= 118 // =============================================================================
119 // 119 //
120 GLRenderer::GLRenderer (QWidget* parent) : QGLWidget (parent) 120 GLRenderer::GLRenderer (QWidget* parent) : QGLWidget (parent)
121 { 121 {
122 m_Picking = m_rangepick = false; 122 m_Picking = m_rangepick = false;
123 m_camera = (GL::EFixedCamera) gl_camera; 123 m_camera = (EFixedCamera) gl_camera;
124 m_drawToolTip = false; 124 m_drawToolTip = false;
125 m_EditMode = ESelectMode; 125 m_EditMode = ESelectMode;
126 m_rectdraw = false; 126 m_rectdraw = false;
127 m_panning = false; 127 m_panning = false;
128 m_compiler = new GLCompiler; 128 m_compiler = new GLCompiler;
370 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE); 370 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
371 371
372 glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 372 glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
373 glEnable (GL_DEPTH_TEST); 373 glEnable (GL_DEPTH_TEST);
374 374
375 if (m_camera != EFreeCamera) 375 if (camera() != EFreeCamera)
376 { 376 {
377 glMatrixMode (GL_PROJECTION); 377 glMatrixMode (GL_PROJECTION);
378 glPushMatrix(); 378 glPushMatrix();
379 379
380 glLoadIdentity(); 380 glLoadIdentity();
381 glOrtho (-m_virtWidth, m_virtWidth, -m_virtHeight, m_virtHeight, -100.0f, 100.0f); 381 glOrtho (-m_virtWidth, m_virtWidth, -m_virtHeight, m_virtHeight, -100.0f, 100.0f);
382 glTranslatef (pan (X), pan (Y), 0.0f); 382 glTranslatef (pan (X), pan (Y), 0.0f);
383 383
384 if (m_camera != EFrontCamera && m_camera != EBackCamera) 384 if (camera() != EFrontCamera && camera() != EBackCamera)
385 { 385 {
386 glRotatef (90.0f, g_FixedCameras[camera()].glrotate[0], 386 glRotatef (90.0f, g_FixedCameras[camera()].glrotate[0],
387 g_FixedCameras[camera()].glrotate[1], 387 g_FixedCameras[camera()].glrotate[1],
388 g_FixedCameras[camera()].glrotate[2]); 388 g_FixedCameras[camera()].glrotate[2]);
389 } 389 }
390 390
391 // Back camera needs to be handled differently 391 // Back camera needs to be handled differently
392 if (m_camera == GLRenderer::EBackCamera) 392 if (camera() == EBackCamera)
393 { 393 {
394 glRotatef (180.0f, 1.0f, 0.0f, 0.0f); 394 glRotatef (180.0f, 1.0f, 0.0f, 0.0f);
395 glRotatef (180.0f, 0.0f, 0.0f, 1.0f); 395 glRotatef (180.0f, 0.0f, 0.0f, 1.0f);
396 } 396 }
397 } 397 }
494 Vertex GLRenderer::coordconv2_3 (const QPoint& pos2d, bool snap) const 494 Vertex GLRenderer::coordconv2_3 (const QPoint& pos2d, bool snap) const
495 { 495 {
496 assert (camera() != EFreeCamera); 496 assert (camera() != EFreeCamera);
497 497
498 Vertex pos3d; 498 Vertex pos3d;
499 const LDFixedCameraInfo* cam = &g_FixedCameras[m_camera]; 499 const LDFixedCameraInfo* cam = &g_FixedCameras[camera()];
500 const Axis axisX = cam->axisX; 500 const Axis axisX = cam->axisX;
501 const Axis axisY = cam->axisY; 501 const Axis axisY = cam->axisY;
502 const int negXFac = cam->negX ? -1 : 1, 502 const int negXFac = cam->negX ? -1 : 1,
503 negYFac = cam->negY ? -1 : 1; 503 negYFac = cam->negY ? -1 : 1;
504 504
531 // position. Don't ask me how this code manages to work, I don't even know. 531 // position. Don't ask me how this code manages to work, I don't even know.
532 // 532 //
533 QPoint GLRenderer::coordconv3_2 (const Vertex& pos3d) const 533 QPoint GLRenderer::coordconv3_2 (const Vertex& pos3d) const
534 { 534 {
535 GLfloat m[16]; 535 GLfloat m[16];
536 const LDFixedCameraInfo* cam = &g_FixedCameras[m_camera]; 536 const LDFixedCameraInfo* cam = &g_FixedCameras[camera()];
537 const Axis axisX = cam->axisX; 537 const Axis axisX = cam->axisX;
538 const Axis axisY = cam->axisY; 538 const Axis axisY = cam->axisY;
539 const int negXFac = cam->negX ? -1 : 1, 539 const int negXFac = cam->negX ? -1 : 1,
540 negYFac = cam->negY ? -1 : 1; 540 negYFac = cam->negY ? -1 : 1;
541 541
577 577
578 // If we wish to only draw the brick, stop here 578 // If we wish to only draw the brick, stop here
579 if (isDrawOnly()) 579 if (isDrawOnly())
580 return; 580 return;
581 581
582 if (m_camera != EFreeCamera && !isPicking()) 582 if (camera() != EFreeCamera && !isPicking())
583 { 583 {
584 // Paint the overlay image if we have one 584 // Paint the overlay image if we have one
585 const LDGLOverlay& overlay = currentDocumentData().overlays[m_camera]; 585 const LDGLOverlay& overlay = currentDocumentData().overlays[camera()];
586 586
587 if (overlay.img != null) 587 if (overlay.img != null)
588 { 588 {
589 QPoint v0 = coordconv3_2 (currentDocumentData().overlays[m_camera].v0), 589 QPoint v0 = coordconv3_2 (currentDocumentData().overlays[camera()].v0),
590 v1 = coordconv3_2 (currentDocumentData().overlays[m_camera].v1); 590 v1 = coordconv3_2 (currentDocumentData().overlays[camera()].v1);
591 591
592 QRect targRect (v0.x(), v0.y(), abs (v1.x() - v0.x()), abs (v1.y() - v0.y())), 592 QRect targRect (v0.x(), v0.y(), abs (v1.x() - v0.x()), abs (v1.y() - v0.y())),
593 srcRect (0, 0, overlay.img->width(), overlay.img->height()); 593 srcRect (0, 0, overlay.img->width(), overlay.img->height());
594 paint.drawImage (targRect, *overlay.img, srcRect); 594 paint.drawImage (targRect, *overlay.img, srcRect);
595 } 595 }
1305 1305
1306 case EDrawMode: 1306 case EDrawMode:
1307 case ECircleMode: 1307 case ECircleMode:
1308 { 1308 {
1309 // Cannot draw into the free camera - use top instead. 1309 // Cannot draw into the free camera - use top instead.
1310 if (m_camera == EFreeCamera) 1310 if (camera() == EFreeCamera)
1311 setCamera (ETopCamera); 1311 setCamera (ETopCamera);
1312 1312
1313 // Disable the context menu - we need the right mouse button 1313 // Disable the context menu - we need the right mouse button
1314 // for removing vertices. 1314 // for removing vertices.
1315 setContextMenuPolicy (Qt::NoContextMenu); 1315 setContextMenuPolicy (Qt::NoContextMenu);
1576 1576
1577 // ============================================================================= 1577 // =============================================================================
1578 // 1578 //
1579 void GLRenderer::getRelativeAxes (Axis& relX, Axis& relY) const 1579 void GLRenderer::getRelativeAxes (Axis& relX, Axis& relY) const
1580 { 1580 {
1581 const LDFixedCameraInfo* cam = &g_FixedCameras[m_camera]; 1581 const LDFixedCameraInfo* cam = &g_FixedCameras[camera()];
1582 relX = cam->axisX; 1582 relX = cam->axisX;
1583 relY = cam->axisY; 1583 relY = cam->axisY;
1584 } 1584 }
1585 1585
1586 // ============================================================================= 1586 // =============================================================================
1672 // ============================================================================= 1672 // =============================================================================
1673 // 1673 //
1674 Axis GLRenderer::getCameraAxis (bool y, GLRenderer::EFixedCamera camid) 1674 Axis GLRenderer::getCameraAxis (bool y, GLRenderer::EFixedCamera camid)
1675 { 1675 {
1676 if (camid == (GL::EFixedCamera) - 1) 1676 if (camid == (GL::EFixedCamera) - 1)
1677 camid = m_camera; 1677 camid = camera();
1678 1678
1679 const LDFixedCameraInfo* cam = &g_FixedCameras[camid]; 1679 const LDFixedCameraInfo* cam = &g_FixedCameras[camid];
1680 return (y) ? cam->axisY : cam->axisX; 1680 return (y) ? cam->axisY : cam->axisX;
1681 } 1681 }
1682 1682

mercurial