Advertisement
faenil

Untitled

Oct 18th, 2011
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. //Reverse Viewport transformation
  2. qreal conv_x = ( (mousex / (854.0/2.0)) -1);
  3. qreal conv_y = ( (mousey / (480.0/2.0)) -1);
  4.  
  5. //Get viewport points as begin and end of the ray
  6. QVector4D nearPlane(conv_x, conv_y, -1, 0.0);
  7. QVector4D farPlane(conv_x, conv_y, +1, 0.0);
  8.  
  9. //Multiply per the inverted ModelView matrix, to get world space coordinates of those points
  10. QVector4D nearPlane2 = cam_m.inverted() * nearPlane;
  11. QVector4D farPlane2 = cam_m.inverted() * farPlane;
  12.  
  13. nearPlane2.setX(nearPlane2.x() / nearPlane2.w());
  14. nearPlane2.setY(nearPlane2.y() / nearPlane2.w());
  15. nearPlane2.setZ(nearPlane2.z() / nearPlane2.w());
  16.  
  17. farPlane2.setX(farPlane2.x() / farPlane2.w());
  18. farPlane2.setY(farPlane2.y() / farPlane2.w());
  19. farPlane2.setZ(farPlane2.z() / farPlane2.w());
  20.  
  21. //direction, farPlane - nearPlane
  22. QVector4D direction = farPlane2 - nearPlane2;
  23.  
  24.  
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement