Jump to content

  • Log In with Google      Sign In   
  • Create Account


glararan

Member Since 05 Aug 2013
Offline Last Active Sep 06 2014 01:39 PM

Posts I've Made

In Topic: Terrain LOD tessellation cracks

02 June 2014 - 01:41 PM

Thanks.


In Topic: Qt5 - QOpenGL terrain, trying get terrain coords by mouse

09 August 2013 - 06:57 AM

BUMP

 

I’m trying to get terrain coords from camera QMatrix4×4, but it returns incorrets values.

Im using in camera these properties:
viewMatrix, projectionMatrix and viewProjectionMatrix.

I tried to figure it out with this code:

  1.         QMatrix4x4 inverted = m_camera->projectionMatrix() * m_camera->viewMatrix();
  2.         inverted = inverted.inverted();
  3.  
  4.         float posZ;
  5.  
  6.         // m_funcs = QOpenGLFuncions_4_0_Core
  7.         m_funcs->glReadPixels(mouse_position.x(), mouse_position.y(), 1, 1,GL_DEPTH_COMPONENT, GL_FLOAT, &posZ);
  8.  
  9.         QVector4D clickedPointOnScreen(mouse_position.x(),mouse_position.y(), posZ, 1.0f);
  10.         QVector4D clickedPointIn3DOrgn = inverted * clickedPointOnScreen;
  11.  
  12.         terrain_pos = clickedPointIn3DOrgn.toVector3D();
  13.  
  14.         qDebug()  << terrain_pos;

 

I’m with camera on position: 250.0f, 10.0f, 250.0f
And I’m getting: QVector3D(415.715, 99.3959, 6.45992) (cursor is in center ofQGLWidget screen, i calculated coords). It should be QVector3D(250.0f, 10.0f, 260f+-)


PARTNERS