Zoom in to point

Software: Away3D 4.x

frank_, Newbie
Posted: 23 July 2012 02:55 PM   Total Posts: 12

I’m working on adding a zoom to mouse feature in away3d 4.

I’m performing the zoom by changing the FOV of the camera

stage.addEventListener(MouseEvent.MOUSE_WHEELhandleZoom);  

protected function 
handleZoom(e:MouseEvent):void{
    
var l:PerspectiveLens view.camera.lens as PerspectiveLens;
    
l.fieldOfView -= e.delta;
  

This seems to be working well.

I’m now wondering how to take this and have the camera zoom in on the mouse x/y.

I’m using a HoverController with my cam

controller = new HoverController(camnull03601500, -9090NaNNaN81false

I’ve tried cam.moveTo(mouseX, mouseY, cam.z) but that approach does not seem to work.

Whats the best way go about doing this?

Thanks!

   

Avatar
oladitan, Member
Posted: 24 July 2012 12:11 AM   Total Posts: 71   [ # 1 ]

did you try making the distance parameter of the hovercam a public variable variableName:Number; and adusting that variable. I think that will work if you call

controller.update(); 

in the onEnterFrame function.

   

Richard Olsson, Administrator
Posted: 24 July 2012 08:14 AM   Total Posts: 1192   [ # 2 ]

If you want to zoom into a particular point in view space (along a ray in 3D space) you should probably not be using the hover controller, at least not while zooming, because the hover controller will dictate where the camera points to.

Because of how 3D perspective work, you can’t zoom into a certain point of the 2D view plane (or at least not easily, nor is it desirable). It would create rather weird perspective, sort of as if you took a photo where the vanishing point is in the center and then cropped and zoomed into the top left corner of it in Photoshop. As you can imagine, that will leave you with a rather odd perspective.

Instead, what you have to do, is lock the orientation of the camera when the user starts zooming, but move it along it’s local X/Y axes (e.g. using moveLeft(), moveRight(), moveUp(), moveDown()) to re-align around the mouse position. The math probably doesn’t need to be perfect, so you can probably do just a basic estimation of where the camera should be every frame, and animate it towards that point. At the same time, change the FOV as you have suggested to get the zoom effect you’re after.

This will prove problematic with the hover controller, because even if you stop updating while zooming, as soon as you resume updating the controller it will snap back to look at the lookAtTarget.

Another way that you may be able to achieve it using the HoverController though is to have a dummy look-at target (e.g. an empty container) and when the user zooms towards some off-center point you move the target towards that point. When it’s time to go back, you just animate the target back to it’s center-position.

It’s hard to give a great explanation when I have no references to what exactly it is that you’re doing. If the above comes off as confusing, please provide a more in-depth explanation of your project, what it is that you’re displaying, why you are using the hover controller et c, which might help us give better explanations.

   

frank_, Newbie
Posted: 24 July 2012 01:34 PM   Total Posts: 12   [ # 3 ]

Thanks for your reply. The idea of making some geometry and using look at seems like it may work. I’m going to try to work on that implementation.

A bit about what I’m trying to do:

I have a collection of geometry that in my case represents a building. I’m using a HoverControler to allow the user to rotate around the building. I have zoom implemented on mouse wheel.

The next steps will be to implement pan and zoom to point functionality. The goal of zoom is to take the users mouse X/Y and recenter the model around that point. This will give the user the ability to zoom in to a specific point on the model.

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X