Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Opengl world coords change on camera rotation
Forum Updated to NodeBB v4.3 + New Features

Opengl world coords change on camera rotation

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 699 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    glararan
    wrote on last edited by
    #1

    Hi,

    I build own gluUnProject, but I have big trouble with camera, when I rotate camera, world coords are changed and are incorrect.

    When I just start app, my Z coordinate is incorrect, when I turn camera to left by 90 degrees, Z is in normal, but X is corrupted.

    @ QMatrix4x4 viewMatrix = m_camera->viewMatrix();
    QMatrix4x4 modelViewMatrix = viewMatrix * m_modelMatrix;
    QMatrix4x4 modelViewProject = m_camera->projectionMatrix() * modelViewMatrix;
    QMatrix4x4 inverted = m_viewportMatrix * modelViewProject;

        inverted = inverted.inverted();
    
        float posZ;
        int   posY = (int)m_viewportSize.y() - (int)mouse_position.y() - 1;
    
        m_funcs->glReadPixels((int)mouse_position.x(), posY, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &posZ);
    
        QVector4D clickedPointOnScreen(mouse_position.x(), (float)posY, posZ, 1.0f);
        QVector4D clickedPointIn3DOrgn = inverted * clickedPointOnScreen;
    
        clickedPointIn3DOrgn = clickedPointIn3DOrgn / clickedPointIn3DOrgn.w();
    
        terrain_pos = clickedPointIn3DOrgn.toVector3DAffine();@
    
    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved