Question

I have the regular OpenGL / EAGL setup going on:

@interface EAGLView : UIView {
@public
    EAGLContext* context;
}
@property (nonatomic, retain) EAGLContext* context;
@end

@implementation EAGLView
@synthesize context;
+ (Class)layerClass {
    return [CAEAGLLayer class];
}
@end

@interface EAGLViewController : UIViewController {
@public
    EAGLView* glView;
}
@property(nonatomic, retain) EAGLView* glView;
@end

@implementation EAGLViewController
@synthesize glView;

- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
    for (UITouch* touch in touches) {
        CGPoint location = [touch locationInView:glView];
        int index;
        for (index = 0; index < gCONST_CURSOR_COUNT; ++index) {
            if (sCursor[index] == NULL) {
                sCursor[index] = touch;
                break;
            }
        }
    }
    [super touchesBegan:touches withEvent:event];
}

That implementation includes corresponding touchesEnded/Canceled/Moved as well. The code fully works and tracks well.

I also make sure that I'm giving proper values for everything:

sViewController = [EAGLViewController alloc];

CGRect rect = [[UIScreen mainScreen] applicationFrame];
sViewController.glView = [[EAGLView alloc] initWithFrame:CGRectMake(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height)];
Assert(sViewController.glView);
sViewController.glView.userInteractionEnabled = YES;
sViewController.glView.multipleTouchEnabled = YES;
sViewController.glView.exclusiveTouch = YES;

It all compiles just fine, but I'm never receiving more than one UITouch. I don't mean in a single touchesBegan, but the index never goes past 0. I also set a breakpoint for the second time it enters that function, and putting two fingers on doesn't make it trigger.

Was it helpful?

Solution 3

It seems all I was missing was this:

sViewController.view = sViewController.glView;

OTHER TIPS

If you want to detect multiple touches (and/or distinguish between a one finger, two finger etc. touch), try using a UIPanGestureRecognizer. When you set it up, you can specify the minimum and maximum number of touches. Then attach it to the view where you want to detect the touches. When you receive events from it, you can ask it how many touches it received and branch accordingly.

Here's the apple documentation:

http://developer.apple.com/library/ios/#documentation/uikit/reference/UIPanGestureRecognizer_Class/Reference/Reference.html

If you do this, you might not need to use the touchesBegan/Moved/Ended methods at all and, depending on how you set up the gesturerecognizer, touchesBegan/Moved/Ended may never get called.

Use [event allTouches] in place of touches. touches represents only the touches that have 'changed'. From the apple docs:

If you are interested in touches that have not changed since the last phase or that are in a different phase than the touches in the passed-in set, you can find those in the event object. Figure 3-2 depicts an event object that contains touch objects. To get all of these touch objects, call the allTouches method on the event object.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top