private static void Prefix(FPSCamera __instance) { Vector3 euler = HMD.GetVRCameraEulerRelativeToFPSCameraParent(); __instance.m_pitch = euler.x; __instance.m_yaw = euler.y; }
private static bool Prefix(FPSCamera __instance) { bool vis = false; if (VRConfig.configUseControllers.Value) { //Used for throwing weapons __instance.CameraRayDir = HMD.GetVRInteractionLookDir(); RaycastHit hit; if (Physics.Raycast(Controllers.GetAimFromPos(), Controllers.GetAimForward(), out hit, 50f, LayerManager.MASK_CAMERA_RAY)) { __instance.CameraRayPos = hit.point; __instance.CameraRayCollider = hit.collider; __instance.CameraRayNormal = hit.normal; __instance.CameraRayObject = hit.collider.gameObject; __instance.CameraRayDist = hit.distance; if (FPSCamera.FriendlyTargetVisAllowed && hit.collider.gameObject.layer == LayerManager.LAYER_PLAYER_SYNCED) { vis = true; } } else { __instance.CameraRayPos = Controllers.GetAimFromPos() + Controllers.GetAimForward() * 50f; __instance.CameraRayCollider = null; __instance.CameraRayNormal = -Controllers.GetAimForward(); __instance.CameraRayObject = null; __instance.CameraRayDist = 0.0f; } } GuiManager.CrosshairLayer.SetFriendlyTargetVisible(vis); return(false); }
private void SetupOrigin() { Controllers.SetOrigin(transform); HMD.SetOrigin(transform); DontDestroyOnLoad(gameObject); Log.Info("Origin created and set"); }
public static void PrepareNavMarker(NavMarker n) { n.transform.SetParent(null); n.m_initScale *= 0.009f; SetTransformHierarchyLayer(n.transform); foreach (TextMeshPro p in n.transform.GetComponentsInChildren <TextMeshPro>(true)) { if (p == null || p.fontSharedMaterial == null) { return; } Log.Debug($"Prev shader = {p.fontMaterial.shader.name}"); p.fontSharedMaterial.shader = VRAssets.GetTextNoCull(); } if (n != null && n.m_distance != null && n.m_distance.fontSharedMaterial != null) { n.m_distance.fontSharedMaterial.shader = VRAssets.GetTextNoCull(); } if (n.m_trackingObj) { n.transform.position = n.m_trackingObj.transform.position; n.transform.rotation = Quaternion.LookRotation(HMD.GetFlatForwardDirection()); } }
private void OnDestroy() { Controllers.OnOriginDestroyed(); HMD.OnOriginDestroyed(); FocusStateEvents.OnFocusStateChange -= FocusStateChanged; Snapturn.OnSnapTurn += HandleOriginShift; }
protected virtual void Dispose(bool disposing) { if (_disposed) { return; } if (disposing) { if (DepthStencilBuffer != null) { DepthStencilBuffer.Dispose(); } if (RenderTarget != null) { RenderTarget.Dispose(); } if (HMD != null) { HMD.Dispose(); } OVR.Shutdown(); } _disposed = true; }
protected void InitializeRendering(GraphicsDevice graphicsDevice) { // Get our initial render target size // The scaling factor doesn't seem to affect the image quality. There is no golden value for this as stated in the SDK documentation var renderTargetSize = HMD.GetDefaultRenderTargetSize(1.5f); // Create the render target texture that is shown on the HMD RenderTarget = RenderTarget2D.New(graphicsDevice, renderTargetSize.Width, renderTargetSize.Height, new MipMapCount(1), PixelFormat.R8G8B8A8.UNorm); // The created texture can have a different size due to hardware limitations so the render target size needs to be updated renderTargetSize.Width = RenderTarget.Width; renderTargetSize.Height = RenderTarget.Height; DepthStencilBuffer = DepthStencilBuffer.New(graphicsDevice, renderTargetSize.Width, renderTargetSize.Height, DepthFormat.Depth32, true); // Compute the virtual cameras' viewports EyeViewport[0] = new Rect(0, 0, renderTargetSize.Width / 2, renderTargetSize.Height); EyeViewport[1] = new Rect((renderTargetSize.Width + 1) / 2, 0, EyeViewport[0].Width, EyeViewport[0].Height); // Create HMD's eye texture data EyeTextureData = new D3D11TextureData[2]; EyeTextureData[0].Header.API = RenderAPIType.D3D11; EyeTextureData[0].Header.TextureSize = renderTargetSize; EyeTextureData[0].Header.RenderViewport = EyeViewport[0]; EyeTextureData[0].pTexture = ((SharpDX.Direct3D11.Texture2D)RenderTarget).NativePointer; EyeTextureData[0].pSRView = ((ShaderResourceView)RenderTarget).NativePointer; // Right eye holds the same values except for the viewport EyeTextureData[1] = EyeTextureData[0]; EyeTextureData[1].Header.RenderViewport = EyeViewport[1]; }
public void BeginFrame(GraphicsDevice graphicsDevice) { graphicsDevice.SetRenderTargets(DepthStencilBuffer, RenderTarget); // Begin oculus rift drawing mode HMD.BeginFrame(0); // Update the eye's pose from sensor data HMD.GetEyePoses(0, EyeOffset, EyePose); }
private Vector3 GetInteractionPromptPosition() { if (ShouldUsePointerPosition()) { return(VRPlayer.FpsCamera.CameraRayPos + new Vector3(0, 0.05f, 0) - VRPlayer.FpsCamera.transform.forward * .1f); } return(VRPlayer.PlayerAgent.PlayerCharacterController.SmoothPosition + HMD.GetFlatForwardDirection() * .7f + new Vector3(0, 1f, 0)); }
public static void UpdateVRCameraTransform(FPSCamera fpsCamera) { if (!FocusStateManager.CurrentState.Equals(eFocusState.InElevator)) { fpsCamera.transform.position = HMD.GetWorldPosition(); } fpsCamera.m_camera.transform.parent.localRotation = Quaternion.Euler(HMD.GetVRCameraEulerRelativeToFPSCameraParent()); fpsCamera.UpdateCameraRay(); }
static void Postfix(FPSCamera __instance) { if (!PlayerVR.VRSetup) { return; } Vector3 euler = __instance.m_camera.transform.parent.localEulerAngles; euler.z = HMD.GetVRCameraEulerRotation().z; __instance.m_camera.transform.parent.localRotation = Quaternion.Euler(euler); }
private Vector3 CalculateCrouchOffset() { if (m_agent && m_agent.Locomotion.m_currentStateEnum.Equals(PlayerLocomotion.PLOC_State.Crouch)) { float goalCrouchHeight = VRConfig.configCrouchHeight.Value / 100f; float diff = Mathf.Max(0f, HMD.GetPlayerHeight() - goalCrouchHeight + VRConfig.configFloorOffset.Value / 100f); return(new Vector3(0, diff, 0)); } return(Vector3.zero); }
private void SnapUIToPlayerView() { if (m_statusBarHolder) { m_statusBarHolder.transform.rotation = Quaternion.LookRotation(HMD.GetFlatForwardDirection()); } if (m_intelHolder) { m_intelHolder.transform.rotation = Quaternion.LookRotation(HMD.GetFlatForwardDirection()); } }
private Vector3 GetIntelPosition() { if (FocusStateEvents.currentState.Equals(eFocusState.InElevator) && VRPlayer.FpsCamera) { Vector3 flatForward = VRPlayer.FpsCamera.m_camera.transform.forward; flatForward.y = 0f; Vector3 pos = VRPlayer.FpsCamera.m_camera.transform.position; return(pos + flatForward.normalized * 1.2f); } return(HMD.GetWorldPosition() + HMD.GetFlatForwardDirection() * 1.75f); }
public void DoSnapTurnTowards(Vector3 direction, float fadeDuration) { Vector3 deltaRot = Quaternion.LookRotation(direction).eulerAngles; deltaRot.x = 0; deltaRot.z = 0; deltaRot.y -= HMD.GetVRCameraEulerRelativeToFPSCameraParent().y; m_origin.RotatePlayer(Quaternion.Euler(deltaRot)); SnapTurnFade(fadeDuration); OnSnapTurn.Invoke(); }
protected VRGame() { // Creates a graphics manager. This is mandatory. Graphics = new GraphicsDeviceManager(this); OVR.Initialize(); hmd = OVR.HmdCreate(0) ?? OVR.HmdCreateDebug(HMDType.DK2); ToDispose(hmd); Graphics.PreferredBackBufferWidth = hmd.Resolution.Width; Graphics.PreferredBackBufferHeight = hmd.Resolution.Height; Graphics.PreferredFullScreenOutputIndex = 1; Graphics.DeviceCreationFlags |= DeviceCreationFlags.Debug; }
protected void InitializeHMD(GraphicsDevice graphicsDevice, IntPtr windowHandle) { // Attach the HMD to window to direct back buffer output from the window to the HMD HMD.AttachToWindow(windowHandle); // Configure DirectX 11 var device = (SharpDX.Direct3D11.Device)graphicsDevice; var d3D11Cfg = new D3D11ConfigData { Header = { API = RenderAPIType.D3D11, BackBufferSize = HMD.Resolution, Multisample = 1 }, pDevice = device.NativePointer, pDeviceContext = device.ImmediateContext.NativePointer, pBackBufferRT = ((RenderTargetView)graphicsDevice.BackBuffer).NativePointer, pSwapChain = ((SwapChain)graphicsDevice.Presenter.NativePresenter).NativePointer }; // Configure the HMD's rendering settings EyeRenderDesc = new EyeRenderDesc[2]; if (!HMD.ConfigureRendering(d3D11Cfg, DistortionCapabilities.Chromatic | DistortionCapabilities.TimeWarp, HMD.DefaultEyeFov, EyeRenderDesc)) { throw new Exception("Failed to configure HMD"); } // IPD EyeOffset[0] = EyeRenderDesc[0].HmdToEyeViewOffset; EyeOffset[1] = EyeRenderDesc[1].HmdToEyeViewOffset; // Enable low persistence and dynamic prediction features HMD.EnabledCaps = HMDCapabilities.LowPersistence | HMDCapabilities.DynamicPrediction; // Enable all DK2 tracking features HMD.ConfigureTracking(TrackingCapabilities.Orientation | TrackingCapabilities.Position | TrackingCapabilities.MagYawCorrection, TrackingCapabilities.None); // Dismiss the Heatlh and Safety Window HMD.DismissHSWDisplay(); // Get HMD output display var adapter = (Adapter)graphicsDevice.Adapter; var hmdOutput = adapter.Outputs.FirstOrDefault(o => HMD.DeviceName.StartsWith(o.Description.DeviceName, StringComparison.OrdinalIgnoreCase)); if (hmdOutput != null) { // Set game to fullscreen on rift var swapChain = (SwapChain)graphicsDevice.Presenter.NativePresenter; var description = swapChain.Description.ModeDescription; swapChain.ResizeTarget(ref description); swapChain.SetFullscreenState(true, hmdOutput); } }
private void OrientMenu() { if (originOverride != null) { transform.position = originOverride.transform.position; } else { transform.position = Controllers.GetInteractionHandGO(targetHand).transform.position; } transform.rotation = Quaternion.LookRotation(transform.position - HMD.GetWorldPosition()); }
private static void Postfix(FPSCamera __instance) { if (!FocusStateManager.CurrentState.Equals(eFocusState.InElevator)) { __instance.Position = HMD.GetWorldPosition(); } Vector3 euler = __instance.m_camera.transform.parent.localEulerAngles; euler.z = HMD.GetVRCameraEulerRelativeToFPSCameraParent().z; __instance.m_camera.transform.parent.localRotation = Quaternion.Euler(euler); __instance.UpdateFlatTransform(); }
private static void Postfix(FPSCamera __instance) { // Repeat position inject or the transforms will get out of sync (Unity transform handling mumbo jumbo ensues, frame later or frame behind tracking) if (!FocusStateManager.CurrentState.Equals(eFocusState.InElevator)) { __instance.Position = HMD.GetWorldPosition(); } Vector3 euler = HMD.GetVRCameraEulerRelativeToFPSCameraParent(); __instance.m_pitch = euler.x; __instance.m_yaw = euler.y; }
private void UpdateInteraction() { if (m_interactionBarHolder == null) { Log.Error("m_interactionBarHolder was null!"); return; } m_interactionBarHolder.SetActive(interactGUI.IsVisible() && interactGUI.InteractPromptVisible); if (m_interactionBarHolder.activeSelf) { m_interactionBarHolder.transform.position = GetInteractionPromptPosition(); m_interactionBarHolder.transform.rotation = Quaternion.LookRotation(HMD.GetFlatForwardDirection()); } }
private void UpdateStatus() { if (m_statusBarHolder == null) { Log.Error("m_statusBarHolder bar was null!"); return; } m_statusBarHolder.SetActive(interactGUI.IsVisible() && interactGUI.MessageVisible); if (m_statusBarHolder.activeSelf) { m_statusBarHolder.transform.position = GetStatusBarPosition(); m_statusBarHolder.transform.rotation = Quaternion.LookRotation(HMD.GetFlatForwardDirection()); } }
private static void Postfix(FPSCamera __instance, ref Vector3 __result) { if (!VRConfig.configUseControllers.Value) { return; } if (useInteractionControllersPosition) { __result = HMD.GetVRInteractionFromPosition(); } if (useControllerPosition) { __result = Controllers.GetAimForward(); } }
//管理员——删除所有黑名单 public bool del_hmd_all() { try { HMD Del_hmd_all = new HMD(); chloe_connect.Delete <HMD>(a => a.UserName != null); MessageBox.Show("删除全部成功!"); return(true); } catch (Exception e) { MessageBox.Show("删除全部失败!"); Console.WriteLine(e.ToString()); return(false); } }
/// <summary> /// Initialized all the components /// </summary> void Start() { newPoses = SteamVR_Events.NewPosesAction(OnNewPoses); newPoses.enabled = true; RegisterExistingPads(); HideGameObjectFromZED(); if (UnityEngine.XR.XRDevice.model.Contains("Oculus")) { model = HMD.OCULUS; } else { model = HMD.STEAMVR; } }
//管理员——删除黑名单 public bool del_hmd(String username) { try { HMD Del_hmd = new HMD(); Del_hmd.UserName = username; chloe_connect.Delete(Del_hmd); MessageBox.Show("删除成功!"); return(true); } catch (Exception e) { Console.WriteLine(e.ToString()); MessageBox.Show("删除失败!"); return(false); } }
//管理员——录入黑名单 public bool inser_hmd(String username, String realname) { try { HMD hmd_to_insert = new HMD(); hmd_to_insert.UserName = username; hmd_to_insert.RealName = realname; chloe_connect.Insert(hmd_to_insert); MessageBox.Show("插入成功"); return(true); } catch (Exception e) { Console.WriteLine(e.ToString()); MessageBox.Show("插入失败"); return(false); } }
private void UpdateCompass() { if (m_compassHolder == null) { Log.Error("m_compassHolder bar was null!"); return; } if (compass != null && compass.transform.localScale.x > 0.0037) { compass.transform.localScale = Vector3.one * 0.0036f; } m_compassHolder.SetActive(playerGUI.IsVisible()); if (m_compassHolder.activeSelf) { m_compassHolder.transform.position = GetCompassPosition(); m_compassHolder.transform.rotation = Quaternion.LookRotation(HMD.GetFlatForwardDirection()); } UpdateCompassCull(); }
/// <summary> /// If the player head is colliding with something or if an object like a door is between the camera and the true player agent position then /// we fade the screen. No cheating! /// </summary> public void HandleCameraInCollision() { m_fpsCameraInCollision = Physics.OverlapBox(HMD.GetWorldPosition() + HMD.GetWorldForward() * 0.05f, new Vector3(0.03f, 0.03f, 0.03f), HMD.Hmd.transform.rotation, LayerManager.MASK_TENTACLE_BLOCKERS).Length > 0; Vector3 centerPlayerHeadPos = VRPlayer.FpsCamera.GetCamerposForPlayerPos(m_agent.PlayerCharacterController.SmoothPosition); m_playerAgentToHMDPositionBlocked = Physics.Linecast(centerPlayerHeadPos, HMD.GetWorldPosition(), LayerManager.MASK_TENTACLE_BLOCKERS); if (m_playerAgentToHMDPositionBlocked || m_fpsCameraInCollision) { m_wasFadedLastFrame = true; SteamVR_Fade.Start(Color.black, 0.2f, true); return; } else if (m_wasFadedLastFrame) { SteamVR_Fade.Start(Color.clear, 0.2f, true); m_wasFadedLastFrame = false; } }
static void Postfix(FPSCamera __instance, PlayerAgent ___m_owner) { if (!PlayerVR.VRSetup) { return; } // Repeat position inject or the transforms will get out of sync (Unity transform handling mumbo jumbo ensues, frame later or frame behind tracking) if (VRSettings.VR_TRACKING_TYPE.Equals(TrackingType.PositionAndRotation) && !FocusStateManager.CurrentState.Equals(eFocusState.InElevator)) { __instance.Position = ___m_owner.PlayerCharacterController.SmoothPosition + HMD.GetPosition(); } if ((VRSettings.VR_TRACKING_TYPE.Equals(TrackingType.PositionAndRotation) || VRSettings.VR_TRACKING_TYPE.Equals(TrackingType.Rotation))) { Vector3 euler = HMD.GetVRCameraEulerRotation(); AccessTools.FieldRefAccess <LookCameraController, float>((LookCameraController)__instance, "m_pitch") = euler.x; AccessTools.FieldRefAccess <LookCameraController, float>((LookCameraController)__instance, "m_yaw") = euler.y; } }
/// <summary> /// Initializes a new instance of the <see cref="RiftGame" /> class. /// </summary> public RiftGame() { // Creates a graphics manager. This is mandatory. graphicsDeviceManager = new GraphicsDeviceManager(this); keyMgr = new KeyboardManager(this); //this.graphicsDeviceManager.IsFullScreen = true; // Setup the relative directory to the executable directory // for loading contents with the ContentManager Content.RootDirectory = "Content"; // Initialize OVR Library OVR.Initialize(); // Create our HMD hmd = OVR.HmdCreate(0) ?? OVR.HmdCreateDebug(HMDType.DK2); // Match back buffer size with HMD resolution graphicsDeviceManager.PreferredBackBufferWidth = hmd.Resolution.Width; graphicsDeviceManager.PreferredBackBufferHeight = hmd.Resolution.Height; }
protected void InitializeRift() { // Initialize OVR Library OVR.Initialize(); if (OVR.HmdDetect() < 1) { throw new IndexOutOfRangeException("No Rfft detected"); } // Create our HMD hmd = OVR.HmdCreate(0); if (hmd == null) { throw new IndexOutOfRangeException("Can't create Rift"); } SharpDX.Size2 left = hmd.GetFovTextureSize(EyeType.Left, hmd.DefaultEyeFov[0]); SharpDX.Size2 right = hmd.GetFovTextureSize(EyeType.Right, hmd.DefaultEyeFov[1]); leftEyeWidth = left.Width; leftEyeHeight = left.Height; rightEyeWidth = right.Width; rightEyeHeight = right.Height; // Create our render target eyeTexture[0] = hmd.CreateSwapTexture(RenderContext11.Device, riftFormat, left, false); eyeTexture[1] = hmd.CreateSwapTexture(RenderContext11.Device, riftFormat, right, false); swapTextures[0] = new SwapTextureSetD3D(eyeTexture[0].TextureSet); swapTextures[1] = new SwapTextureSetD3D(eyeTexture[1].TextureSet); // Create our layer layerEyeFov = new LayerEyeFov { Header = new LayerHeader(LayerType.EyeFov, LayerFlags.HighQuality), ColorTextureLeft = eyeTexture[0].TextureSet, ColorTextureRight = eyeTexture[1].TextureSet, ViewportLeft = new Rect(0, 0, eyeTexture[0].Size.Width, eyeTexture[0].Size.Height), ViewportRight = new Rect(0, 0, eyeTexture[1].Size.Width, eyeTexture[1].Size.Height), FovLeft = hmd.DefaultEyeFov[0], FovRight = hmd.DefaultEyeFov[1], }; // Keep eye view offsets eyeRenderDesc[0] = hmd.GetRenderDesc(EyeType.Left, hmd.DefaultEyeFov[0]); eyeRenderDesc[1] = hmd.GetRenderDesc(EyeType.Right, hmd.DefaultEyeFov[1]); hmdToEyeViewOffset[0] = eyeRenderDesc[0].HmdToEyeViewOffset; hmdToEyeViewOffset[1] = eyeRenderDesc[1].HmdToEyeViewOffset; // Create a mirror texture mirrorTexture = hmd.CreateMirrorTexture(RenderContext11.Device, RenderContext11.BackBuffer.Description); mirror = new Texture11(mirrorTexture); // Configure tracking hmd.ConfigureTracking(TrackingCapabilities.Orientation | TrackingCapabilities.Position | TrackingCapabilities.MagYawCorrection, TrackingCapabilities.None); // Set enabled capabilities hmd.EnabledCaps = HMDCapabilities.LowPersistence | HMDCapabilities.DynamicPrediction; riftInit = true; }