Game Development Community

Smooth zooming with a camera?

by Spencer Grey · in Torque Game Builder · 06/28/2006 (12:39 pm) · 8 replies

Hey,

Is there a tutorial anywhere on how to zoom in and out with the camera? The setTargetCameraZoom (or whatever it is) on the scenewindow requires me to dismount it first, and even then it doesnt zoom in smooth, small increments.

If someone could point me in the right direction I'd be very greatful :).

Edit -- Im aware that it might be done using the setTargetCameraZoom, but its just not doing what I want. >.<

#1
06/28/2006 (12:54 pm)
I'm not sure if this is the best way to do it, but I figured something out.

I attached this function to my camera class:

function Camera::zoom(%this, %perc) {
	sceneWindow2D.dismount();
	sceneWindow2D.setTargetCameraZoom (%perc);
	sceneWindow2D.startCameraMove();
	sceneWindow2D.completeCameraMove();
	sceneWindow2D.mount(%this.camera, "0 0", %force, true);
}

Now when I tell it to zoom, it automatically dismounts, sets the zoom, completes the zoom, then remounts.

Is this a decent way to go about it?

Also, I'd like to attach this to my mouse wheel event. I looked at the scene callbacks page, but it doesnt show a function for that. It only lists the left and right mouse button stuff. I'll keep poking around, but if anyone wants to give me a hint I wouldnt complain, hehe.

Thanks.

Edit -- Aha! It gets bound in an actionMap! =D
#2
06/28/2006 (1:55 pm)
Are you sure you have to dismount it?
#3
06/28/2006 (2:49 pm)
Yeah, you do actually have to dismount a camera before you zoom it unfortunately.

And yes, your best bet for controlled, step based zoom is exactly as you have it set up--have a target zoom point and interpolate between the current zoom and the target zoom in a series of small steps.

And as you appear to have discovered, you can bind the middle mouse button to a "cameraZoomIn/Out" type of function and give them direct control as well!
#4
06/29/2006 (1:49 pm)
It's actually not difficult to change it so that you can zoom, it's just that I opted for the easier to understand case of either mounted with an automatic position and fixed fov or unmounted with both a dynamic position and fov.

I've added it to our database as a feature tweak; "#0001836: Allow dynamic zooming when camera is mounted."

- Melv.
#5
06/29/2006 (1:53 pm)
@Melv - Please do... the dismount/mount trick doesn't work well if your using a springy camera mount.
#6
06/29/2006 (10:33 pm)
@Tom - This is just a suggestion, have you considered leaving the camera unmounted and manually controlling the springyness?
#7
07/01/2006 (12:31 am)
Hey Melv,
Could you toss in camera rotation with that feature tweak...

~SG
#8
07/07/2006 (3:29 pm)
Mm... delicious camera rotation!