开发者

Detecting touches on a NSOpenGLView

开发者 https://www.devze.com 2022-12-15 08:02 出处:网络
I have added an NSOpenGLView to my MainMenu.xib file, and have implemented drawRect to draw to it, this works great, so far so good.

I have added an NSOpenGLView to my MainMenu.xib file, and have implemented drawRect to draw to it, this works great, so far so good.

How do I detect touches on the screen? I imagine I c开发者_运维问答ould perhaps dump some transparent buttons or something over the NSOpenGLView area in Interface Builder?

The application is simple, i just need to know which area of a grid has been touched.


No need to add transparent buttons or overlays.

I'm assuming this is for the phone because you mentioned Cocoa Touch, but I'm not aware of NSOpenGLView for the phone. You need to look at the Apple example and create an EAGLView by overriding +layerClass in your subclass thus:

+ (Class)layerClass {
    return [CAEAGLLayer class];
}

Next, Make sure "User Interaction Enabled" is checked in IB.

Finally, implement the touch method calls:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event;

These will tell you where users touched the surface, and with how many fingers. You can do the rest from there. Try creating the template OpenGL project and looking at that. In addition, Jeff LaMarche has some good iPhone OpenGL tutorials on his blog: http://iphonedevelopment.blogspot.com/

0

精彩评论

暂无评论...
验证码 换一张
取 消