Camera work. centering mouse

FreeKQuency23
Unregistered
 
Post: #1
Hello

Im trying to do some first person camera work in CocoaGL.
Is there a way to:

a) keep the mouse centered in the middle of the screen so any movement with the mouse is interpreted as a vector from the center of the screen? After every movement the mouse should center itself back to the center of the screen.

b) hide the mouse when in fullscreen mode so all you see is the first person movement.

Thank you.
Quote this message in a reply
Member
Posts: 114
Joined: 2005.03
Post: #2
To get the relative mouse motion, use NSEvent's deltaX and deltaY methods. This won't center the mouse on the screen, but it will always, even if the mouse is at the edge of the screen, give correct results. To hide the mouse cursor on the main screen, use CGDisplayHideCursor(kCGMainDisplay) and CGDisplayShowCursor(kCGMainDisplay) to show it again.
Quote this message in a reply
FreeKQuency23
Unregistered
 
Post: #3
The first part works great. thank you.
The second part however, doesnt work becuase my window is a cocoa window and that is a carbon function call.

Im still a noob here, so sorry if this is something totally obvious, but here is my error message from xcode:
error: cannot convert 'NSWindow*' to '_CGDirectDisplayID*' for argument '1' to 'CGDisplayErr CGDisplayShowCursor(_CGDirectDisplayID*)'

Im checking the APIs to see if there is a conversion. thanks again.
Quote this message in a reply
FreeKQuency23
Unregistered
 
Post: #4
OK
I found the cocoa way of doing it:
[NSCursor hide];
[NSCursor show];

thanks.
Quote this message in a reply
Moderator
Posts: 508
Joined: 2002.09
Post: #5
FreeKQuency23 Wrote:The second part however, doesnt work becuase my window is a cocoa window and that is a carbon function call.

So? You can perfectly combine Cocoa with Carbon!

"When you dream, there are no rules..."
Quote this message in a reply
Moderator
Posts: 1,140
Joined: 2005.07
Post: #6
The reason why it didn't work is because you didn't follow Cochrane's function calls correctly. He had kCGMainDisplay as the arguments for a reason.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  centering a sprite in the middle of the screen convertToWorldSpace / NodeSpace sefiroths 0 2,910 Dec 21, 2011 01:25 AM
Last Post: sefiroths
  [NSWindow center] not centering maaaaark 9 7,092 Mar 13, 2005 12:34 PM
Last Post: maaaaark