Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 5th, 2012  |  syntax: None  |  size: 0.54 KB  |  hits: 17  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Converting touch screen coordinates to 3d Opengl world coordinates on iphone
  2. touchLocation.y = [[self view] bounds].size.height - touchLocation.y;
  3.        
  4. CGFloat scale = [[UIScreen mainScreen] scale];
  5. touchLocation.y *= scale;
  6. touchLocation.y *= scale;
  7.        
  8. Vector3 near, far;
  9. gluUnProject(touchLocation.x, touchLocation.y, 0, _modelview, _projection, _viewport, &near.x, &near.y, &near.z);
  10. gluUnProject(touchLocation.x, touchLocation.y, 1, _modelview, _projection, _viewport, &far.x, &far.y, &far.z);
  11. return MakeRay(near, Vector3Subtract(far, near));