home *** CD-ROM | disk | FTP | other *** search
Text File | 2001-02-20 | 2.2 KB | 102 lines | [AMAS/AMAP] |
- // -* BurnBehavior.js *-
- //
- // Name: Burn behavior
- // Description:
- // Author:
- // Version: $Id: BurnBehavior.js,v 1.8 2000/12/21 15:03:30 consumer Exp $
- //
-
- // Keep an array of the solids using this behavior
- var burnSolids = new Array(1);
-
- function BurnBehavior(solidName, textureFile, intensity)
- {
- // Member methods of the behavior
- this.start = BurnBehaviorStart;
- this.stop = BurnBehaviorStop;
-
- // Make a new burn particle system
- this.psId = TSMakeUniqID("Burn_" + solidName);
-
- MakeBurnParticleSystem(this.psId, textureFile, intensity, TSSolidGetLengthX(solidName));
- TSAppendChild(solidName, this.psId);
- TSUpdateNode(this.psId);
- }
-
- function BurnBehaviorStart(solidName)
- {
- TSUpdateNodeAttribute(this.psId, 'state', '1');
- }
-
- function BurnBehaviorStop(solidName)
- {
- TSUpdateNodeAttribute(this.psId, 'state', '0');
- }
-
- //
- // Helper function
- //
-
- function MakeBurnParticleSystem(id,
- textureFile,
- intensity,
- size)
- {
- var factor = size * intensity;
-
- var yawVar = '0';
- var pitchVar = '0';
- var initialColor = '1 0.5 0';
- var endColor = '1 1 1';
- var initialSize = new String(0.2 * factor);
- var endSize = new String(0.05 * factor);
- var speed = new String(0.001 * factor);
- var speedVariation = new String(0.0005 * factor);
- var lifeSpan = '800';
- var lifeSpanVariation = '200';
- var position = '0 0 0';
- var rotation = '0 0 0';
-
- TSMakeParticleSystem(id,
- textureFile,
- 'geometry',
- position,
- rotation,
- yawVar,
- pitchVar,
- initialColor,
- endColor,
- initialSize,
- endSize,
- speed,
- speedVariation,
- lifeSpan,
- lifeSpanVariation);
- }
-
- //
- // Event functions
- //
-
- function BurnBehaviorStartEvent(obj, event)
- {
- if (burnSolids[obj] == null) {
- var intensity = TSGetExtraParam(event, 'intensity');
- var textureFile = TSGetExtraParam(event, 'texture');
- var targetSolid = TSGetExtraParam(event, 'targetSolid');
-
- if (targetSolid == "")
- burnSolids[obj] = new BurnBehavior(obj, textureFile, intensity);
- else
- burnSolids[obj] = new BurnBehavior(targetSolid, textureFile, intensity);
-
- }
-
- burnSolids[obj].start();
- }
-
- function BurnBehaviorStopEvent(obj, event)
- {
- burnSolids[obj].stop();
- }
-