Log in or register to post comments

Intersection Point on Target Overlay - Cloud Reco Example

August 28, 2013 - 10:36pm #1

Hello,

I am using clould reco example and added following method to CRParentViewControllerClass. 

bool
linePlaneIntersection(QCAR::Vec3F lineStart, QCAR::Vec3F lineEnd,
                      QCAR::Vec3F pointOnPlane, QCAR::Vec3F planeNormal,
                      QCAR::Vec3F &intersection)
{
    QCAR::Vec3F lineDir = SampleMath::Vec3FSub(lineEnd, lineStart);
    lineDir = SampleMath::Vec3FNormalize(lineDir);
    
    QCAR::Vec3F planeDir = SampleMath::Vec3FSub(pointOnPlane, lineStart);
    
    float n = SampleMath::Vec3FDot(planeNormal, planeDir);
    float d = SampleMath::Vec3FDot(planeNormal, lineDir);
    
    if (fabs(d) < 0.00001) {
        // Line is parallel to plane
        return false;
    }
    
    float dist = n / d;
    
    QCAR::Vec3F offset = SampleMath::Vec3FScale(lineDir, dist);
    intersection = SampleMath::Vec3FAdd(lineStart, offset);
    
    return true;
}
void
projectScreenPointToPlane(QCAR::Vec2F point, QCAR::Vec3F planeCenter, QCAR::Vec3F planeNormal,
                          QCAR::Vec3F &intersection, QCAR::Vec3F &lineStart, QCAR::Vec3F &lineEnd)
{
    CloudRecoAppDelegate* delegate = (CloudRecoAppDelegate*)[[UIApplication sharedApplication] delegate];
    QCARutils *qUtils = [QCARutils getInstance];
    
    // Window Coordinates to Normalized Device Coordinates
    QCAR::VideoBackgroundConfig config = QCAR::Renderer::getInstance().getVideoBackgroundConfig();
    
    float halfScreenWidth = qUtils.viewSize.height / 2.0f; // note use of height for width
    float halfScreenHeight = qUtils.viewSize.width / 2.0f; // likewise
    
    float halfViewportWidth = config.mSize.data[0] / 2.0f;
    float halfViewportHeight = config.mSize.data[1] / 2.0f;
    
    float x = (qUtils.contentScalingFactor * point.data[0] - halfScreenWidth) / halfViewportWidth;
    float y = (qUtils.contentScalingFactor * point.data[1] - halfScreenHeight) / halfViewportHeight * -1;
    
    QCAR::Vec4F ndcNear(x, y, -1, 1);
    QCAR::Vec4F ndcFar(x, y, 1, 1);
    
    // Normalized Device Coordinates to Eye Coordinates
    QCAR::Matrix44F projectionMatrix = [QCARutils getInstance].projectionMatrix;
    QCAR::Matrix44F inverseProjMatrix = SampleMath::Matrix44FInverse(projectionMatrix);
    
    QCAR::Vec4F pointOnNearPlane = SampleMath::Vec4FTransform(ndcNear, inverseProjMatrix);
    QCAR::Vec4F pointOnFarPlane = SampleMath::Vec4FTransform(ndcFar, inverseProjMatrix);
    pointOnNearPlane = SampleMath::Vec4FDiv(pointOnNearPlane, pointOnNearPlane.data[3]);
    pointOnFarPlane = SampleMath::Vec4FDiv(pointOnFarPlane, pointOnFarPlane.data[3]);
    if ([delegate.modelViewMatrix count] > 0){
        for ( int vv = 0 ; vv < 16 ; vv++){
            //NSLog(@"use::vv%d::%@",vv,delegate.modelViewMatrix[vv]);
            modelUse.data[vv] = [[delegate.modelViewMatrix objectAtIndex:vv] floatValue];
        }
        
    }
    
    
    // Eye Coordinates to Object Coordinates
    QCAR::Matrix44F inverseModelViewMatrix = SampleMath::Matrix44FInverse(modelUse);
    
    QCAR::Vec4F nearWorld = SampleMath::Vec4FTransform(pointOnNearPlane, inverseModelViewMatrix);
    QCAR::Vec4F farWorld = SampleMath::Vec4FTransform(pointOnFarPlane, inverseModelViewMatrix);
    
    lineStart = QCAR::Vec3F(nearWorld.data[0], nearWorld.data[1], nearWorld.data[2]);
    lineEnd = QCAR::Vec3F(farWorld.data[0], farWorld.data[1], farWorld.data[2]);
    linePlaneIntersection(lineStart, lineEnd, planeCenter, planeNormal, intersection);
}

