//SIMPLE3DWORLD CLASS
/*--------------------------------------------
constructor for Simple 3D World Object
---------------------------------------------*/
//STARTMOVE & STOPMOVIE SCRIPTS
//global start and stop movie functions
//these are provided by director
function startmovie() {
//create an object to setup and control
//the 3D world. Pass it which sprite number
//the 3D cast member is in.
_global.o3D WorldObject = new Simple3DWorld(
"sphereWorld",
1);
}
function Simple3DWorld(sName, iSpriteNum) {
//set basic props
this.sName = sName;
this.iSpriteNum = iSpriteNum;
this.ThreeDSprite = sprite(iSpriteNum);
this.ThreeDWorld = sprite(iSpriteNum).member;
this.mSphereSetup(); //create a sphere
this.mCameraSetup(); //position camera
}
/*--------------------------------------------
Simple3DWorld::SphereSetup
creates a sphere at 0,0,0 with radius 200
---------------------------------------------*/
Simple3DWorld.prototype.mSphereSetup = function() {
//create a template (model resource)
//for how to build a spheres
this.mrSphere = this.ThreeDWorld.newModelResource(
this.sName + "_model_resource",
symbol("sphere"));
//fill out properties of the template
this.mrSphere.radius = 200;
this.mrSphere.startAngle = 0.000;
this.mrSphere.endAngle = 360.000;
this.mrSphere.resolution = 50;
//build a sphere in the world
this.mSphere = this.ThreeDWorld.newModel(
this.a_sName + "_model",
this.mrSphere);
//set its position in the world
this.mSphere.transform.position = vector(0,0,0);
}
/*--------------------------------------------
Simple3DWorld::CameraSetup
positions the camera at XYZ 0,200,800, pointed
at the origin
---------------------------------------------*/
Simple3DWorld.prototype.mCameraSetup = function() {
var vCamPos = vector(0,200,800); //cam position
var vLookPos = vector(0,0,0); //lookat position
var vUp = vector(0,1,0); //"up" orientation
//get a handle to the default camera created by S3D
this.oCamera = this.ThreeDWorld.getProp("camera", 1);
//set its world position
this.oCamera.transform.position = vCamPos;
//point it at the origin, with no rotation along
//its local Z axis (vUp matches world-space up)
this.oCamera.pointAt(vLookPos, vUp);
}
/*--------------------------------------------
Simple3DWorld::Update
called per frame to animate camera in a
simple loop
---------------------------------------------*/
Simple3DWorld.prototype.mUpdate = function() {
//rotate the camera around the Y-axius
//2 degrees per frame, using world coordinate
//space.
this.oCamera.rotate(0,2,0,symbol("world"));
}
function stopmovie() {
//clean up after ourselves, reset the world
//to an empty one, and clear all globals
_global.o3DWorldObject.mResetWorlds();
_global.clearGlobals();
}
/*--------------------------------------------
Simple3DWorld::ResetWorlds
called on movie destruction, resets the 3D
castmember to its original state.
---------------------------------------------*/
Simple3DWorld.prototype.mResetWorlds = function() {
this.ThreeDWorld.resetWorld();
}
//EXITFRAME LOOP
//called once per frame
function exitFrame() {
//rotate the camera in the 3D world
_global.o3DWorldObject.mUpdate();
//loop back to this frame again
_movie.go(_movie.frame);
}