Hey Sören this examples almost does what you want - just replace the offset generated by the mouse position with one that reacts to the mouse when dragging, and you're done!
Rob On Tue, Dec 29, 2009 at 10:38 AM, Sören Meyer-Eppler <[email protected]>wrote: > I have wasted the better part of the last couple of days trying to > figure this out and still haven't found a satisfactory solution. > > I'm trying to implement a mouse controlled rotating camera like the one > in Google Earth. Pick a point on the globe and drag it to rotate the > camera around. The mouse cursor should stay put on the anchor point. You > should be able to freely rotate around the globe - the poles should not > represent a special case. > > I think the algorithm should look something like this: > 1) find the anchor point on the globe on mouseDown > 2) find the current cursor position on the globe on mouseMove > 3) calculate the angular difference between 1) and 2), i.e. get a > rotation axis via cross product and an angle via dot product > 4) rotate the camera accordingly > > What I've tried so far (with various degrees of success): > - hovercamera. Won't allow tilting across the poles. Handles weirdly at > the poles. I think the rotational model of pan/tilt is too simple for > this case. > - rotate a targetCamera using matrix math. I basically ran into the same > problems as the hovercamera. > - rotate a targetCamera using quaternions. The most promising approach > so far. Works most of the time but I still have some unpredictable > "wobbles" when moving the mouse in a straight line (in screenspace). > - create a ray via camera.unproject of the current mouse position and > the camera position and intersect that with the sphere. I had numerical > instabilities with this approach which lead to jumpy movement. > - use a virtual trackball sphere at the origin and assume the camera is > always looking right at it. Works better than the ray/sphere > intersection tried before but now I'm missing aspect ratio correction > and zoom. So my sphere is really an ellipsoid and rotations are > fast/slow depending on direction. Should be fixable. > > My main pain points are: > - rotation over the poles > - smooth movement without glitches and numerical issues > - correctly tracking the anchor point, i.e. making sure it's always > under the mouse cursor > Most examples I could find suffered from some or all of these problems > as well, yet google earth and other applications prove the problem is > perfectly solvable. > > If anyone can provide a working sample or some pointers I'll greatly > appreciate it - this problem has really gotten frustrating by now. > The question already came up on this list in 2008 and Rob wanted to > write an example, did that actually turn up anywhere? > > Help? Please? > > Sören > -- Rob Bateman Flash Development & Consultancy [email protected] www.infiniteturtles.co.uk www.away3d.com
Basic_FreeRotationGlobe.as
Description: Binary data
