Bright Hub
 
Matthew Casperson's Hubfolio

Away3D Lite Programming Tutorials - Target Camera

Article by Matthew Casperson (227,413 pts )
Published on Sep 22, 2009

Learn how to use the TargetCamera3D with the standard Away3D Lite application templates.

Introduction

Away3D Lite includes 2 additional cameras other than the standard Camera3D object that is created by the template. In this tutorial we will look at the TargetCamera3D.

Code Documentation

ApplicationManager.as

First we need something to look at. Here we load the Max3DS parser, set it to scale the loaded model by 5, parse it and extract the Mesh object from the returned ObjectCollection3D. [code]

The model is then textured with a new BitmapMaterial that has had it smooth property set to true to blend the material. [code]

The mesh is then rotated so it is standing upright. [code]

Finally the mesh is added to the scene so it is visible. [code]

Away3D Lite cameras can be swapped at runtime. The first thing we need to do is create a new TargetCamera3D. We supply the focus and zoom as 10 and 100 (the defaults), and set the target of the camera to be the mesh that we just loaded. [code]

The camera is then positioned down the z axis so it can view the mesh, which is at the origin. [code]

The default templates shipped with Away3D Lite create the standard Camera3D object. To replace this default camera with our own target camera we just assign it to the views camera property. [code]

In the onPreRender function we rotate the mesh around slowly, and modify the zoom of the camera to match the slider that was added to the Flex Application GUI. [code]

A3DL_TargetCamera.mxml

We have made three changes to the MXML file from the last tutorial. The first is that the maximum framerate has been increased to 100. This lets Away3D Lite really show off its speed. [code]

Secondly we have added the Away3D Lite template using the addChildAt function, supplying 0 as the index. This ensures that the Flex GUI controls appear on top of the Away3D display. [code]

The last change is the addition of a vertical slider, which allows the user to modify the zoom of the target camera. [code]

Final Words

The Away3D Lite target camera provides a simple way to keep the view on a specific object, without having to manually update the position of the camera when the position of the target object moves.

Back to Away3D Tutorials

Related Files

Images

Screenshot

Next Article

Away3D Lite Hover CameraAway3D Lite Programming Tutorials - Hover Camera

Learn how to use the Away3D Lite hover camera to create a simple model viewing application.

Related Articles

Away3D MD2 LoadingAway3D Programming Tutorials - Loading MD2 Models

Learn how to load Quake 2 MD2 models in an Away3D application.

Search More About:

 
Follow Matthew Casperson
Receive weekly updates from Matthew Casperson
 
Bright Hub - Science & Technology Articles, Buyer's Guides, How-To Tips and Software Reviews
About Bright Hub | Contact Us | Advertise with Us | Become a Writer | RSS | Site Map | Terms of Use | Privacy Policy | Copyright Policy
©2010 Bright Hub Inc. All rights reserved. Page copy protected against web site content infringement by Copyscape