public void toMainCamera() { if ((cam != null) && (cam.transform != null)) { cam.transform.parent = origParent; Camera.main.nearClipPlane = origClip; cam.setTarget(FlightGlobals.ActiveVessel.transform); if (currentCamera != null) { currentCamera.ltcamActive = false; } currentCamera = null; MapView.EnterMapView(); MapView.ExitMapView(); } }
protected static void RestoreMainCamera() { DebugOutput("RestoreMainCamera"); sCam.transform.parent = sOrigParent; sCam.transform.localPosition = sOrigPosition; sCam.transform.localRotation = sOrigRotation; Camera.main.nearClipPlane = sOrigClip; sCam.SetFoV(sOrigFov); if (FlightGlobals.ActiveVessel != null && HighLogic.LoadedScene == GameScenes.FLIGHT) { sCam.setTarget(FlightGlobals.ActiveVessel.transform); } sOrigParent = null; if (sCurrentCamera != null) { sCurrentCamera.camActive = false; } sCurrentCamera = null; }
public void toMainCamera() { if ((cam != null) && (cam.transform != null)) { cam.transform.parent = origParent; Camera.mainCamera.nearClipPlane = origClip; foreach (Camera c in cam.GetComponentsInChildren <Camera>()) { c.fov = origFoV; } cam.setTarget(FlightGlobals.ActiveVessel.transform); if (currentCamera != null) { currentCamera.camActive = false; } currentCamera = null; MapView.EnterMapView(); MapView.ExitMapView(); } }
int posCounter = 0; //debug void FixedUpdate() { /* * if(FloatingOrigin.fetch.offset!=lastOffset) * { * lastOffset = FloatingOrigin.fetch.offset; * OnFloatingOriginShift(lastOffset); * } */ if (FlightGlobals.ActiveVessel != null && (vessel == null || vessel != FlightGlobals.ActiveVessel)) { vessel = FlightGlobals.ActiveVessel; } if (vessel != null) { lastVesselPosition = vessel.transform.position; cameraParent.transform.position = manualPosition + (vessel.findWorldCenterOfMass() - vessel.rigidbody.velocity * Time.fixedDeltaTime); } //stationary camera if (isStationaryCamera) { if (posCounter < 3) { posCounter++; Debug.Log("flightCamera position: " + flightCamera.transform.position); flightCamera.transform.position = resetPositionFix; if (hasSavedRotation) { flightCamera.transform.rotation = savedRotation; } } if (flightCamera.Target != null) { flightCamera.setTarget(null); //dont go to next vessel if vessel is destroyed } if (camTarget != null) { Vector3 lookPosition = camTarget.position; if (camTarget.rigidbody) { lookPosition += camTarget.rigidbody.velocity * Time.fixedDeltaTime; } flightCamera.transform.rotation = Quaternion.LookRotation(lookPosition - flightCamera.transform.position, cameraUp); lastTargetPosition = lookPosition; } else if (hasTarget) { flightCamera.transform.rotation = Quaternion.LookRotation(lastTargetPosition - flightCamera.transform.position, cameraUp); } if (vessel != null) { if (referenceMode == ReferenceModes.Surface) { flightCamera.transform.position -= Time.fixedDeltaTime * Mathf.Clamp((float)vessel.srf_velocity.magnitude, 0, maxRelV) * vessel.srf_velocity.normalized; } else if (referenceMode == ReferenceModes.Orbit) { flightCamera.transform.position -= Time.fixedDeltaTime * Mathf.Clamp((float)vessel.obt_velocity.magnitude, 0, maxRelV) * vessel.obt_velocity.normalized; } else if (referenceMode == ReferenceModes.InitialVelocity) { Vector3 camVelocity = Vector3.zero; if (useOrbital && initialOrbit != null) { camVelocity = (initialOrbit.getOrbitalVelocityAtUT(Planetarium.GetUniversalTime()).xzy - vessel.GetObtVelocity()); } else { camVelocity = (initialVelocity - vessel.srf_velocity); } flightCamera.transform.position += camVelocity * Time.fixedDeltaTime; } } //mouse panning, moving Vector3 forwardLevelAxis = (Quaternion.AngleAxis(-90, cameraUp) * flightCamera.transform.right).normalized; Vector3 rightAxis = (Quaternion.AngleAxis(90, forwardLevelAxis) * cameraUp).normalized; //free move if (enableKeypad) { if (Input.GetKey(fmUpKey)) { manualPosition += cameraUp * freeMoveSpeed * Time.fixedDeltaTime; } else if (Input.GetKey(fmDownKey)) { manualPosition -= cameraUp * freeMoveSpeed * Time.fixedDeltaTime; } if (Input.GetKey(fmForwardKey)) { manualPosition += forwardLevelAxis * freeMoveSpeed * Time.fixedDeltaTime; } else if (Input.GetKey(fmBackKey)) { manualPosition -= forwardLevelAxis * freeMoveSpeed * Time.fixedDeltaTime; } if (Input.GetKey(fmLeftKey)) { manualPosition -= flightCamera.transform.right * freeMoveSpeed * Time.fixedDeltaTime; } else if (Input.GetKey(fmRightKey)) { manualPosition += flightCamera.transform.right * freeMoveSpeed * Time.fixedDeltaTime; } //keyZoom if (Input.GetKey(fmZoomInKey)) { zoomExp = Mathf.Clamp(zoomExp + (keyZoomSpeed * Time.fixedDeltaTime), 1, 8); } else if (Input.GetKey(fmZoomOutKey)) { zoomExp = Mathf.Clamp(zoomExp - (keyZoomSpeed * Time.fixedDeltaTime), 1, 8); } } if (camTarget == null && Input.GetKey(KeyCode.Mouse1)) { flightCamera.transform.rotation *= Quaternion.AngleAxis(Input.GetAxis("Mouse X") * 1.7f, Vector3.up); //*(Mathf.Abs(Mouse.delta.x)/7) flightCamera.transform.rotation *= Quaternion.AngleAxis(-Input.GetAxis("Mouse Y") * 1.7f, Vector3.right); flightCamera.transform.rotation = Quaternion.LookRotation(flightCamera.transform.forward, cameraUp); } if (Input.GetKey(KeyCode.Mouse2)) { manualPosition += flightCamera.transform.right * Input.GetAxis("Mouse X") * 2; manualPosition += forwardLevelAxis * Input.GetAxis("Mouse Y") * 2; } manualPosition += cameraUp * 10 * Input.GetAxis("Mouse ScrollWheel"); //autoFov if (camTarget != null && autoFOV) { float cameraDistance = Vector3.Distance(camTarget.position, flightCamera.transform.position); float targetFoV = Mathf.Clamp((7000 / (cameraDistance + 100)) - 4, 2, 60); //flightCamera.SetFoV(targetFoV); manualFOV = targetFoV; } //FOV if (!autoFOV) { zoomFactor = Mathf.Exp(zoomExp) / Mathf.Exp(1); manualFOV = 60 / zoomFactor; updateFOV = (currentFOV != manualFOV); if (updateFOV) { currentFOV = Mathf.Lerp(currentFOV, manualFOV, 0.1f); flightCamera.SetFoV(currentFOV); updateFOV = false; } } else { currentFOV = Mathf.Lerp(currentFOV, manualFOV, 0.1f); flightCamera.SetFoV(currentFOV); } lastPosition = flightCamera.transform.position; lastRotation = flightCamera.transform.rotation; if (airspeedNoiseTransform) { airspeedNoiseTransform.position = vessel.transform.position; } } if (hasDied && Time.time - diedTime > 2) { RevertCamera(); } }