Author Topic: Zoom setting  (Read 181 times)

Fello Muz   «   on: May 28, 2012, 07:46:26 AM »
Hello,
to control the camera, I want to set the zoom. In the doc I found for Camera3D "near" and "far". How can near and far be used in the code?

Ivan Vodopiviz   «   Reply #1 on: May 28, 2012, 10:11:59 AM »
Hi,

You'll have to use the "zoom" property. Near and far define the properties of the near and far plane of the frustum.

Cheers,

Fello Muz   «   Reply #2 on: May 28, 2012, 11:29:03 AM »
Ok, thx. I tried to code like this for a GestureEvent Zoom:

if (scene.camera.near > 20){
    scene.camera.translateZ( event.scaleX );
}

if (scene.camera.far < 300){
    scene.camera.translateZ( event.scaleX );
}

Is this a good coding?

Ivan Vodopiviz   «   Reply #3 on: May 28, 2012, 12:11:19 PM »
Hi,

In general terms, you shouldn't need to change the near and far planes just to move the camera. Why not simply translate te camera with the values provided by the GestureEvent?

Fello Muz   «   Reply #4 on: May 28, 2012, 01:39:32 PM »



               
                  
                     "Hi,

In general terms, you shouldn't need to change the near and far planes just to move the camera. Why not simply translate te camera with the values provided by the GestureEvent?"
                     Ivan V.
                  

               
               

Yes sure. Maybe I have to tell that the cam should look at an object. So, if the cam is zooming in/out it should stop when it reaches a certain distance to the object. I thought far and near would be the right thing to use. Could you please help me with the code?

Fello Muz   «   Reply #5 on: May 28, 2012, 03:55:56 PM »
The cam should look at the object car:

scene.camera.near( 20 );
scene.camera.far( 300 );

function onZoom( event:TransformGestureEvent ):void
{
    scene.camera.translateZ( event.scaleX, car.dir() );
}

How about that?

Fello Muz   «   Reply #6 on: May 28, 2012, 03:57:42 PM »
Correction:
scene.camera.translateAxis( event.scaleX, car.dir() );

Ivan Vodopiviz   «   Reply #7 on: May 29, 2012, 12:03:40 PM »
Hi,

Yes, that looks much better. Please be careful when modifying the near and far plane: You're changing the drawing area of the camera, not distances. I insist with this because this can give you issues once your projects get a little more comples.

Most of the times, you won't need to change those values and even if you do, you'll most likely only do it once in your program initialization.

Regards,