Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. void GLWidget::mouseMoveEvent(QMouseEvent *event)
  2. {
  3. /*
  4. int dx = event->x() - m_lastPos.x();
  5. int dy = event->y() - m_lastPos.y();
  6. */
  7. int dx = event->x() - width()/2;
  8. int dy = event->y() - height()/2;
  9.  
  10. float phi = atan2(m_player.direction.z(), m_player.direction.x());
  11. float theta = acos(m_player.direction.y());
  12.  
  13. phi = phi + dx * 0.005;
  14. theta = theta + dy * 0.005;
  15.  
  16. if(theta < 0.01) theta = 0.01;
  17. if(theta > 3.14) theta = 3.14;
  18.  
  19. m_player.direction.setX(sin(theta) * cos(phi));
  20. m_player.direction.setY(cos(theta));
  21. m_player.direction.setZ(sin(theta) * sin(phi));
  22.  
  23. /*
  24. if (event->buttons() & Qt::LeftButton) {
  25. setXRotation(m_camXRot + 0.5f * dy);
  26. setYRotation(m_camYRot + 0.5f * dx);
  27. } else if (event->buttons() & Qt::RightButton) {
  28. setXRotation(m_camXRot + 0.5f * dy);
  29. setZRotation(m_camZRot + 0.5f * dx);
  30. }
  31. m_lastPos = event->pos();
  32. */
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement