home *** CD-ROM | disk | FTP | other *** search
/ Flash MX Savvy / FlashMX Savvy.iso / pc / MAC / Amapi3D / Amapi3DTrial_Edition / 3SPACE / MoveBehavior.js < prev    next >
Encoding:
Text File  |  2001-02-27  |  2.0 KB  |  75 lines  |  [AMAS/AMAP]

  1. // -* MoveBehavior.js *-
  2. //
  3. // Name: Move behavior
  4. // Description: 
  5. // Author:
  6. // Version: $Id: MoveBehavior.js,v 1.3 2001/02/21 11:23:41 consumer Exp $
  7. //
  8.  
  9. // Keep an array of the solids using this behavior
  10. var moveSolids = new Array(1);
  11.  
  12. function MoveBehavior(solidName, intensity, position)
  13. {
  14.   // Member methods of the behavior
  15.   this.start = MoveBehaviorStart;
  16.   this.stop = MoveBehaviorStop;
  17.  
  18.   // Member variables of the behavior
  19.   this.solidName = solidName;
  20.   this.position = position;
  21.   this.intensity = intensity * TSSolidGetMass(solidName);
  22.  
  23.   // Make a drag and a damping force
  24.   this.dragID = TSMakeUniqID("DragForce_" + solidName);
  25.   TSMakeDragForce(this.dragID, this.intensity, "0 0 0", TSMakeStringFromPoint(TSSolidGetPosition(solidName)));
  26.   this.dampID = TSMakeUniqID("DampingForce_" + solidName);
  27.   TSMakeDampingSolidForce(this.dampID, "1", "1");
  28.  
  29.   TSAppendChild(solidName, this.dragID);
  30.   TSAppendChild(solidName, this.dampID);
  31.   TSUpdateNode(solidName);
  32.   TSDropSolid(solidName);
  33. }
  34.  
  35. function MoveBehaviorStart()
  36. {
  37.     solidPosition = TSSolidGetPosition    (this.solidName) ;
  38.     translate = TSMakePointFromString (this.position) ;    
  39.     solidPosition.x = solidPosition.x + translate.x ;
  40.     solidPosition.y = solidPosition.y + translate.y ;
  41.     solidPosition.z = solidPosition.z + translate.z ;
  42.     newPosition = solidPosition.x + " " + solidPosition.y + " " + solidPosition.z ;
  43.     
  44.   TSUpdateNodeAttribute(this.dragID, "targetPoint", newPosition);
  45. }
  46.  
  47. function MoveBehaviorStop()
  48. {
  49. }
  50.  
  51. //
  52. // Event functions
  53. //
  54.  
  55. function MoveBehaviorStartEvent(obj, event)
  56. {
  57.   if (moveSolids[obj] == null) {
  58.     var speed = TSGetExtraParam(event, 'speed');
  59.     var position = TSGetExtraParam(event, 'position');
  60.     var targetSolid = TSGetExtraParam(event, 'targetSolid');
  61.  
  62.     if (targetSolid == "")
  63.       moveSolids[obj] = new MoveBehavior(obj, speed, position);
  64.     else
  65.       moveSolids[obj] = new MoveBehavior(targetSolid, speed, position);
  66.   }
  67.  
  68.   moveSolids[obj].start();
  69. }
  70.  
  71. function MoveBehaviorStopEvent(obj, event)
  72. {
  73.   moveSolids[obj].stop();
  74. }
  75.