Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- screen position change to World 3D position
- @param screenPos normalized screen position 0~1
- @param cam change world to screen camera
- @return world 3d position vec3
- */
- vec3 DrwrApp::worldFromScreen( const vec2 screenPos, const CameraPersp *cam ) {
- // generate a ray from the camera into our world
- float u = screenPos.x;
- float v = screenPos.y;
- // because OpenGL and Cinder use a coordinate system
- // where (0, 0) is in the LOWERleft corner, we have to flip the v-coordinate
- Ray ray = cam->generateRay(u , 1.0f - v, cam->getAspectRatio() );
- float result = 0.0f;
- //vec3 planePos = this->mCamera.getEyePoint();
- vec3 planePos = vec3(0.f,0.f,0.f);
- vec3 normal = cam->getViewDirection();
- if ( ray.calcPlaneIntersection( planePos, normal, &result ) ) {
- return ray.calcPosition( result );
- }
- return vec3(0.f,0.f,0.f);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement