public override void OnUpdate()
        {
            CelestialBody body = this.vessel.mainBody;

            if (body == null)
            {
                return;
            }

            var BaseT = this.part.transform.FindChild("model");

            if (!String.IsNullOrEmpty(PartTransform))
            {
                BaseT = BaseT.FindChild(PartTransform);
            }

            BaseT = BaseT.FindChild(BaseTransform);

            Vector3 bodyCoords = BaseT.InverseTransformPoint(body.transform.position);
            Vector2 pos        = Misc.CartesianToPolar(bodyCoords);

            var alpha = (float)Misc.NormalizeAngle(pos.x + 90);
            var beta  = (float)Misc.NormalizeAngle(pos.y);

            Transform RotH = BaseT.FindChild(HeadingTransform);
            Transform RotV = RotH.FindChild(ElevationTransform);

            if (Math.Abs(RotH.localEulerAngles.y - beta) > 90)
            {
                beta += 180;
                alpha = 360 - alpha;
            }

            var speed = Time.deltaTime * PowerRatio * 60;

            RotH.localRotation = Quaternion.RotateTowards(RotH.localRotation, Quaternion.AngleAxis(beta, new Vector3(0, 1, 0)), speed);
            RotV.localRotation = Quaternion.RotateTowards(RotV.localRotation, Quaternion.AngleAxis(alpha, new Vector3(1, 0, 0)), speed);

            if (float.IsNaN(RotH.localRotation.w))
            {
                RotH.localRotation = Quaternion.identity;
            }
            if (float.IsNaN(RotV.localRotation.w))
            {
                RotV.localRotation = Quaternion.identity;
            }
        }
Exemple #2
0
        public override void OnUpdate()
        {
            Events["EnableDetection"].active  = !IsDetecting;
            Events["DisableDetection"].active = IsDetecting;
            var controller = KethaneController.GetInstance(this.vessel);

            Events["ShowMap"].active = !controller.ShowDetectorWindow;
            Events["HideMap"].active = controller.ShowDetectorWindow;

            if (Misc.GetTrueAltitude(vessel) <= this.DetectingHeight)
            {
                if (IsDetecting)
                {
                    Status = powerRatio > 0 ? "Active" : "Insufficient Power";
                }
                else
                {
                    Status = "Idle";
                }
            }
            else
            {
                Status = "Out Of Range";
            }

            CelestialBody body = this.vessel.mainBody;

            if (body == null)
            {
                return;
            }

            var BaseT = this.part.transform.FindChild("model");

            if (!String.IsNullOrEmpty(PartTransform))
            {
                BaseT = BaseT.FindChild(PartTransform);
            }

            BaseT = BaseT.FindChild(BaseTransform);

            Vector3 bodyCoords = BaseT.InverseTransformPoint(body.transform.position);
            Vector2 pos        = Misc.CartesianToPolar(bodyCoords);

            var alpha = (float)Misc.NormalizeAngle(pos.x + 90);
            var beta  = (float)Misc.NormalizeAngle(pos.y);

            Transform RotH = BaseT.FindChild(HeadingTransform);
            Transform RotV = RotH.FindChild(ElevationTransform);

            if (Math.Abs(RotH.localEulerAngles.y - beta) > 90)
            {
                beta += 180;
                alpha = 360 - alpha;
            }

            var speed = Time.deltaTime * this.powerRatio * 60;

            RotH.localRotation = Quaternion.RotateTowards(RotH.localRotation, Quaternion.AngleAxis(beta, new Vector3(0, 1, 0)), speed);
            RotV.localRotation = Quaternion.RotateTowards(RotV.localRotation, Quaternion.AngleAxis(alpha, new Vector3(1, 0, 0)), speed);

            if (float.IsNaN(RotH.localRotation.w))
            {
                RotH.localRotation = Quaternion.identity;
            }
            if (float.IsNaN(RotV.localRotation.w))
            {
                RotV.localRotation = Quaternion.identity;
            }
        }