objective c - Touch event in vuforia iOS app


Keywords:ios 


Question: 

I am creating an Augmented Reality based iOS app using vuforia.I have integrated Vuforia SDK in my project.I need to shows some objects over the target image while scanning the target image. It works fine. I also need to show some messages over the screen when the user touch any of the object. How can i identify which object the user have touched? How the touch events works when the device get zoom in and zoom out?Please help me.


1 Answer: 

Try to combine ImageTarget and Dominoes sample. Touch event handle in Dominoes starts from EAGLView.mm in the dominoes sample:

// Pass touch events through to the Dominoes module
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch* touch = [touches anyObject];
    CGPoint location = [touch locationInView:self];
    dominoesTouchEvent(ACTION_DOWN, 0, location.x, location.y);
}

- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch* touch = [touches anyObject];
    CGPoint location = [touch locationInView:self];
    dominoesTouchEvent(ACTION_CANCEL, 0, location.x, location.y);
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch* touch = [touches anyObject];
    CGPoint location = [touch locationInView:self];
    dominoesTouchEvent(ACTION_UP, 0, location.x, location.y);
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch* touch = [touches anyObject];
    CGPoint location = [touch locationInView:self];
    dominoesTouchEvent(ACTION_MOVE, 0, location.x, location.y);
}

Understand how they handle these touches and try to do the same. For more reference see Vuforia developer forum