Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Is there a Camera Follow Mouse demo/Tutorial

Author
Message
papabrian
13
Years of Service
User Offline
Joined: 21st Dec 2010
Location: Colorado Springs
Posted: 26th Dec 2010 02:53
I'd like to find demo code, or a tutorial on making the camera follow the mouse cursor (like most FPS games). I tried but it doesn't work, and is not very smooth either.

Thanks
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 26th Dec 2010 13:40 Edited at: 26th Dec 2010 13:43
Here's a sample code. Rotate the camera according to the mouse movement values every loop. The CamSpeed variable is a mouse sensitivity adjustment which can be configured according to the user's preference.

In this sample code I'm using the dbCameraAngleX/Y commands to get the current rotation of the camera, but in the original code where I took the example from, the rotation angles and the CamSpeed were stored as data members of the camera class.



The "hide mouse" and "position mouse" commands are optional but they make it look better. Of course the screen centre position can also be stored in variables instead of using the screen width/height functions every loop.
papabrian
13
Years of Service
User Offline
Joined: 21st Dec 2010
Location: Colorado Springs
Posted: 26th Dec 2010 15:37
Wow. Perfect. It works just the way you said.

Thanks

Login to post a reply

Server time is: 2024-11-19 14:49:41
Your offset time is: 2024-11-19 14:49:41