Zoom in/out a container3D using the mousewheel event

Software: Away3D 3.x

apalabrados, Newbie
Posted: 25 September 2013 06:43 PM   Total Posts: 13

Hi,

  I have a scene with a primitive within a Container3D and wish to be able to use the MouseWheel event for Zoom In/Out such container.

  The fact is that I can not guess how to accomplish this.

  I have the following code:

private function MouseWheel(event:MouseEvent):void {
  var distance_old:Number = distance;
  distance   -= event.delta*4;
 
  if ( (distance - camera.distance) / zoomSpeed > 0 ) {
  container.scaleX=container.scaleY=container.scaleZ = (distance - camera.distance) / zoomSpeed;
  } else distance = distance_old;
 
  }

But the transitions when moving the wheel are strong and Horrible and sometimes do not work. The behavior is strange.

What’s wrong?

   

Avatar
SharpEdge, Member
Posted: 27 September 2013 07:50 AM   Total Posts: 94   [ # 1 ]

If you want smooth movements you should do them in the loop and not in the mouseWheelHandler function, so when you catch the mouse event change a var and set it to your final position, then in the loop apply that value smoothly, a little each frame using deltaTime and some Lerp function.

   

apalabrados, Newbie
Posted: 27 September 2013 10:15 AM   Total Posts: 13   [ # 2 ]

Ok, I see, but, could you please post here some code I could use. The fact is that my problem is that I do not know the way to do it.

thanks.

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X