This method is called as

  QCAR::Vec3F intersection, lineStart, lineEnd;
    projectScreenPointToPlane(QCAR::Vec2F(location.x, location.y), QCAR::Vec3F(0, 0, 0), QCAR::Vec3F(0, 0, 1), intersection, lineStart, lineEnd);
    NSLog(@"intersection Point: %f:%f:%f",intersection.data[0],intersection.data[1],intersection.data[2]);

However the touch point that I am getting is looking off. When I start touching the screen in potrait mode - touching the screen from top to down decreases the data[1] of the intersection point and touch from left to right increases the data[0] of the intersection point. I was expecting it to be reverse. 

 

Can you please advice why this would be. 

 

Intersection Point on Target Overlay - Cloud Reco Example

November 21, 2013 - 4:54am #10

Hi Victor,

I just wondered whether you check this previous thread where you were part of the discussion?

https://developer.vuforia.com/forum/ios/3d-touch-error

There, another developer had similar issues to yours and seemed to get to the bottom of it.  There it turned out to be due to the various rotations being handled incorrectly in the view hierarchy.

Can you please check?

 

cheers

N

Intersection Point on Target Overlay - Cloud Reco Example

November 16, 2013 - 8:23pm #9

No , I am not being able to figure that out. And yes it works perfectly in dominoes example.

Thanks,

 

Intersection Point on Target Overlay - Cloud Reco Example

November 14, 2013 - 2:58am #8

Did you ever get to the bottom of why the results were different in Dominoes and CloudReco?

...and does it work as expected in Dominoes?

 

N

Intersection Point on Target Overlay - Cloud Reco Example

November 14, 2013 - 12:41am #7

I have observed that  if the distance of the target overlay in z axis  in around 1000-1100 in iphone4 and around 800-1100 in iphone5 the touch in 3D work perfectly.

Given I am trying to touch the point in 3D, 

As I take device closer to the target the touch keeps moving toward top right ( potrait mode)

As I take device farther from the to the target the touch keeps moving to bottom left ( potrait mode)

I am  unable to figure out why this would be ?. Could this be mismatch in order of scaling and translation. Please advice. 

Thanks,

Ila

Intersection Point on Target Overlay - Cloud Reco Example

September 11, 2013 - 4:36am #6

Is it that the getPose() returns conceptually different matrixes in case of dominoes and cloud reco example ?

Not that I know of - they should be the same.

 

N

Intersection Point on Target Overlay - Cloud Reco Example

September 9, 2013 - 6:20am #5

Thanks for your response - I tried all three samples cloud reco , dominoes and image target. 

My target overlay is being overlayed exactly as in imageTarget Example. Now i copied the intersection methods from dominoes example projectScreenPointToPlane and linePlaneIntersection and added to the cloud reco exmaple.

In dominoes example I am able to get the correct intersection point but not in cloud reco. I dont see any difference in the way I am finding the intersection point or rendering the TargetOverlay. Is it that the getPose() returns conceptually different matrixes in case of dominoes and cloud reco example ?

Thanks,

 

Intersection Point on Target Overlay - Cloud Reco Example

September 6, 2013 - 8:52am #4

To my knowledge, the center of the Image Target should be at (0,0)

 

In this link https://developer.vuforia.com/resources/dev-guide/image-targets  Figure A shows the (x,y) going from the centre of the stones target.  Also, in the past I have set virtual buttons in the XML config file to be at coordinates based on this premise - which is something that might help you when it comes to debugging.

You might want to check out the Virtual Buttons sample as well just as a checkpoint for coordinates.

 

HTH

N

Intersection Point on Target Overlay - Cloud Reco Example

September 5, 2013 - 9:25pm #3

I think the source of problem is 

when i find the interesection point The top right corner of target overlay is 0,0 and bottom left is at -1,-1. I was expecting the the target overlay to be centered at (0,0) . If it is not centered at 0,0 I will have scale issues . Please can you tell me in general case for vuforia the target space is (0,0) in the center of the marker or the marker is confined from (0,0) to (-1,-1) in target space. 

Thanks.

Intersection Point on Target Overlay - Cloud Reco Example

August 29, 2013 - 3:10am #2

Unfortunately we are not in the position that we can debug your code like this, however everything you need should be present in the Dominoes sample.

It is worth searching the forums for Dominoes and for other related keywords.

This thread may help you:  https://developer.vuforia.com/forum/ios/getting-touch-event-3d-model

 

N

Log in or register to post comments