public bool RenderHUD(RenderTexture screen, float cameraAspect) { if (screen == null || !startupComplete || HighLogic.LoadedSceneIsEditor) { return(false); } if (!firstRenderComplete) { firstRenderComplete = true; hudCamera.orthographicSize = (float)(screen.height) * 0.5f; hudCamera.aspect = (float)screen.width / (float)screen.height; InitializeRenderables(screen); } for (int i = 0; i < verticalBars.Count; ++i) { verticalBars[i].Update(); } for (int i = 0; i < horizontalBars.Count; ++i) { horizontalBars[i].Update(); } GL.Clear(true, true, backgroundColorValue); // Draw the camera's view, if configured. if (cameraObject != null) { if (renderTex == null) { renderTex = new RenderTexture(screen.width, screen.height, screen.depth); renderTex.Create(); } if (cameraObject.Render(renderTex, 0.0f, 0.0f)) { if (cameraEffectMaterial != null) { cameraEffectMaterial.SetVector("_ImageDims", new Vector4((float)renderTex.width, (float)renderTex.height, 1.0f / (float)renderTex.width, 1.0f / (float)renderTex.height)); for (int i = 0; i < ceVariables.Count; ++i) { float value = ceVariables[i].value.AsFloat(); cameraEffectMaterial.SetFloat(ceVariables[i].variable, value); } Graphics.Blit(renderTex, screen, cameraEffectMaterial); } else { Graphics.Blit(renderTex, screen); } renderTex.DiscardContents(); } } hudCamera.targetTexture = screen; // MOARdV TODO: I don't think this does anything... GL.Color(Color.white); RPMVesselComputer comp = RPMVesselComputer.Instance(vessel); Quaternion rotationVesselSurface = comp.RotationVesselSurface; if (headingMesh != null) { UpdateHeading(rotationVesselSurface); JUtil.ShowHide(true, headingMesh); } if (ladderMesh != null) { // Fix up UVs, apply rotation. UpdateLadder(rotationVesselSurface, comp); ladderMaterial.SetVector("_CropBound", cropBound); bool enable = (horizonEnable == null || horizonEnable.IsInRange()); JUtil.ShowHide(enable, ladderMesh); } if (overlayMesh != null) { JUtil.ShowHide(true, overlayMesh); } hudCamera.Render(); JUtil.ShowHide(false, overlayMesh, ladderMesh, headingMesh, progradeLadderIcon, progradeHeadingIcon); for (int i = 0; i < verticalBars.Count; ++i) { JUtil.ShowHide(false, verticalBars[i].barObject); } for (int i = 0; i < horizontalBars.Count; ++i) { JUtil.ShowHide(false, horizontalBars[i].barObject); } return(true); }
public bool RenderPFD(RenderTexture screen, float aspect) { if (screen == null || !startupComplete || HighLogic.LoadedSceneIsEditor) { return(false); } // Analysis disable once CompareOfFloatsByEqualityOperator if (firstRenderComplete == false) { firstRenderComplete = true; ConfigureElements((float)screen.width, (float)screen.height); ballCamera.aspect = aspect; } GL.Clear(true, true, backgroundColorValue); ballCamera.targetTexture = screen; // Navball is rotated around the Y axis 180 degrees since the // original implementation had the camera positioned differently. // We still need MirrorX since KSP does something odd with the // gimbal navBall.transform.rotation = (rotateNavBall * MirrorX(stockNavBall.relativeGymbal)); RPMVesselComputer comp = RPMVesselComputer.Instance(vessel); if (heading != null) { heading.renderer.material.SetTextureOffset("_MainTex", new Vector2(JUtil.DualLerp(0f, 1f, 0f, 360f, comp.RotationVesselSurface.eulerAngles.y) - headingSpan / 2f, 0)); } Quaternion gymbal = stockNavBall.attitudeGymbal; if (FlightUIController.speedDisplayMode == FlightUIController.SpeedDisplayModes.Orbit) { Vector3 velocityVesselOrbitUnit = comp.Prograde; Vector3 radialPlus = comp.RadialOut; Vector3 normalPlus = comp.NormalPlus; MoveMarker(markerPrograde, velocityVesselOrbitUnit, gymbal); MoveMarker(markerRetrograde, -velocityVesselOrbitUnit, gymbal); MoveMarker(markerNormal, normalPlus, gymbal); MoveMarker(markerNormalMinus, -normalPlus, gymbal); MoveMarker(markerRadial, radialPlus, gymbal); MoveMarker(markerRadialMinus, -radialPlus, gymbal); JUtil.ShowHide(true, markerNormal, markerNormalMinus, markerRadial, markerRadialMinus); } else if (FlightUIController.speedDisplayMode == FlightUIController.SpeedDisplayModes.Surface) { Vector3 velocityVesselSurfaceUnit = vessel.srf_velocity.normalized; MoveMarker(markerPrograde, velocityVesselSurfaceUnit, gymbal); MoveMarker(markerRetrograde, -velocityVesselSurfaceUnit, gymbal); } else // FlightUIController.speedDisplayMode == FlightUIController.SpeedDisplayModes.Target { Vector3 targetDirection = FlightGlobals.ship_tgtVelocity.normalized; MoveMarker(markerPrograde, targetDirection, gymbal); MoveMarker(markerRetrograde, -targetDirection, gymbal); } if (vessel.patchedConicSolver != null && vessel.patchedConicSolver.maneuverNodes.Count > 0) { Vector3 burnVector = vessel.patchedConicSolver.maneuverNodes[0].GetBurnVector(vessel.orbit).normalized; MoveMarker(markerManeuver, burnVector, gymbal); MoveMarker(markerManeuverMinus, -burnVector, gymbal); JUtil.ShowHide(true, markerManeuver, markerManeuverMinus); } /* Feature disabled until I can get a career game going and get a waypoint contract. * if (FinePrint.WaypointManager.navIsActive() == true) * { * // MOARdV: Code for the waypoint marker based on https://github.com/Ninenium/NavHud/blob/master/Source/WaypointMarker.cs * GameObject navWaypointIndicator = GameObject.Find("NavBall").transform.FindChild("vectorsPivot").FindChild("NavWaypoint").gameObject; * Material material = navWaypointIndicator.renderer.sharedMaterial; * markerNavWaypoint.renderer.material.mainTexture = material.mainTexture; * * Vector3d waypointPosition = vessel.mainBody.GetWorldSurfacePosition(FinePrint.WaypointManager.navWaypoint.latitude, FinePrint.WaypointManager.navWaypoint.longitude, FinePrint.WaypointManager.navWaypoint.altitude); * Vector3d waypointDirection = (waypointPosition - comp.CoM).normalized; * MoveMarker(markerNavWaypoint, waypointDirection, material.color, gymbal); * JUtil.ShowHide(true, markerNavWaypoint); * } */ ITargetable target = FlightGlobals.fetch.VesselTarget; if (target != null) { Vector3 targetSeparation = comp.TargetSeparation.normalized; MoveMarker(markerTarget, targetSeparation, gymbal); MoveMarker(markerTargetMinus, -targetSeparation, gymbal); var targetPort = target as ModuleDockingNode; if (targetPort != null) { // Thanks to Michael Enßlin Transform targetTransform = targetPort.transform; Transform selfTransform = vessel.ReferenceTransform; Vector3 targetOrientationVector = -targetTransform.up.normalized; Vector3 v1 = Vector3.Cross(selfTransform.up, targetTransform.forward); Vector3 v2 = Vector3.Cross(selfTransform.up, selfTransform.forward); float angle = Vector3.Angle(v1, v2); if (Vector3.Dot(selfTransform.up, Vector3.Cross(v1, v2)) < 0) { angle = -angle; } MoveMarker(markerDockingAlignment, targetOrientationVector, gymbal); markerDockingAlignment.transform.Rotate(Vector3.up, -angle); JUtil.ShowHide(true, markerDockingAlignment); } JUtil.ShowHide(true, markerTarget, markerTargetMinus); } JUtil.ShowHide(true, cameraBody, navBall, overlay, heading, markerPrograde, markerRetrograde); ballCamera.Render(); JUtil.ShowHide(false, cameraBody, navBall, overlay, heading, markerPrograde, markerRetrograde, markerManeuver, markerManeuverMinus, markerTarget, markerTargetMinus, markerNormal, markerNormalMinus, markerRadial, markerRadialMinus, markerDockingAlignment, markerNavWaypoint); return(true); }
public void Start() { if (!HighLogic.LoadedSceneIsFlight) { return; } // Grrrrrr. if (!string.IsNullOrEmpty(nameColor)) { nameColorValue = ConfigNode.ParseColor32(nameColor); } if (!string.IsNullOrEmpty(distanceColor)) { distanceColorValue = ConfigNode.ParseColor32(distanceColor); } if (!string.IsNullOrEmpty(selectedColor)) { selectedColorValue = ConfigNode.ParseColor32(selectedColor); } if (!string.IsNullOrEmpty(unavailableColor)) { unavailableColorValue = ConfigNode.ParseColor32(unavailableColor); } persistentVarName = "targetfilter" + internalProp.propID; RPMVesselComputer comp = RPMVesselComputer.Instance(vessel); // 7 is the bitmask for ship-station-probe; VesselFilterFromBitmask(comp.GetPersistentVariable(persistentVarName, defaultFilter).MassageToInt()); nameColorTag = JUtil.ColorToColorTag(nameColorValue); distanceColorTag = JUtil.ColorToColorTag(distanceColorValue); selectedColorTag = JUtil.ColorToColorTag(selectedColorValue); unavailableColorTag = JUtil.ColorToColorTag(unavailableColorValue); distanceFormatString = distanceFormatString.UnMangleConfigText(); menuTitleFormatString = menuTitleFormatString.UnMangleConfigText(); topMenu.labelColor = nameColorTag; topMenu.selectedColor = selectedColorTag; topMenu.disabledColor = unavailableColorTag; if (!string.IsNullOrEmpty(pageTitle)) { pageTitle = pageTitle.UnMangleConfigText(); } foreach (CelestialBody body in FlightGlobals.Bodies) { celestialsList.Add(new Celestial(body, vessel.transform.position)); } FindReferencePoints(); UpdateUndockablesList(); var menuActions = new List <Action <int, TextMenu.Item> >(); menuActions.Add(ShowCelestialMenu); menuActions.Add(ShowVesselMenu); menuActions.Add(ShowSpaceObjectMenu); menuActions.Add(ShowReferenceMenu); menuActions.Add(ShowUndockMenu); menuActions.Add(ArmGrapple); menuActions.Add(ShowFiltersMenu); menuActions.Add(ClearTarget); for (int i = 0; i < rootMenu.Count; ++i) { var menuitem = new TextMenu.Item(); menuitem.labelText = rootMenu[i]; menuitem.action = menuActions[i]; topMenu.Add(menuitem); switch (menuitem.labelText) { case clearTargetItemText: clearTarget = topMenu[i]; break; case undockItemText: undockMenuItem = topMenu[i]; break; case armGrappleText: grappleMenuItem = topMenu[i]; break; } } activeMenu = topMenu; }