lookat
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); } } }
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
- FDT Theme Designer
- 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
Recent Comments
- Xdragosy on Ribbons
- As on What is BasicView?
- Godie_dito on Dynamic Text on a Plane
- Angel Kaido on Following line
- bambii7 on faq
- Felipe on TweenMax – Tweening a timeline (Advanced Tweening)
- Ocatarinabelachichix on about
- Rajiv on faq
- Rajiv on 3ds max texture baking for Papervision3D
- Anupam Biswas on Maya Texture Baking
Categories
| M | T | W | T | F | S | S |
|---|---|---|---|---|---|---|
| « May | ||||||
| 1 | 2 | 3 | 4 | 5 | ||
| 6 | 7 | 8 | 9 | 10 | 11 | 12 |
| 13 | 14 | 15 | 16 | 17 | 18 | 19 |
| 20 | 21 | 22 | 23 | 24 | 25 | 26 |
| 27 | 28 | 29 | 30 | |||
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


