SHARE
TWEET

Untitled

a guest Apr 18th, 2019 89 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  screen position change to World 3D position
  3.  
  4.  @param screenPos normalized screen position 0~1
  5.  @param cam change world to screen camera
  6.  @return world 3d position vec3
  7.  */
  8. vec3 DrwrApp::worldFromScreen( const vec2 screenPos, const CameraPersp *cam ) {
  9.     // generate a ray from the camera into our world
  10.     float u = screenPos.x;
  11.     float v = screenPos.y;
  12.     // because OpenGL and Cinder use a coordinate system
  13.     // where (0, 0) is in the LOWERleft corner, we have to flip the v-coordinate
  14.     Ray ray = cam->generateRay(u , 1.0f - v, cam->getAspectRatio() );
  15.    
  16.     float result = 0.0f;
  17.     //vec3 planePos = this->mCamera.getEyePoint();
  18.     vec3 planePos = vec3(0.f,0.f,0.f);
  19.     vec3 normal = cam->getViewDirection();
  20.     if ( ray.calcPlaneIntersection( planePos, normal, &result ) ) {
  21.         return ray.calcPosition( result );
  22.     }
  23.     return vec3(0.f,0.f,0.f);
  24. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top