Script Test 2This is a featured page


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.


Mihai.Trandafir
Mihai.Trandafir
Latest page update: made by Mihai.Trandafir , Jul 26 2007, 1:23 PM EDT (about this update About This Update Mihai.Trandafir Edited by Mihai.Trandafir

27 words added
2 images added
2 images deleted

view changes

- complete history)
Keyword tags: None
More Info: links to this page
There are no threads for this page.  Be the first to start a new thread.