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.

Code Snippets / Rotating the Camera Around an Object (Free-Look)

Author
Message
RUCCUS
19
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 20th Jul 2005 22:32
Rotating the Camera Around an Object (Free-Look)
By RUCCUS of RUCCUS.net

I've seen this asked a few times and realized I'd done it a while back without realizing it could help, so here's how to make the mouse or arrow keys rotate around an object and use the scroll wheel/arrow keys to zoom in and out.



Breakdown: Basically you make a dummy object, a triangle with 0,0,0,0,0,0,0,0,0 dimensions for minimal amount of lag. Then add a limb to that object and offset it away from it a bit. Then you can do this:

Zooming: Using the mousemovez() command we can get the mouse wheel movement speed, using that speed we can increase or decrease the offset of the dummy object's limb. Increasing or decreasing the offset will have a zooming effect since wherever the limb goes the camera goes.

Rotating: Using the mousemovex() and mousemovey() commands we can yrotate and xrotate the dummy object with these values. Rotating the dummy object will in turn move it's limb with it, and since once agan the camera goes where the limb goes, a rotation effect is given.

I added in arrowkey controls aswell since some people might need that:

Upkey = Zoom in
Downkey = Zoom out
Leftkey = Rotate left
Rightkey = Rotate right

+ = Zoom in
- = Zoom out

Editing it to fit your needs:

To change the default distance of the camera, change the OFFSET# variable.

To change the max distance able to zoom out, change the MAX_ZOOM# variable.

To change the max distance able to zoom in, change the MIN_ZOOM# variable.

To change the object being viewed, change the VIEW_OBJECT# variable

Thats basically it, if you need help understanding it just ask and Ill go into more detail but it's pretty simple for the novice to understand.

Hope it helps, RUCCUS.


Current Projects: SHADE - Game Maker | Mecho - TGC Puzzle Entry | Halo Physics Engine | COLD - Polygonal Collision Detection

Login to post a reply

Server time is: 2024-11-23 11:14:48
Your offset time is: 2024-11-23 11:14:48