コード例 #1
0
 void MaintainRotationY(double secs)
 {
     if ((!IsOnGround() || TrackSpeed == 0) && Keyboard.IsDown(System.Windows.Input.Key.A, System.Windows.Input.Key.D))
     {
         //DesiredRotationY = Math.PI / 2;
         if (Keyboard.IsDown(System.Windows.Input.Key.A) && !Keyboard.IsDown(System.Windows.Input.Key.D))
         {
             DesiredRotationY = Math.PI;
         }
         if (Keyboard.IsDown(System.Windows.Input.Key.D) && !Keyboard.IsDown(System.Windows.Input.Key.A))
         {
             DesiredRotationY = 0;
         }
     }
     NextRotationY = RotationY;
     MyLib.SmoothTo(ref NextRotationY, DesiredRotationY, secs, Math.Max(Math.Abs(DesiredRotationY - RotationY) / Math.PI, 0.2) * 0.2);
 }
コード例 #2
0
 public Body() : base()
 {
     propeller.IsOnGround = () => IsOnGround();
     Kernel.Heart.Beat1  += (secs) =>
     {
         //if (IsOnGround()) System.Diagnostics.Trace.WriteLine("A");
         MaintainRotationY(secs);
         MaintainRotationZ(secs);
         //drill.Folding = System.Math.Abs(System.DateTime.Now.Ticks % 100000000 - 50000000) / 50000000.0;
         {
             RB.position.Z = RB.velocity.Z = 0;
             RB.force      = new Vector3D();
             RigidBodyUpdating?.Invoke(secs, RB);
             RB.force += new Vector3D(0, -RB.mass * Constants.Gravity, 0);
             RB.force += new Vector3D(-Math.Sin(RB.theta) * propeller.LiftForce(), Math.Cos(RB.theta) * propeller.LiftForce(), 0);
             NextRB    = new RigidBody(RB);
             MaintainRigidBody(secs);
         }
         {
             double frictionAcceleration = (TrackSpeed > 0 ? -1 : 1) * (TrackFriction /*+ 0.5 * Math.Abs(TrackSpeed)*/);
             double acceleration         = 0;
             if (IsOnGround() && Keyboard.IsDown(System.Windows.Input.Key.A, System.Windows.Input.Key.D))
             {
                 if (!Keyboard.IsDown(RotationY > Math.PI / 2 ? System.Windows.Input.Key.D : System.Windows.Input.Key.A))
                 {
                     acceleration += Math.Min(MaxTrackAcceleration, MaxTrackPower / Math.Max(Math.Abs(TrackSpeed), double.MinValue));
                 }
                 else
                 {
                     frictionAcceleration += (TrackSpeed > 0 ? -1 : 1) * MaxTrackAcceleration;
                 }
             }
             NextTrackSpeed  = TrackSpeed;
             NextTrackSpeed += acceleration * secs;
             if ((NextTrackSpeed > 0) != (NextTrackSpeed + frictionAcceleration * secs > 0))
             {
                 NextTrackSpeed = 0;
             }
             else
             {
                 NextTrackSpeed += frictionAcceleration * secs;
             }
         }
         const double lookOffset = 1.3;
         MyLib.SmoothTo(ref Kernel.CameraProperties.position, RB.position + new Vector3D(0, 0, 30 / Math.Pow(0.4 + SetZ(RB.position - Kernel.CameraProperties.position, 0).Length * 0.1, 0.5)), secs, 0.2);
         var target = RB.position + 0.1 * RB.velocity - Kernel.CameraProperties.position;
         target /= Math.Abs(target.Z);
         var len       = Math.Sqrt(Math.Pow(target.X, 2) + Math.Pow(target.Y, 2));
         var targetLen = Math.Min(len, lookOffset);
         target.X *= targetLen / len;
         target.Y *= targetLen / len;
         MyLib.SmoothTo(ref Kernel.CameraProperties.lookDirection, target, secs, 0.2);
         //this.Folding = 1;
         //for(int i=0;i<1;i++)
         {
             var color    = (byte)MyLib.Rand.Next(200, 210);
             var position = RB.position + new Vector3D(-Math.Cos(RotationY) * 1, 1, MyLib.Rand.NextDouble() / 2 + 0.5);
             var speed    = new Vector3D(2 * -Math.Cos(RotationY) + MyLib.Rand.NextDouble() - 0.5, 5 + MyLib.Rand.NextDouble() - 0.5, 0);
             Fumes.Instance.AddFums(position, speed
                                    , Color.FromArgb(50, color, color, color)
                                    , 0.1, 2, 2, speed.Length * 1.5);
         }
     };
     Kernel.Heart.Beat2 += () =>
     {
         RotationY = NextRotationY;
         MyLib.Set(SubTransforms, TransformIndexRotateAroundY, true).RotatePrepend(new Vector3D(0, -1, 0), RotationY).Done();
         MyLib.Set(SubTransforms, TransformIndexRotateAroundZ, true).RotatePrepend(new Vector3D(0, 0, 1), RB.theta).Done();
         RB              = NextRB;
         TrackSpeed      = NextTrackSpeed;
         OriginTransform = MyLib.Transform(new MatrixTransform3D()).Translate(RB.position - new Point3D()).Value;
         UpdateTransform();
     };
 }