yshrkt / VuforiaSampleSwift

Vuforia sample code with SceneKit using Swift
MIT License
123 stars 24 forks source link

Touch event in LandscapeLeft or LandscapeRight orientation. #14

Open jhudziak opened 8 years ago

jhudziak commented 8 years ago

Do you know how to calculate position x and y used in hitTest method when vuforia and device work in landscape orientation ?

Regards, JH

yshrkt commented 8 years ago

Maybe you not need to fix hitTest method for landscape orientation. This sample work in landscape orientation, by prepare like below:

vuforiaManager?.prepare(with: .landscapeLeft)
jhudziak commented 8 years ago

I wrote this functionality. If you want i can fork this project with rotation support, and later you can add this to your sample.

But my question is about touchedNodWithLocationInView. Did i change it propperly?

- (SCNNode*)touchedNodeWithLocationInView:(CGPoint)location {
    CGPoint pos = location;
    pos.x *= [[UIScreen mainScreen] nativeScale];
    pos.y *= [[UIScreen mainScreen] nativeScale];
    pos.y = _manager.viewport.size.height + _manager.viewport.origin.y - pos.y;

    UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
    if(orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeLeft){
        pos.x += fabs( _manager.viewport.origin.x);
    }

    NSArray* results = [_renderer hitTest:pos options:nil];
    return [[results firstObject] node];
}
yshrkt commented 8 years ago

But my question is about touchedNodWithLocationInView. Did i change it properly?

If you want to use in landscape mode only, I think you don't need to modify touchedNodeWithLocationInView method. You can you use in landscape mode to setup like below:

Otherwise, you might need to modify it.