Spot Light Tutorial
|
|
|
Tweet |
To view this page ensure that Adobe Flash Player version 11.0.0 or greater is installed.
package
{
import com.yogurt3d.Yogurt3D;
import com.yogurt3d.core.events.Yogurt3DEvent;
import com.yogurt3d.core.lights.Light;
import com.yogurt3d.core.lights.RenderableLight;
import com.yogurt3d.core.materials.MaterialDiffuseFill;
import com.yogurt3d.presets.primitives.sceneobjects.PlaneSceneObject;
import com.yogurt3d.core.managers.tickmanager.TickManager;
import com.yogurt3d.core.managers.tickmanager.TimeInfo;
import com.yogurt3d.core.objects.interfaces.ITickedObject;
import flash.display.Sprite;
import flash.events.Event;
import flash.geom.Vector3D;
[SWF(width="400", height="300")]
public class SpotLightTutorial extends Sprite implements ITickedObject
{
var spot1:Light;
var spot2:RenderableLight;
// starting point: initialize the Yogurt3D engine
public function SpotLightTutorial()
{
Yogurt3D.instance.addEventListener( Yogurt3DEvent.READY, onContextReady );
Yogurt3D.instance.init( this.stage );
}
// Create the scene and start rendering when the Context3D is ready
public function onContextReady( _e:Event ):void{
// Initialize the Yogurt3D engine with the default setup (scene, camera, renderer etc.)
Yogurt3D.instance.defaultSetup(400,300);
// change the background color of the scene to Yogurt3D blue
Yogurt3D.instance.defaultScene.sceneColor = 0x6b9cc4;
// create a 10 by 10 plane to be served as the ground
// it lies on the y = 0 plane by default
var ground:PlaneSceneObject = new PlaneSceneObject(10,10);
// set its colro to light brown
ground.material = new MaterialDiffuseFill( 0xFFFFFF);
Yogurt3D.instance.defaultScene.addChild( ground);
// Camera Setup
// We already have the default camera on the scene. Elevate the camera a little bit from the ground and let it look at to the origin
Yogurt3D.instance.defaultCamera.transformation.position = new Vector3D( 8, 10, 8 );
Yogurt3D.instance.defaultCamera.transformation.lookAt( new Vector3D );
// Adding the Spot Light
// create the first spot light with a yellowish color
spot1 = new Light( Light.SPOT_LIGHT, 0xffea00, 1);
// set the position of the light source
spot1.transformation.position = new Vector3D(5,5,-5);
// and it is directed to the scene origin
spot1.transformation.lookAt(new Vector3D(0,0,0));
spot1.innerConeAngle = 20;
spot1.outerConeAngle = 30;
// add the newly created light object to the scene
Yogurt3D.instance.defaultScene.addChild( spot1 );
// Let's add a second spot light, this time using RenderableLight class.
// RenderableLight is same as the Light class except that the light source is visible
// This is highly useful for development/debugging purposes.
spot2 = new RenderableLight(Light.SPOT_LIGHT, 0xd957c2); // create as a purple spot light
spot2.transformation.position = new Vector3D(0,5,0); // hangs just above the origin
spot2.light.innerConeAngle = 20;
spot2.light.outerConeAngle = 30;
// looking at the origin again (we will add a little animation on this one)
spot2.transformation.lookAt( new Vector3D );
// add the light to the scene
Yogurt3D.instance.defaultScene.addChild( spot2 );
// Now we are ready to render the scene
// start the rendering
Yogurt3D.instance.startAutoUpdate();
// register the Y3D_TimingTest object to the Tick Manager
TickManager.registerObject( this );
}
// this is called before rendering each frame
// we want to animate spot2 (the purple renderable spot)
public function updateWithTimeInfo(_timeInfo:TimeInfo):void{
// change the direction of the light according to the objectTime info
spot2.transformation.lookAt(new Vector3D(Math.sin( _timeInfo.objectTime / 1000 ) * 5, 0, Math.sin( _timeInfo.objectTime / 1000 ) * 5));
}
}
}
New Version with Stage3D
Yogurt3D v2.1
About Yogurt3D
Yogurt3D Game Engine is a state of the art Actionscript 3.0 library for developing 3D applications on Adobe Flash Platform. We claim it is possible to create in-browser 3D games without any plug-in installation. Its animation system, model formats, exporter plug-ins for modelling tools, scene hierarchy and scene management structure, and that it is developed with a game developer perspective, makes Yogurt3D a powerful tool for 3D game developers.
If you wish to target both casual and seasoned players with browser-based real-time 3D games on the web, Yogurt 3D Game Engine is the ultimate tool to choose.
About Yogurt Technologies
Yoğurt Technologies was founded in 1997 by a group of artists and computer engineers.
For 10 years the group worked as a new media agency producing technology for other companies.
In 2007, the decision to focus on its own products was taken as Yoğurt members foresaw that 3D would be the next big thing on the web. Thus, the company now produces 3D tools that will be available to anyone who wants to try a hand on 3D content.
