Using CGPoint for RaySceneQuery

Discussion of issues specific to mobile platforms such as iOS, Android, Symbian and Meego.
Post Reply
cg76
Gnoblar
Posts: 24
Joined: Fri Feb 06, 2009 5:58 am
x 2

Using CGPoint for RaySceneQuery

Post by cg76 »

Hi all,

How do I convert CGPoint coordinates to device coordinates for RaySceneQuery? I'm using the code below but the ray does not return the intersection result correctly.

Code: Select all

-(void) touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event
{
	UITouch *touch = [touches anyObject];
	NSUInteger numTaps = [touch tapCount];
	CGPoint pt = [touch locationInView:self];
	
	if ( numTaps > 1 )
	{	
		Ogre::Real newX = (pt.x - (320 / 2)) / (320 /2);
		Ogre::Real newY = (pt.y - (480 / 2)) / (480 /2);

                Ogre::Ray mouseRay = cameraPtr->getCameraToViewportRay(newX, newY);
	}
}
Thanks in advance,
CG

User avatar
DanielSefton
Ogre Magi
Posts: 1235
Joined: Fri Oct 26, 2007 12:36 am
Location: Mountain View, CA
x 10
Contact:

Re: Using CGPoint for RaySceneQuery

Post by DanielSefton »

Your calculation looks wrong. getCameraFromViewportRay takes a value of 0-1, and locationInView returns the screen coords of the touch. Try:

Code: Select all

Ogre::Real newX = 1 - (pt.x / 320);
Ogre::Real newY = 1 - (pt.y / 480);

Post Reply