Tweening the Camera and Tweening lookAt()
This example shows how to make a target object (in this case “lookAtMe”) and have the camera target it using camera.target = lookAtMe. Also, the arrow will behave similarly by calling arrow.lookat(lookAtMe) in onRenderTick. For added effect, the light follows around lookAtMe.
package { import flash.events.Event; import gs.TweenMax; import gs.easing.Cubic; import org.papervision3d.core.proto.MaterialObject3D; import org.papervision3d.events.InteractiveScene3DEvent; import org.papervision3d.lights.PointLight3D; import org.papervision3d.materials.shadematerials.FlatShadeMaterial; import org.papervision3d.materials.shadematerials.GouraudMaterial; import org.papervision3d.objects.DisplayObject3D; import org.papervision3d.objects.primitives.Sphere; import org.papervision3d.view.BasicView; import org.pv3d.objects.Arrow; [SWF(width="640", height="480", backgroundColor="#000000", frameRate="60")] public class TweeningLookAt extends BasicView { private var arrow:Arrow; private var light:PointLight3D; private var lookAtMe:DisplayObject3D; private var lookAtTarget:DisplayObject3D; public function TweeningLookAt() { viewport.interactive = true; light = new PointLight3D(); var material:MaterialObject3D; material = new GouraudMaterial(light, 0xdddddd, 0xcc0000, 10); arrow = new Arrow(material); arrow.scale = .5; scene.addChild(arrow); for(var i:int = 0; i < 20; i++) { var randomColor:Number = Math.random() * 0x555555; var lightColor:Number = 0xdddddd; material = new FlatShadeMaterial(light, lightColor, randomColor, 10); material.interactive = true; var sphere:Sphere = new Sphere(material, 200, 6, 6); sphere.x = Math.random() * 4000 - 2000; sphere.y = Math.random() * 4000 - 2000; sphere.z = Math.random() * 2000 + 300; scene.addChild(sphere); sphere.addEventListener(InteractiveScene3DEvent.OBJECT_CLICK, sphere_objectClickHandler); sphere.lookAt(arrow); } lookAtMe = new DisplayObject3D(); lookAtMe.z = 1000; lookAtTarget = new DisplayObject3D(); camera.target = lookAtMe; scene.addChild(lookAtMe); startRendering(); } private function sphere_objectClickHandler(event:InteractiveScene3DEvent):void { lookAtTarget.copyTransform(event.displayObject3D); lookAtTarget.moveForward(500); var time:Number = 1; var tweenObject:Object = {}; tweenObject.x = lookAtTarget.x; tweenObject.y = lookAtTarget.y; tweenObject.z = lookAtTarget.z; tweenObject.ease = Cubic.easeInOut; TweenMax.to(lookAtMe, time, tweenObject); } override protected function onRenderTick(event:Event=null):void { light.x = lookAtMe.x; light.y = lookAtMe.y; light.z = lookAtMe.z; arrow.lookAt(lookAtMe); super.onRenderTick(event); } } }
No comments yet.
Leave a comment
Search
Recent Posts
- MorphController - Mighty Morphing Papervision3D
- End dump
- Test if a plane is within the view of the camera (aka testing if culled)
- Materials Reference
- Perlin Blob
- Dynamic Text on a Plane
- Maya Texture Baking
- Creating a Custom VectorVision Font
- Workshop video and example dump
- 3D Math Book Recommendation
- Heading to New York. brb ;)
- Launching Flex4.org
- Flex 4 Layouts and Groups
- Flex 4 States
- How to click on stuff in Papervision3D - Viewport, ViewportLayers, InteractiveScene3DEvent, Mouse3D, and MovieMaterial Buttons
Recent Comments
- alexxcz on MorphController - Mighty Morphing Papervision3D
- andre venancio on 3D Math Book Recommendation
- DS on Dynamic Text on a Plane
- John Lindquist on Maya Texture Baking
- Itai on Maya Texture Baking
- Javier on End dump
- samBrown on End dump
- tf on archive
- Pan on requests
- Martin Lindelöf on requests

