Dragging an object to rotate
The cool thing about this example is you can really just drop any DisplayObject3D in to rotate it around. It’s not super exciting, but I bet many of you will find it useful.
package { import flash.events.Event; import flash.events.MouseEvent; import flash.geom.Point; import org.papervision3d.core.math.Matrix3D; import org.papervision3d.core.math.Number3D; import org.papervision3d.lights.PointLight3D; import org.papervision3d.materials.shadematerials.FlatShadeMaterial; import org.papervision3d.objects.primitives.Sphere; import org.papervision3d.view.BasicView; [SWF(width="640", height="480", backgroundColor="#000000", frameRate="60")] public class Trackball extends BasicView { private static const FORWARD:Number3D = new Number3D(0, 0, 1); private var sphere:Sphere; private var previousMousePoint:Point = new Point(); private var isMouseDown:Boolean = false; public function Trackball() { var light:PointLight3D = new PointLight3D(); var flatShadeMaterial:FlatShadeMaterial = new FlatShadeMaterial(light, 0xcc0000, 0x222222); sphere = new Sphere(flatShadeMaterial, 500, 32, 24); scene.addChild(sphere); startRendering(); stage.addEventListener(MouseEvent.MOUSE_DOWN, stage_mouseDownHandler); stage.addEventListener(MouseEvent.MOUSE_UP, stage_mouseUpHandler); } private function stage_mouseDownHandler(event:MouseEvent):void { isMouseDown = true; } private function stage_mouseUpHandler(event:MouseEvent):void { isMouseDown = false; } override protected function onRenderTick(event:Event=null):void { var currentMousePoint:Point = new Point(viewport.containerSprite.mouseX, viewport.containerSprite.mouseY); if(isMouseDown) { var difference:Point = currentMousePoint.subtract(previousMousePoint); var vector:Number3D = new Number3D(difference.x, difference.y, 0); var rotationAxis:Number3D = Number3D.cross(vector, FORWARD); rotationAxis.normalize(); var distance:Number = Point.distance(currentMousePoint, previousMousePoint); var rotationMatrix:Matrix3D = Matrix3D.rotationMatrix(rotationAxis.x, -rotationAxis.y, rotationAxis.z, distance/250); sphere.transform.calculateMultiply3x3(rotationMatrix, sphere.transform); } previousMousePoint = currentMousePoint; super.onRenderTick(event); } } }
-
pasadena fitness boot camp
-
alternative medicine
-
online promotion tools
-
Hosting forums
-
web hosting companies
-
USB 3G
-
joomla developers
-
Affordable web hosting plans
-
Mrobinson86
-
Neoarunone
-
derkoidus
-
Dave
-
Kosta
-
Scott
-
yukimi
-
richard
-
yukimi
-
mca
-
harry
-
lwz7512
-
dada
Search
Recommended Books
Speaking at FITC Toronto
Recent Posts
- Moving to johnlindquist.com
- AsyncCommand with Robotlegs, Signals, Flight, MinimalComps
- Search Widget – Robotlegs, Signals, Flight, Minimal Comps, Yahoo Astra
- FDT Super Awesome March Deal
- haXe Tutorial
- AS3 Signals Tutorial
- Preferred Video Tutorial Resolution?
- TweenMax – Tweening a timeline (Advanced Tweening)
- Robotlegs + Flight + Union Platform
- Back in the saddle
- Eclipse Theme Designer Preview
- RobotLegs Hello World Video Tutorial
- 10 Things Every Senior Flash Developer Should Know
- Efflex – 3D Effects for Flex
- MorphController – Mighty Morphing Papervision3D
Recent Comments
- list of lpn courses on SpringCamera3D and Driving a Car
- rn to bsn in montgomery al on archive
- PowerPoint Recovery on Eclipse Theme Designer Preview
- cheat mw3 on Test if a plane is within the view of the camera (aka testing if culled)
- Goa Hotels on Looking around the inside of a Sphere
- cheat gratuit on Looking around the inside of a Sphere
- Application Development on Robotlegs + Flight + Union Platform
- nexium on Moving Faces
- buy nexium on Holy Sphere
- buy aldara online on Tweening a “moveForward()” behavior
Categories
Archives
Preferred Video Tutorial Resolution
- 1024x768 (53%, 85 Votes)
- 1280x1024 (15%, 24 Votes)
- 1920x1080 (15%, 24 Votes)
- 800x600 (13%, 20 Votes)
- 480x320 (4%, 6 Votes)
- 640x480 (0%, 2 Votes)
Total Voters: 160


