Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Reverse Viewport transformation
- qreal conv_x = ( (mousex / (854.0/2.0)) -1);
- qreal conv_y = ( (mousey / (480.0/2.0)) -1);
- //Get viewport points as begin and end of the ray
- QVector4D nearPlane(conv_x, conv_y, -1, 0.0);
- QVector4D farPlane(conv_x, conv_y, +1, 0.0);
- //Multiply per the inverted ModelView matrix, to get world space coordinates of those points
- QVector4D nearPlane2 = cam_m.inverted() * nearPlane;
- QVector4D farPlane2 = cam_m.inverted() * farPlane;
- nearPlane2.setX(nearPlane2.x() / nearPlane2.w());
- nearPlane2.setY(nearPlane2.y() / nearPlane2.w());
- nearPlane2.setZ(nearPlane2.z() / nearPlane2.w());
- farPlane2.setX(farPlane2.x() / farPlane2.w());
- farPlane2.setY(farPlane2.y() / farPlane2.w());
- farPlane2.setZ(farPlane2.z() / farPlane2.w());
- //direction, farPlane - nearPlane
- QVector4D direction = farPlane2 - nearPlane2;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement