void CamWindow(int windowID)
        {
            if (!TargetingCamera.Instance)
            {
                return;
            }

            windowIsOpen = true;

            GUI.DragWindow(new Rect(0, 0, camImageSize + 16, camImageSize + 8));

            Rect imageRect = new Rect(8, 20, camImageSize, camImageSize);

            GUI.DrawTexture(imageRect, TargetingCamera.Instance.targetCamRenderTexture, ScaleMode.StretchToFill, false);
            GUI.DrawTexture(imageRect, TargetingCamera.Instance.ReticleTexture, ScaleMode.StretchToFill, true);

            float controlsStartY = 24 + camImageSize + 4;

            //slew buttons
            float slewStartX    = 8;
            float slewSize      = (controlPanelHeight / 3) - 8;
            Rect  slewUpRect    = new Rect(slewStartX + slewSize, controlsStartY, slewSize, slewSize);
            Rect  slewDownRect  = new Rect(slewStartX + slewSize, controlsStartY + (2 * slewSize), slewSize, slewSize);
            Rect  slewLeftRect  = new Rect(slewStartX, controlsStartY + slewSize, slewSize, slewSize);
            Rect  slewRightRect = new Rect(slewStartX + (2 * slewSize), controlsStartY + slewSize, slewSize, slewSize);

            if (GUI.RepeatButton(slewUpRect, "^", HighLogic.Skin.button))
            {
                //SlewCamera(Vector3.up);
                slewInput.y = 1;
            }
            if (GUI.RepeatButton(slewDownRect, "v", HighLogic.Skin.button))
            {
                //SlewCamera(Vector3.down);
                slewInput.y = -1;
            }
            if (GUI.RepeatButton(slewLeftRect, "<", HighLogic.Skin.button))
            {
                //SlewCamera(Vector3.left);
                slewInput.x = -1;
            }
            if (GUI.RepeatButton(slewRightRect, ">", HighLogic.Skin.button))
            {
                //SlewCamera(Vector3.right);
                slewInput.x = 1;
            }

            //zoom buttons
            float    zoomStartX    = 8 + (3 * slewSize) + 4;
            Rect     zoomInRect    = new Rect(zoomStartX, controlsStartY, 3 * slewSize, slewSize);
            Rect     zoomOutRect   = new Rect(zoomStartX, controlsStartY + (2 * slewSize), 3 * slewSize, slewSize);
            GUIStyle disabledStyle = new GUIStyle();

            disabledStyle.alignment        = TextAnchor.MiddleCenter;
            disabledStyle.normal.textColor = Color.white;
            if (currentFovIndex < zoomFovs.Length - 1)
            {
                if (GUI.Button(zoomInRect, "In", HighLogic.Skin.button))
                {
                    ZoomIn();
                }
            }
            else
            {
                GUI.Label(zoomInRect, "(In)", disabledStyle);
            }
            if (currentFovIndex > 0)
            {
                if (GUI.Button(zoomOutRect, "Out", HighLogic.Skin.button))
                {
                    ZoomOut();
                }
            }
            else
            {
                GUI.Label(zoomOutRect, "(Out)", disabledStyle);
            }
            Rect     zoomInfoRect  = new Rect(zoomStartX, controlsStartY + slewSize, 3 * slewSize, slewSize);
            GUIStyle zoomInfoStyle = new GUIStyle(HighLogic.Skin.box);

            zoomInfoStyle.fontSize = 12;
            zoomInfoStyle.wordWrap = false;
            GUI.Label(zoomInfoRect, "Zoom " + (currentFovIndex + 1).ToString(), zoomInfoStyle);

            GUIStyle dataStyle = new GUIStyle();

            dataStyle.alignment        = TextAnchor.MiddleCenter;
            dataStyle.normal.textColor = Color.white;

            //groundStablize button
            float stabilStartX  = zoomStartX + zoomInRect.width + 4;
            Rect  stabilizeRect = new Rect(stabilStartX, controlsStartY, 3 * slewSize, 3 * slewSize);

            if (!groundStabilized)
            {
                if (GUI.Button(stabilizeRect, "Lock\nTarget", HighLogic.Skin.button))
                {
                    GroundStabilize();
                }
            }
            else
            {
                if (GUI.Button(new Rect(stabilizeRect.x, stabilizeRect.y, stabilizeRect.width, stabilizeRect.height / 2), "Unlock", HighLogic.Skin.button))
                {
                    ClearTarget();
                }
                if (weaponManager)
                {
                    GUIStyle gpsStyle = new GUIStyle(HighLogic.Skin.button);
                    gpsStyle.fontSize = 10;
                    if (GUI.Button(new Rect(stabilizeRect.x, stabilizeRect.y + (stabilizeRect.height / 2), stabilizeRect.width, stabilizeRect.height / 2), "Send GPS", gpsStyle))
                    {
                        SendGPS();
                    }
                }

                if (!gimbalLimitReached)
                {
                    //open square
                    float oSqrSize = (24f / 512f) * camImageSize;
                    Rect  oSqrRect = new Rect(imageRect.x + (camImageSize / 2) - (oSqrSize / 2), imageRect.y + (camImageSize / 2) - (oSqrSize / 2), oSqrSize, oSqrSize);
                    GUI.DrawTexture(oSqrRect, BDArmorySettings.Instance.openWhiteSquareTexture, ScaleMode.StretchToFill, true);
                }

                //geo data
                Rect   geoRect  = new Rect(imageRect.x, (camImageSize * 0.94f), camImageSize, 14);
                string geoLabel = Misc.FormattedGeoPos(bodyRelativeGTP, false);
                GUI.Label(geoRect, geoLabel, dataStyle);

                //target data
                dataStyle.fontSize = 16;
                float  dataStartX      = stabilStartX + stabilizeRect.width + 8;
                Rect   targetRangeRect = new Rect(imageRect.x, (camImageSize * 0.94f) - 18, camImageSize, 18);
                float  targetRange     = Vector3.Distance(groundTargetPosition, transform.position);
                string rangeString     = "Range: " + targetRange.ToString("0.0") + "m";
                GUI.Label(targetRangeRect, rangeString, dataStyle);

                //laser ranging indicator
                dataStyle.fontSize = 18;
                string lrLabel = surfaceDetected ? "LR" : "NO LR";
                Rect   lrRect  = new Rect(imageRect.x, imageRect.y + (camImageSize * 0.65f), camImageSize, 20);
                GUI.Label(lrRect, lrLabel, dataStyle);

                //azimuth and elevation indicator //UNFINISHED

                /*
                 * Vector2 azielPos = TargetAzimuthElevationScreenPos(imageRect, groundTargetPosition, 4);
                 * Rect azielRect = new Rect(azielPos.x, azielPos.y, 4, 4);
                 * GUI.DrawTexture(azielRect, BDArmorySettings.Instance.whiteSquareTexture, ScaleMode.StretchToFill, true);
                 */

                //DLZ
                if (weaponManager && weaponManager.selectedWeapon != null)
                {
                    if (weaponManager.selectedWeapon.GetWeaponClass() == WeaponClasses.Missile)
                    {
                        MissileLauncher currMissile = weaponManager.currentMissile;
                        if (currMissile.targetingMode == MissileLauncher.TargetingModes.GPS || currMissile.targetingMode == MissileLauncher.TargetingModes.Laser)
                        {
                            MissileLaunchParams dlz = MissileLaunchParams.GetDynamicLaunchParams(currMissile, Vector3.zero, groundTargetPosition);
                            float dlzWidth          = 12 * (imageRect.width / 360);
                            float lineWidth         = 2;
                            Rect  dlzRect           = new Rect(imageRect.x + imageRect.width - (3 * dlzWidth) - lineWidth, imageRect.y + (imageRect.height / 4), dlzWidth, imageRect.height / 2);
                            float scaleDistance     = Mathf.Max(Mathf.Max(8000f, currMissile.maxStaticLaunchRange * 2), targetRange);
                            float rangeToPixels     = (1f / scaleDistance) * dlzRect.height;


                            GUI.BeginGroup(dlzRect);

                            float dlzX = 0;

                            BDGUIUtils.DrawRectangle(new Rect(0, 0, dlzWidth, dlzRect.height), Color.black);

                            Rect maxRangeVertLineRect = new Rect(dlzRect.width - lineWidth, Mathf.Clamp(dlzRect.height - (dlz.maxLaunchRange * rangeToPixels), 0, dlzRect.height), lineWidth, Mathf.Clamp(dlz.maxLaunchRange * rangeToPixels, 0, dlzRect.height));
                            BDGUIUtils.DrawRectangle(maxRangeVertLineRect, Color.white);


                            Rect maxRangeTickRect = new Rect(dlzX, maxRangeVertLineRect.y, dlzWidth, lineWidth);
                            BDGUIUtils.DrawRectangle(maxRangeTickRect, Color.white);

                            Rect minRangeTickRect = new Rect(dlzX, Mathf.Clamp(dlzRect.height - (dlz.minLaunchRange * rangeToPixels), 0, dlzRect.height), dlzWidth, lineWidth);
                            BDGUIUtils.DrawRectangle(minRangeTickRect, Color.white);

                            Rect rTrTickRect = new Rect(dlzX, Mathf.Clamp(dlzRect.height - (dlz.rangeTr * rangeToPixels), 0, dlzRect.height), dlzWidth, lineWidth);
                            BDGUIUtils.DrawRectangle(rTrTickRect, Color.white);

                            Rect noEscapeLineRect = new Rect(dlzX, rTrTickRect.y, lineWidth, minRangeTickRect.y - rTrTickRect.y);
                            BDGUIUtils.DrawRectangle(noEscapeLineRect, Color.white);


                            GUI.EndGroup();

                            float targetDistIconSize = 6;
                            float targetDistY        = dlzRect.y + dlzRect.height - (targetRange * rangeToPixels);
                            Rect  targetDistanceRect = new Rect(dlzRect.x - (targetDistIconSize / 2), targetDistY, (targetDistIconSize / 2) + dlzRect.width, targetDistIconSize);
                            BDGUIUtils.DrawRectangle(targetDistanceRect, Color.white);
                        }
                    }
                }
            }



            //gimbal limit
            dataStyle.fontSize = 24;
            if (gimbalLimitReached)
            {
                Rect gLimRect = new Rect(imageRect.x, imageRect.y + (camImageSize * 0.15f), camImageSize, 28);
                GUI.Label(gLimRect, "GIMBAL LIMIT", dataStyle);
            }


            //reset button
            float resetStartX = stabilStartX + stabilizeRect.width + 4;
            Rect  resetRect   = new Rect(resetStartX, controlsStartY + (2 * slewSize), 3 * slewSize, slewSize - 1);

            if (GUI.Button(resetRect, "Reset", HighLogic.Skin.button))
            {
                ResetCameraButton();
            }


            //CoM lock
            Rect     comLockRect = new Rect(resetRect.x, controlsStartY, 3 * slewSize, slewSize - 1);
            GUIStyle comStyle    = new GUIStyle(CoMLock ? HighLogic.Skin.box : HighLogic.Skin.button);

            comStyle.fontSize = 10;
            comStyle.wordWrap = false;
            if (GUI.Button(comLockRect, "CoM Track", comStyle))
            {
                CoMLock = !CoMLock;
            }


            //radar slave
            Rect     radarSlaveRect  = new Rect(comLockRect.x + comLockRect.width + 4, comLockRect.y, 3 * slewSize, slewSize - 1);
            GUIStyle radarSlaveStyle = radarLock ? HighLogic.Skin.box : HighLogic.Skin.button;

            if (GUI.Button(radarSlaveRect, "Radar", radarSlaveStyle))
            {
                radarLock = !radarLock;
            }

            //slave turrets button
            Rect slaveRect = new Rect(resetStartX, controlsStartY + slewSize, (3 * slewSize), slewSize - 1);

            if (!slaveTurrets)
            {
                if (GUI.Button(slaveRect, "Turrets", HighLogic.Skin.button))
                {
                    SlaveTurrets();
                }
            }
            else
            {
                if (GUI.Button(slaveRect, "Turrets", HighLogic.Skin.box))
                {
                    UnslaveTurrets();
                }
            }

            //point to gps button
            Rect toGpsRect = new Rect(resetRect.x + slaveRect.width + 4, slaveRect.y, 3 * slewSize, slewSize - 1);

            if (GUI.Button(toGpsRect, "To GPS", HighLogic.Skin.button))
            {
                PointToGPSTarget();
            }


            //nv button
            float    nvStartX = resetStartX + resetRect.width + 4;
            Rect     nvRect   = new Rect(nvStartX, resetRect.y, 3 * slewSize, slewSize - 1);
            string   nvLabel  = nvMode ? "NV Off" : "NV On";
            GUIStyle nvStyle  = nvMode ? HighLogic.Skin.box : HighLogic.Skin.button;

            if (GUI.Button(nvRect, nvLabel, nvStyle))
            {
                ToggleNV();
            }

            //off button
            float offStartX = nvStartX + nvRect.width + 4;
            Rect  offRect   = new Rect(offStartX, controlsStartY, slewSize * 1.5f, 3 * slewSize);

            if (GUI.Button(offRect, "O\nF\nF", HighLogic.Skin.button))
            {
                DisableCamera();
            }


            float   indicatorSize   = Mathf.Clamp(64 * (camImageSize / 360), 64, 128);
            float   indicatorBorder = imageRect.width * 0.056f;
            Vector3 vesForward      = vessel.ReferenceTransform.up;
            Vector3 upDirection     = (transform.position - FlightGlobals.currentMainBody.transform.position).normalized;
            //horizon indicator
            float   horizY   = imageRect.y + imageRect.height - indicatorSize - indicatorBorder;
            Vector3 hForward = Vector3.ProjectOnPlane(vesForward, upDirection);
            float   hAngle   = -Misc.SignedAngle(hForward, vesForward, upDirection);

            horizY -= (hAngle / 90) * (indicatorSize / 2);
            Rect horizonRect = new Rect(indicatorBorder + imageRect.x, horizY, indicatorSize, indicatorSize);

            GUI.DrawTexture(horizonRect, BDArmorySettings.Instance.horizonIndicatorTexture, ScaleMode.StretchToFill, true);

            //roll indicator
            Rect rollRect = new Rect(indicatorBorder + imageRect.x, imageRect.y + imageRect.height - indicatorSize - indicatorBorder, indicatorSize, indicatorSize);

            GUI.DrawTexture(rollRect, rollReferenceTexture, ScaleMode.StretchToFill, true);
            Vector3 localUp = vessel.ReferenceTransform.InverseTransformDirection(upDirection);

            localUp = Vector3.ProjectOnPlane(localUp, Vector3.up).normalized;
            float rollAngle = -Misc.SignedAngle(-Vector3.forward, localUp, Vector3.right);

            GUIUtility.RotateAroundPivot(rollAngle, rollRect.center);
            GUI.DrawTexture(rollRect, rollIndicatorTexture, ScaleMode.StretchToFill, true);
            GUI.matrix = Matrix4x4.identity;

            //target direction indicator
            float angleToTarget = Misc.SignedAngle(hForward, Vector3.ProjectOnPlane(targetPointPosition - transform.position, upDirection), Vector3.Cross(upDirection, hForward));

            GUIUtility.RotateAroundPivot(angleToTarget, rollRect.center);
            GUI.DrawTexture(rollRect, BDArmorySettings.Instance.targetDirectionTexture, ScaleMode.StretchToFill, true);
            GUI.matrix = Matrix4x4.identity;



            //resizing
            Rect resizeRect = new Rect(camWindowRect.width - 20, camWindowRect.height - 20, 20, 20);

            if (GUI.RepeatButton(resizeRect, "//"))
            {
                resizing = true;
            }

            if (resizing)
            {
                camImageSize += Mouse.delta.x / 4;
                camImageSize += Mouse.delta.y / 4;

                camImageSize = Mathf.Clamp(camImageSize, 360, 800);


                RefreshWindowSize();
            }

            if (Input.GetMouseButtonUp(0))
            {
                resizing = false;
            }
        }
示例#2
0
        void FlyToPosition(FlightCtrlState s, Vector3 targetPosition)
        {
            if (!startedLanded)
            {
                targetPosition = FlightPosition(targetPosition, minAltitude);
                targetPosition = vesselTransform.position + ((targetPosition - vesselTransform.position).normalized * 100);
            }

            Vector3d srfVel = vessel.srf_velocity;

            if (srfVel != Vector3d.zero)
            {
                velocityTransform.rotation = Quaternion.LookRotation(srfVel, -vesselTransform.forward);
            }
            velocityTransform.rotation = Quaternion.AngleAxis(90, velocityTransform.right) * velocityTransform.rotation;
            Vector3 localAngVel = vessel.angularVelocity;

            float angleToTarget = Vector3.Angle(targetPosition - vesselTransform.position, vesselTransform.up);

            if (steerMode == SteerModes.NormalFlight)
            {
                //Vector3 dampedDirection = Vector3.RotateTowards(vesselTransform.up, targetPosition - vesselTransform.position, (angleToTarget / 2) * Mathf.Deg2Rad, 0).normalized;
                //targetPosition = vesselTransform.position + (100 * dampedDirection);
            }

            if (BDArmorySettings.DRAW_DEBUG_LINES)
            {
                flyingToPosition = targetPosition;
            }

            //slow down for tighter turns
            float velAngleToTarget     = Vector3.Angle(targetPosition - vesselTransform.position, vessel.srf_velocity);
            float normVelAngleToTarget = Mathf.Clamp(velAngleToTarget, 0, 90) / 90;
            float speedReductionFactor = 1.25f;
            float finalSpeed           = Mathf.Min(speedController.targetSpeed, Mathf.Clamp(maxSpeed - (speedReductionFactor * normVelAngleToTarget), minSpeed, maxSpeed));

            debugString += "\nFinal Target Speed: " + finalSpeed.ToString("0.0");
            AdjustThrottle(finalSpeed, useBrakes, useAB);

            Vector3 targetDirection;
            Vector3 targetDirectionYaw;
            float   yawError;
            float   pitchError;
            float   postYawFactor;
            float   postPitchFactor;

            if (steerMode == SteerModes.NormalFlight)
            {
                targetDirection = velocityTransform.InverseTransformDirection(targetPosition - velocityTransform.position).normalized;
                targetDirection = Vector3.RotateTowards(Vector3.up, targetDirection, 45 * Mathf.Deg2Rad, 0);

                targetDirectionYaw = vesselTransform.InverseTransformDirection(vessel.srf_velocity).normalized;
                targetDirectionYaw = Vector3.RotateTowards(Vector3.up, targetDirectionYaw, 45 * Mathf.Deg2Rad, 0);


                postYawFactor   = 1;
                postPitchFactor = 1;

                if (command == PilotCommands.Orbit)
                {
                    postPitchFactor = 0.85f;
                }
            }
            else            //(steerMode == SteerModes.Aiming)
            {
                targetDirection    = vesselTransform.InverseTransformDirection(targetPosition - vesselTransform.position).normalized;
                targetDirection    = Vector3.RotateTowards(Vector3.up, targetDirection, 45 * Mathf.Deg2Rad, 0);
                targetDirectionYaw = targetDirection;

                if (command == PilotCommands.Follow)
                {
                    postYawFactor   = 1.3f;
                    postPitchFactor = 1f;
                }
                else
                {
                    postYawFactor   = 1.5f;
                    postPitchFactor = 2.4f;
                }
            }

            pitchError = VectorUtils.SignedAngle(Vector3.up, Vector3.ProjectOnPlane(targetDirection, Vector3.right), Vector3.back);
            yawError   = VectorUtils.SignedAngle(Vector3.up, Vector3.ProjectOnPlane(targetDirectionYaw, Vector3.forward), Vector3.right);



            float finalMaxSteer = threatLevel * maxSteer;

            float steerPitch = (postPitchFactor * 0.015f * steerMult * pitchError) - (postPitchFactor * steerDamping * -localAngVel.x);
            float steerYaw   = (postYawFactor * 0.022f * steerMult * yawError) - (postYawFactor * steerDamping * -localAngVel.z);


            s.yaw   = Mathf.Clamp(steerYaw, -finalMaxSteer, finalMaxSteer);
            s.pitch = Mathf.Clamp(steerPitch, Mathf.Min(-finalMaxSteer, -0.2f), finalMaxSteer);


            //roll
            Vector3 currentRoll = -vesselTransform.forward;
            Vector3 rollTarget;

            //if(steerMode == SteerModes.Aiming || angleToTarget > 2)
            //{
            rollTarget = (targetPosition + ((steerMode == SteerModes.Aiming ? 10f : 30f) * upDirection)) - vesselTransform.position;
            //}
            //else
            //{
            //	rollTarget = upDirection;
            //}

            if (command == PilotCommands.Follow && useRollHint)
            {
                rollTarget = -commandLeader.vessel.ReferenceTransform.forward;
            }

            rollTarget = Vector3.ProjectOnPlane(rollTarget, vesselTransform.up);



            float rollError = Misc.SignedAngle(currentRoll, rollTarget, vesselTransform.right);

            debugString += "\nRoll offset: " + rollError;
            float steerRoll = (steerMult * 0.0015f * rollError);

            debugString += "\nSteerRoll: " + steerRoll;
            float rollDamping = (.10f * steerDamping * -localAngVel.y);

            steerRoll   -= rollDamping;
            debugString += "\nRollDamping: " + rollDamping;



            float roll = Mathf.Clamp(steerRoll, -maxSteer, maxSteer);

            s.roll = roll;
            //
        }