Created
January 26, 2017 09:58
-
-
Save flushpot1125/cffb3ab2a2cc0caa1d2902201669366b 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
/*copy from "https://developer.microsoft.com/en-us/windows/holographic/holograms_101"*/ | |
using UnityEngine; | |
public class WorldCursor : MonoBehaviour | |
{ | |
private MeshRenderer meshRenderer; | |
// Use this for initialization | |
void Start() | |
{ | |
// Grab the mesh renderer that's on the same object as this script. | |
meshRenderer = this.gameObject.GetComponentInChildren<MeshRenderer>(); | |
} | |
// Update is called once per frame | |
void Update() | |
{ | |
// Do a raycast into the world based on the user's | |
// head position and orientation. | |
var headPosition = Camera.main.transform.position; | |
var gazeDirection = Camera.main.transform.forward; | |
RaycastHit hitInfo; | |
if (Physics.Raycast(headPosition, gazeDirection, out hitInfo)) | |
{ | |
// If the raycast hit a hologram... | |
// Display the cursor mesh. | |
meshRenderer.enabled = true; | |
// Move the cursor to the point where the raycast hit. | |
this.transform.position = hitInfo.point; | |
// Rotate the cursor to hug the surface of the hologram. | |
this.transform.rotation = Quaternion.FromToRotation(Vector3.up, hitInfo.normal); | |
} | |
else | |
{ | |
// If the raycast did not hit a hologram, hide the cursor mesh. | |
meshRenderer.enabled = false; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment