Tap Intersection

General discussion.
Post Reply
grire974
Posts: 1
Joined: Tue Feb 20, 2018 11:39 pm

Tap Intersection

Post by grire974 » Tue Feb 20, 2018 11:59 pm

Hi Folks,

Basically I'm trying to take a two dimensional tap event on an iOS screen (e.g. x, y) and find out if the user has tapped a 3D model that is currently rendering in my ARTK view. I've been working with the NFT-OSG example

I see there's an OSG method here:
http://www.artoolkitx.org/artoolkit5/do ... tersection

which in the OSG example code is wrapped in a function called: - (BOOL) isIntersectedByRayFromPoint:(ARVec3)p1 toPoint:(ARVec3)p2

This all seems straight forward; but my biggest problem is trying to figure out the coordinate system to find the 'world coordinates' mentioned in the apiref above. I don't see reference anywhere in the ARTK code to 'world coordinates' only eye space and pose space.

Anyhow I've tried testing the data manually by printing xyz translation components to the console:
e.g.
ARPose p = [((VEObjectOSG *)[[virtualEnvironment getObjects] objectAtIndex:i]) poseInEyeSpace];
NSLog(@"x = %f, y = %f, z = %f\n", (float)p.T[12], (float)p.T[13], (float)p.T[14]);

Have tried this with poseInEyeSpace, pose, inversePose, inversePoseInEyespace;

The non-inverted pose variants give me values that seem to fall roughly within the range of glView.contentWidth/Height so I tried plugging those values in but get inconsistent results (e.g. I can get some hits, but not usually near the actual model)

My approach has been as follows:
VEObjectOSG* anObject= ((VEObjectOSG *)[[virtualEnvironment getObjects] objectAtIndex:0]); //have checked there's only one model loaded
ARVec3 rayPoint1;
rayPoint1.v[0] = ex;//iOS tap event screen coordinate mapped into the range of glView.contentWidth/Height
rayPoint1.v[1] = ey;//iOS tap event screen coordinate mapped into the range of glView.contentWidth/Height
rayPoint1.v[2] = 1000000.0f;
ARVec3 rayPoint2;
rayPoint2.v[0] = ex;
rayPoint2.v[1] = ey;
rayPoint2.v[2] = -1000000.0f;
if([anObject isIntersectedByRayFromPoint:rayPoint1 toPoint:rayPoint2] == YES){
NSLog(@"does intersect");
}else{
NSLog(@"doesn't intersect");
}

Am all out of ideas; without any solid direction there are too many permutations for trial and error.
Any help is much appreciated

Post Reply