Last active
November 3, 2018 20:51
-
-
Save vaghniku/8e03b7341173866ceea96f71fade240a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using UnityEngine.VR; | |
using Valve.VR; | |
public class Cubeoverlay : MonoBehaviour | |
{ | |
public GameObject Cube; | |
private RenderTexture renderTexture { get; set; } | |
private ulong OverlayHandle; | |
public Camera mainCamera; | |
private uint openvrid; | |
void Start() | |
{ | |
OverlayHandle = Valve.VR.OpenVR.k_ulOverlayHandleInvalid; | |
HmdColor_t hmdColor_T = new HmdColor_t(); | |
hmdColor_T.a = 1; | |
hmdColor_T.b = 1; | |
hmdColor_T.g = 1; | |
hmdColor_T.r = 1; | |
Debug.Log(gameObject.name); | |
Debug.Log(OverlayHandle.ToString()); | |
OpenVR.Overlay.CreateOverlay(gameObject.name, gameObject.name, ref OverlayHandle); | |
OpenVR.Overlay.SetOverlayRenderModel(OverlayHandle, Cube.name, ref hmdColor_T); | |
OpenVR.Overlay.ShowOverlay(OverlayHandle); | |
RenderTexture renderTexture = new RenderTexture(1000, 1000, 1000); | |
mainCamera.targetTexture = renderTexture; | |
SteamVR_Camera Cam = SteamVR_Render.Top(); | |
SteamVR_Utils.RigidTransform offset = new SteamVR_Utils.RigidTransform(transform); | |
offset.pos.x /= Cam.origin.localScale.x; | |
offset.pos.y /= Cam.origin.localScale.y; | |
offset.pos.z /= Cam.origin.localScale.z; | |
HmdMatrix34_t matrix = offset.ToHmdMatrix34(); | |
OpenVR.Overlay.SetOverlayTransformTrackedDeviceRelative(OverlayHandle, OpenVR.k_unTrackedDeviceIndexInvalid, ref matrix); | |
Texture_t overlayTexture = new Texture_t(); | |
overlayTexture.handle = renderTexture.GetNativeTexturePtr(); | |
OpenVR.Overlay.SetOverlayTexture(OverlayHandle, ref overlayTexture); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment