public override void OnFixedUpdate()
        {
            //Restore the saved target when we are made active vessel
            if (!wasActiveVessel && vessel.isActiveVessel)
            {
                if (target != null && target.GetVessel() != null)
                {
                    FlightGlobals.fetch.SetVesselTarget(target);
                }
            }

            //notice when the user switches targets
            if (vessel.isActiveVessel && target != FlightGlobals.fetch.VesselTarget)
            {
                target = FlightGlobals.fetch.VesselTarget;
                if (target is Vessel && ((Vessel)target).LandedOrSplashed && (((Vessel)target).mainBody == vessel.mainBody))
                {
                    targetBody      = vessel.mainBody;
                    targetLatitude  = vessel.mainBody.GetLatitude(target.GetTransform().position);
                    targetLongitude = vessel.mainBody.GetLongitude(target.GetTransform().position);
                }
            }

            //Update targets that need updating:
            if (target is DirectionTarget)
            {
                ((DirectionTarget)target).Update(targetDirection);
            }
            else if (target is PositionTarget)
            {
                ((PositionTarget)target).Update(targetBody, targetLatitude, targetLongitude);
            }

            wasActiveVessel = vessel.isActiveVessel;
        }
Example #2
0
            // A method to calculate the overshoot (length of the component of the vector from the target to the actual landing position that is parallel to the vector from the start position to the target site.)
            public double GetOvershoot(EditableAngle targetLatitude, EditableAngle targetLongitude)
            {
                // Get the start, end and target positions as a set of 3d vectors that we can work with
                Vector3 end    = this.body.GetRelSurfacePosition(endPosition.latitude, endPosition.longitude, 0);
                Vector3 target = this.body.GetRelSurfacePosition(targetLatitude, targetLongitude, 0);
                Vector3 start  = this.body.GetRelSurfacePosition(startPosition.latitude, startPosition.longitude, 0);

                // First we need to get two vectors that are non orthogonal to each other and to the vector from the start to the target. TODO can we simplify this code by using Vector3.Exclude?
                Vector3 start2Target = target - start;
                Vector3 orthog1      = Vector3.Cross(start2Target, Vector3.up);

                // check for the spaecial case where start2target is parrallel to up. If it is then the result will be zero,and we need to try again
                if (orthog1 == Vector3.up)
                {
                    orthog1 = Vector3.Cross(start2Target, Vector3.forward);
                }
                Vector3 orthog2 = Vector3.Cross(start2Target, orthog1);

                // Now that we have those two orthogonal vectors, we can project any vector onto the two planes defined by them to give us the vector component that is parallel to start2Target.
                Vector3 target2end = end - target;

                Vector3 overshoot = target2end.ProjectIntoPlane(orthog1).ProjectIntoPlane(orthog2);

                // finally how long is it? We know it is parrallel to start2target, so if we add it to start2target, and then get the difference of the lengths, that should give us a positive or negative
                double overshootLength = (start2Target + overshoot).magnitude - start2Target.magnitude;

                return(overshootLength);
            }
        public void SetPositionTarget(CelestialBody body, double latitude, double longitude)
        {
            targetBody      = body;
            targetLatitude  = latitude;
            targetLongitude = longitude;

            Set(new PositionTarget(String.Format(GetPositionTargetString(), latitude, longitude)));
        }
 override public void readModuleConfiguration()
 {
     deployGear       = module_autopilot.deployGears;
     deployChutes     = module_autopilot.deployChutes;
     limitChutesStage = module_autopilot.limitChutesStage;
     touchdownSpeed   = module_autopilot.touchdownSpeed;
     if (core.target.PositionTargetExists)
     {
         landTarget      = true;
         targetLattitude = core.target.targetLatitude;
         targetLongitude = core.target.targetLongitude;
     }
 }
        public override void OnFixedUpdate()
        {
            //Restore the saved target when we are made active vessel
            if (!wasActiveVessel && vessel.isActiveVessel)
            {
                if (target != null && target.GetVessel() != null)
                {
                    vessel.targetObject = target;
                }
            }

            //notice when the user switches targets
            if (target != vessel.targetObject)
            {
                target = vessel.targetObject;
                if (target is Vessel && ((Vessel)target).LandedOrSplashed && (((Vessel)target).mainBody == vessel.mainBody))
                {
                    targetBody      = vessel.mainBody;
                    targetLatitude  = vessel.mainBody.GetLatitude(target.GetTransform().position);
                    targetLongitude = vessel.mainBody.GetLongitude(target.GetTransform().position);
                }
                if (target is CelestialBody)
                {
                    targetBody = (CelestialBody)target;
                }
            }

            // .23 temp fix until I understand better what's going on
            if (targetBody == null)
            {
                targetBody = vessel.mainBody;
            }

            //Update targets that need updating:
            if (target is DirectionTarget)
            {
                ((DirectionTarget)target).Update(targetDirection);
            }
            else if (target is PositionTarget)
            {
                ((PositionTarget)target).Update(targetBody, targetLatitude, targetLongitude);
            }

            wasActiveVessel = vessel.isActiveVessel;
        }
            // A method to calculate the overshoot (length of the component of the vector from the target to the actual landing position that is parallel to the vector from the start position to the target site.)
            public double GetOvershoot(EditableAngle targetLatitude,EditableAngle targetLongitude)
            {
                // Get the start, end and target positions as a set of 3d vectors that we can work with
                Vector3 end = this.body.GetRelSurfacePosition(endPosition.latitude, endPosition.longitude, 0);
                Vector3 target = this.body.GetRelSurfacePosition(targetLatitude, targetLongitude, 0); 
                Vector3 start = this.body.GetRelSurfacePosition(startPosition.latitude, startPosition.longitude, 0);

                // First we need to get two vectors that are non orthogonal to each other and to the vector from the start to the target. TODO can we simplify this code by using Vector3.Exclude?
                Vector3 start2Target = target - start;
                Vector3 orthog1 = Vector3.Cross(start2Target,Vector3.up);
                // check for the spaecial case where start2target is parrallel to up. If it is then the result will be zero,and we need to try again
                if(orthog1 == Vector3.up)
                {
                    orthog1 = Vector3.Cross(start2Target,Vector3.forward);
                }
                Vector3 orthog2 = Vector3.Cross(start2Target,orthog1);

                // Now that we have those two orthogonal vectors, we can project any vector onto the two planes defined by them to give us the vector component that is parallel to start2Target.
                Vector3 target2end = end - target;

                Vector3 overshoot = target2end.ProjectIntoPlane(orthog1).ProjectIntoPlane(orthog2);

                // finally how long is it? We know it is parrallel to start2target, so if we add it to start2target, and then get the difference of the lengths, that should give us a positive or negative
                double overshootLength = (start2Target+overshoot).magnitude - start2Target.magnitude;

                return overshootLength;
            }
Example #7
0
        private void moveByMeter(ref EditableAngle angle, double distance, double Alt)
        {
            double angularDelta = distance * UtilMath.Rad2Deg / (Alt + mainBody.Radius);

            angle += angularDelta;
        }
        public override void OnFixedUpdate()
        {
            //Restore the saved target when we are made active vessel
            if (!wasActiveVessel && vessel.isActiveVessel)
            {
                if (target != null && target.GetVessel() != null)
                {                    
                    FlightGlobals.fetch.SetVesselTarget(target);
                }
            }

            //notice when the user switches targets
            if (vessel.isActiveVessel && target != FlightGlobals.fetch.VesselTarget)
            {
                target = FlightGlobals.fetch.VesselTarget;
                if (target is Vessel && ((Vessel)target).LandedOrSplashed && (((Vessel)target).mainBody == vessel.mainBody))
                {
                    targetBody = vessel.mainBody;
                    targetLatitude = vessel.mainBody.GetLatitude(target.GetTransform().position);
                    targetLongitude = vessel.mainBody.GetLongitude(target.GetTransform().position);
                }
            }


            // .23 temp fix until I understand better what's going on
            if (targetBody == null)
                targetBody = vessel.mainBody;
            
            //Update targets that need updating:
            if (target is DirectionTarget) ((DirectionTarget)target).Update(targetDirection);
            else if (target is PositionTarget) ((PositionTarget)target).Update(targetBody, targetLatitude, targetLongitude);

            wasActiveVessel = vessel.isActiveVessel;
        }
 private void moveByMeter(ref EditableAngle angle, double distance, double Alt)
 {
     double angularDelta = distance * 180d / (Math.PI * (Alt + mainBody.Radius));
     angle += angularDelta;
 }
Example #10
0
        private void moveByMeter(ref EditableAngle angle, double distance, double Alt)
        {
            double angularDelta = distance * 180d / (Math.PI * (Alt + mainBody.Radius));

            angle += angularDelta;
        }