Cocoa - Reset Mouse Position to center of View

CactusJack
Unregistered
 
Post: #1
Cocoa First Personal Viewpoints:

First, I'm not a hard-core game programmer: I am a beginner. I'm experienced in Windows programming, but I wanted to learn Cocoa, so I deceided I'd port some Open GL tutorials to Cocoa. This is why I would like Cocoa specific help. I've learned quite a bit about Cocoa, but I've hit some snags.

My question is this: I can track the position of the mouse in the glWindow through the mouseMoved event. What I'd like to do in each render cycle, take the coordinates of the mouse from this event and use the distance from them to the center of the screen to rotate my viewpoint and then set the mouse coordinates back to the center of the screen to start over again. Does anyone have any ideas on how to do this in Cocoa?

Also, how do it make it if I push Escape, the program quits? (because if I start moving the cursor back to the center all the time, I'll never be able to muse the Application menu to quit. appreciate

One last question. Do you know how to hide the cursor?

Thanks for any help you may be able to give me. I appreciate your time!

John Baker
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
You should never move the mouse pointer, as that would be against the HI guidelines. You should never mess with standard mouse behavior for a non-full-screen application. That's why you can't do it from Cocoa.

When you receive a mouse moved event, you can call

Code:
void CGGetLastMouseDelta( CGMouseDelta * deltaX, CGMouseDelta * deltaY );

which returns the amount the mouse moved disregarding screen bounds. This will get you the information you want.

If you do decide to go full-screen, you can hide and show the cursor using

Code:
CGDisplayErr CGDisplayHideCursor(CGDirectDisplayID display);    /* increments hide cursor count */
CGDisplayErr CGDisplayShowCursor(CGDirectDisplayID display);    /* decrements hide cursor count  */

#include <ApplicationServices/ApplicationServices.h> for these functions.

You can quit a Cocoa application by doing

Code:
[NSApp terminate:self];
Quote this message in a reply
CactusJack
Unregistered
 
Post: #3
Thank you SO much for your quick reply. I'm new to Mac Game programming and had no idea about those methods. That really helped!

John Baker
Quote this message in a reply
CactusJack
Unregistered
 
Post: #4
I can use CGGetLastMouseDelta now fine for tracking the distance the mouse traveled, but it stops tracking when I click a mouse button and drag. Is this easily avoided? Is this a problem with a first responser or something?

Thanks ahead of time.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #5
I suspect it's simply that you're getting mouseDragged (or similar) events when the mouse button is down as opposed to the mouseMoved events you get when no buttons are pressed.

If you look in the NSResponder docs/header file you should be able to find all the different events you can be sent.
Quote this message in a reply
Member
Posts: 64
Joined: 2005.06
Post: #6
Try your code in mouseDragged
Quote this message in a reply
CactusJack
Unregistered
 
Post: #7
I feel stupid. I thought this is what was happening but wasn't sure.

Thanks again!

Cactus
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  finding a training center - Heeeelp Glauter 1 3,009 Dec 26, 2011 12:30 PM
Last Post: zenkimoto
  new position with vector pander007 3 3,736 Oct 13, 2007 11:49 AM
Last Post: Nevada
  changing mouse icon in cocoa Leroy 13 6,930 Sep 4, 2007 07:10 PM
Last Post: SethWillits
  Mouse coordinates with Cocoa vnvrymdreglage 13 6,737 Apr 8, 2007 07:26 AM
Last Post: vnvrymdreglage
  Generating Corner points of Rectangular Box using center point and forward vector 3DPat 6 5,800 Nov 13, 2006 09:40 PM
Last Post: 3DPat