Beispiel #1
0
        public LandingPrediction predictLandPosition()
        {
            VesselController.updateBodyPosition();
            var   currentPosition = VesselController.getPosition();
            var   currentVelocity = VesselController.getVelocity();
            float stepsize        = 0.01f;
            float time            = 0.0f;

            while (VesselController.getAltitudeAtPoint(currentPosition) > 0)
            {
                var normalizedVelocity = currentVelocity;
                normalizedVelocity.Normalize();
                currentPosition += currentVelocity * stepsize;
                currentVelocity += -normalizedVelocity * stepsize * (float)VesselController.getDrag()
                                   * (float)calculateDynamicPressure(VesselController.getAltitudeAtPoint(currentPosition), currentVelocity.Length());
                currentVelocity += VesselController.getGravityAtPoint(currentPosition) * stepsize;
                time            += stepsize;
            }
            return(new LandingPrediction()
            {
                Position = currentPosition,
                Velocity = currentVelocity,
                TimeLeft = time
            });
        }
        public void update()
        {
            VesselController.updateBodyPosition();
            var quat = VesselController.getOrientation();

            var shipup      = Vector3.Transform(new Vector3(1.0f, 0.0f, 0.0f), quat);
            var shipleft    = Vector3.Transform(new Vector3(0.0f, 0.0f, 1.0f), quat);
            var shipforward = Vector3.Transform(new Vector3(0.0f, 1.0f, 0.0f), quat);

            var fdir = shipforward + targetDirection * 1.1f;

            fdir.Normalize();

            float xt = -Vector3.Dot(shipup, fdir);
            float yt = -Vector3.Dot(shipleft, fdir);
            float zt = -Vector3.Dot(shipup, Vector3.UnitX);

            //VesselController.setYaw((float)clamp(xt * 0.1, -0.1, 0.1));
            //VesselController.setPitch((float)clamp(-yt * 0.1, -0.1, 0.1));
            VesselController.setYaw((float)clamp(orientationYawContoller.Calculate(0.0, xt), -1.0, 1.0));
            VesselController.setPitch((float)clamp(-orientationPitchContoller.Calculate(0.0, yt), -1.0, 1.0));
            VesselController.setRoll((float)clamp(orientationRollContoller.Calculate(0.0, zt), -1.0, 1.0));
            //  Console.WriteLine(VesselController.getAngularVelocity().X);
            //  Console.WriteLine(VesselController.getAngularVelocity().Y);
            //  Console.WriteLine(VesselController.getAngularVelocity().Z);
            //  Console.WriteLine(" ");
        }