home *** CD-ROM | disk | FTP | other *** search
/ Computer Active 2010 August / CA08.iso / Multimedija / shufflr.air / ShufflrClient.swf / scripts / org / papervision3d / cameras / SpringCamera3D.as < prev   
Encoding:
Text File  |  2010-06-23  |  5.4 KB  |  136 lines

  1. package org.papervision3d.cameras
  2. {
  3.    import org.papervision3d.core.math.Matrix3D;
  4.    import org.papervision3d.core.math.Number3D;
  5.    import org.papervision3d.objects.DisplayObject3D;
  6.    
  7.    public class SpringCamera3D extends Camera3D
  8.    {
  9.       public var _camTarget:DisplayObject3D;
  10.       
  11.       private var _velocity:Number3D = new Number3D();
  12.       
  13.       private var _stretch:Number3D = new Number3D();
  14.       
  15.       public var damping:Number = 4;
  16.       
  17.       public var stiffness:Number = 1;
  18.       
  19.       public var lookOffset:Number3D = new Number3D(0,2,10);
  20.       
  21.       private var _lookAtPosition:Number3D = new Number3D();
  22.       
  23.       public var positionOffset:Number3D = new Number3D(0,5,-50);
  24.       
  25.       private var _acceleration:Number3D = new Number3D();
  26.       
  27.       private var _targetTransform:Matrix3D = new Matrix3D();
  28.       
  29.       private var _desiredPosition:Number3D = new Number3D();
  30.       
  31.       private var _force:Number3D = new Number3D();
  32.       
  33.       private var _xPosition:Number3D = new Number3D();
  34.       
  35.       private var _dv:Number3D = new Number3D();
  36.       
  37.       private var _xLookOffset:Number3D = new Number3D();
  38.       
  39.       public var mass:Number = 40;
  40.       
  41.       private var _xPositionOffset:Number3D = new Number3D();
  42.       
  43.       private var _xLookAtObject:DisplayObject3D = new DisplayObject3D();
  44.       
  45.       private var _zrot:Number = 0;
  46.       
  47.       public function SpringCamera3D(param1:Number = 60, param2:Number = 10, param3:Number = 5000, param4:Boolean = false, param5:Boolean = false)
  48.       {
  49.          super(param1,param2,param3,param4,param5);
  50.       }
  51.       
  52.       override public function transformView(param1:Matrix3D = null) : void
  53.       {
  54.          if(this._camTarget != null)
  55.          {
  56.             this._targetTransform.n31 = this._camTarget.transform.n31;
  57.             this._targetTransform.n32 = this._camTarget.transform.n32;
  58.             this._targetTransform.n33 = this._camTarget.transform.n33;
  59.             this._targetTransform.n21 = this._camTarget.transform.n21;
  60.             this._targetTransform.n22 = this._camTarget.transform.n22;
  61.             this._targetTransform.n23 = this._camTarget.transform.n23;
  62.             this._targetTransform.n11 = this._camTarget.transform.n11;
  63.             this._targetTransform.n12 = this._camTarget.transform.n12;
  64.             this._targetTransform.n13 = this._camTarget.transform.n13;
  65.             this._xPositionOffset.x = this.positionOffset.x;
  66.             this._xPositionOffset.y = this.positionOffset.y;
  67.             this._xPositionOffset.z = this.positionOffset.z;
  68.             Matrix3D.multiplyVector(this._targetTransform,this._xPositionOffset);
  69.             this._xLookOffset.x = this.lookOffset.x;
  70.             this._xLookOffset.y = this.lookOffset.y;
  71.             this._xLookOffset.z = this.lookOffset.z;
  72.             Matrix3D.multiplyVector(this._targetTransform,this._xLookOffset);
  73.             this._desiredPosition.x = this._camTarget.x + this._xPositionOffset.x;
  74.             this._desiredPosition.y = this._camTarget.y + this._xPositionOffset.y;
  75.             this._desiredPosition.z = this._camTarget.z + this._xPositionOffset.z;
  76.             this._lookAtPosition.x = this._camTarget.x + this._xLookOffset.x;
  77.             this._lookAtPosition.y = this._camTarget.y + this._xLookOffset.y;
  78.             this._lookAtPosition.z = this._camTarget.z + this._xLookOffset.z;
  79.             this._stretch.x = (x - this._desiredPosition.x) * -this.stiffness;
  80.             this._stretch.y = (y - this._desiredPosition.y) * -this.stiffness;
  81.             this._stretch.z = (z - this._desiredPosition.z) * -this.stiffness;
  82.             this._dv.x = this._velocity.x * this.damping;
  83.             this._dv.y = this._velocity.y * this.damping;
  84.             this._dv.z = this._velocity.z * this.damping;
  85.             this._force.x = this._stretch.x - this._dv.x;
  86.             this._force.y = this._stretch.y - this._dv.y;
  87.             this._force.z = this._stretch.z - this._dv.z;
  88.             this._acceleration.x = this._force.x * (1 / this.mass);
  89.             this._acceleration.y = this._force.y * (1 / this.mass);
  90.             this._acceleration.z = this._force.z * (1 / this.mass);
  91.             this._velocity.plusEq(this._acceleration);
  92.             this._xPosition.x = x + this._velocity.x;
  93.             this._xPosition.y = y + this._velocity.y;
  94.             this._xPosition.z = z + this._velocity.z;
  95.             x = this._xPosition.x;
  96.             y = this._xPosition.y;
  97.             z = this._xPosition.z;
  98.             this._xLookAtObject.x = this._lookAtPosition.x;
  99.             this._xLookAtObject.y = this._lookAtPosition.y;
  100.             this._xLookAtObject.z = this._lookAtPosition.z;
  101.             lookAt(this._xLookAtObject);
  102.             if(Math.abs(this._zrot) > 0)
  103.             {
  104.                this.rotationZ = this._zrot;
  105.             }
  106.          }
  107.          super.transformView(param1);
  108.       }
  109.       
  110.       override public function get target() : DisplayObject3D
  111.       {
  112.          return this._camTarget;
  113.       }
  114.       
  115.       public function get zrot() : Number
  116.       {
  117.          return this._zrot;
  118.       }
  119.       
  120.       override public function set target(param1:DisplayObject3D) : void
  121.       {
  122.          this._camTarget = param1;
  123.       }
  124.       
  125.       public function set zrot(param1:Number) : void
  126.       {
  127.          this._zrot = param1;
  128.          if(this._zrot < 0.001)
  129.          {
  130.             param1 = 0;
  131.          }
  132.       }
  133.    }
  134. }
  135.  
  136.