J
J
Julia2017-03-28 10:55:25
Qt
Julia, 2017-03-28 10:55:25

How to convert 3d point to 2d for display on Widget?

Hello everyone
Please tell me how to be, I have a position of an object in 3d space and I want to display it in QtOpenGlWidget using QPainter or you can leave it in 3d and draw using OpenGl tools
How does this projection work? Are there ready methods from Qt? Where can you read about this?
circlePosition is the position of my object saved as a Vector3d


QPoint circlePositionPoint = QPoint(circlePosition.x(), circlePosition.y());
painter.drawEllipse(circlePositionPoint, 30, 30);

void Navigation::paintEvent(QPaintEvent * event)
{

  naviTargetWidget->makeCurrent();
  initGL( naviTargetWidget->width(), naviTargetWidget->height());
  glClearColor((float)(121 / 255.0), (float)(188 / 255.0), (float)(255 / 255.0), (float)1);
   
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  glEnable(GL_DEPTH_TEST);

  QPainter painter(naviTargetWidget);

  // Crosshair 
  painter.setPen(Qt::black);
  int targRadius = 30, icx, icy;
  icx = naviTargetWidget->width() / 2;
  icy = naviTargetWidget->height() / 2;
  QPointF  widgetCenter(icx, icy);

  //Cicle Gradient
  QRadialGradient radialGrad(QPointF(icx, icy), 300);
  radialGrad.setColorAt(0, Qt::white);
  radialGrad.setColorAt(1, Qt::yellow);

  painter.setBrush(radialGrad);

  painter.drawEllipse(widgetCenter, 300, 300);

  painter.setPen(Qt::black);

  painter.drawLine(icx - targRadius, icy, icx + targRadius, icy);
  painter.drawLine(icx, icy - targRadius, icx, icy + targRadius);

  // Little TargetCircle
  painter.setBrush(Qt::transparent);
  painter.drawEllipse(widgetCenter, 15, 15);
  // Big TargetCircle
  painter.setBrush(Qt::transparent);
  painter.drawEllipse(widgetCenter, 30, 30);


  //Circle from drill
  painter.setBrush(Qt::transparent);

////// ---->>>>  circlePosition это Vector3d 
  QPoint circlePositionPoint = QPoint(circlePosition.x(), circlePosition.y());
  painter.drawEllipse(circlePositionPoint, 30, 30);

  painter.end();

Thank you for your attention

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question