Exemple #1
0
        public Aabb(Vector3 center, Vector3 size)
        {
            var halfSize = size.AbsComponents() / 2f;

            min = center - halfSize;
            max = center + halfSize;
        }
 public float AngularDragResistanceAroundAxis(Vector3 axis)
 { 
     axis = axis.AbsComponents().normalized;
     var s = VSL.Geometry.BoundsSideAreas;
     return 
         Torque.x*axis.x/(s.y+s.z) +
         Torque.y*axis.y/(s.x+s.z) +
         Torque.z*axis.z/(s.y+s.x);
 }
 protected void compute_steering()
 {
     #if DEBUG
     VSL.Controls.GimbalLimit = UseGimball && VSL.PreUpdateControls.mainThrottle > 0 ? 100 : 0;
     #else
     VSL.Controls.GimbalLimit = VSL.PreUpdateControls.mainThrottle > 0? 100 : 0;
     #endif
     if (rotation_axis.IsZero())
     {
         return;
     }
     var AV                = get_angular_velocity();
     var AM                = Vector3.Scale(AV, VSL.Physics.MoI);
     var angular_error     = VSL.Controls.AttitudeError / 180;
     var abs_rotation_axis = rotation_axis.AbsComponents();
     var ErrV              = angular_error * abs_rotation_axis;
     var iErr              = Vector3.one - ErrV;
     var MaxAA             = VSL.Torque.Slow ?
                             VSL.Torque.Instant.AA + VSL.Torque.SlowMaxPossible.AA * Mathf.Min(VSL.PreUpdateControls.mainThrottle, VSL.OnPlanetParams.GeeVSF) :
                             VSL.Torque.MaxCurrent.AA;
     MaxAA_Filter.Tau = (1 - Mathf.Sqrt(angular_error)) * C.AALowPassF;
     MaxAA            = MaxAA_Filter.Update(MaxAA);
     var iMaxAA = MaxAA.Inverse(0);
     if (VSL.Torque.Slow)
     {
         pid_pitch.Tune(AV.x, AM.x, MaxAA.x, iMaxAA.x, ErrV.x, iErr.x,
                        MaxAA.x > 0 ? VSL.Torque.Instant.AA.x / MaxAA.x : 1,
                        VSL.Torque.EnginesResponseTime.x,
                        VSL.Torque.MaxPossible.SpecificTorque.x);
         pid_roll.Tune(AV.y, AM.y, MaxAA.y, iMaxAA.y, ErrV.y, iErr.y,
                       MaxAA.y > 0 ? VSL.Torque.Instant.AA.y / MaxAA.y : 1,
                       VSL.Torque.EnginesResponseTime.y,
                       VSL.Torque.MaxPossible.SpecificTorque.y);
         pid_yaw.Tune(AV.z, AM.z, MaxAA.z, iMaxAA.z, ErrV.z, iErr.z,
                      MaxAA.z > 0 ? VSL.Torque.Instant.AA.z / MaxAA.z : 1,
                      VSL.Torque.EnginesResponseTime.z,
                      VSL.Torque.MaxPossible.SpecificTorque.z);
     }
     else
     {
         pid_pitch.TuneFast(AV.x, AM.x, MaxAA.x, iMaxAA.x, iErr.x);
         pid_roll.TuneFast(AV.y, AM.y, MaxAA.y, iMaxAA.y, iErr.y);
         pid_yaw.TuneFast(AV.z, AM.z, MaxAA.z, iMaxAA.z, iErr.z);
     }
     pid_pitch.atPID.Update(ErrV.x * Mathf.PI, -AV.x * Mathf.Sign(rotation_axis.x));
     pid_roll.atPID.Update(ErrV.y * Mathf.PI, -AV.y * Mathf.Sign(rotation_axis.y));
     pid_yaw.atPID.Update(ErrV.z * Mathf.PI, -AV.z * Mathf.Sign(rotation_axis.z));
     var avErr = compute_av_error(AV, angular_error);
     steering = new Vector3(pid_pitch.UpdateAV(avErr.x), pid_roll.UpdateAV(avErr.y), pid_yaw.UpdateAV(avErr.z));
     correct_steering();
 }
 public float AngularAccelerationAroundAxis(Vector3 axis)
 {
     return(Mathf.Abs(Vector3.Dot(AA, axis.AbsComponents().normalized)));
 }