Version User Scope of changes
Jul 26 2007, 1:23 PM EDT (current) Mihai.Trandafir 27 words added, 2 photos added, 2 photos deleted
Jul 26 2007, 1:17 PM EDT Mihai.Trandafir 1 word added, 1 word deleted, 1 photo added, 1 photo deleted

Changes

Key:  Additions   Deletions

This sample demonstrates the use of scripts to control scene items.
ScriptTest2.xpkg

Click on the image to install the sample.

Script Test 2 - Blade3D
After installing the package, an instance of the Tree class is added to the scene, as well as a floor Grid. This instance has an event, OnUpdateChanged. This means the script is activated everytime the object is updated.

Script Test 2 - Blade3D


Also, in order to enable the Update event to fire, you need to change the FireUpdate property on the Spatial tab of the Tree instance to True.


Here's is what the OnUpdateChanged event script contains.
The first line initializes a position to the world origin (0,0,0).

Vector3 pos = Vector3.Zero;


Next, a scalar value is obtained by scaling the context SceneTime (the amount of time passed since last update).

float speed = (float) context.SceneTime * 0.4f;


This scalar is the used in conjuction with Sine and Cosine, to generate a circular position on the XZ plane.

pos.X = (float) Math.Sin(speed);
pos.Z = (float) Math.Cos(speed);


It is then scaled to give a bigger (or smaller) circle.

pos *= 5;


Finally, the new position is set on the Tree's local position.

context.Spatial.Local.Translation = pos;


This makes the tree in the scene move in a circle around the floor Grid. You could try changing the '5' multiplier to make a bigger or smaller circle, or change the '0.4f' to make it circle faster or slower.