Created
January 29, 2017 04:34
-
-
Save flushpot1125/45b84fc58f92a86ae0b40f5acacf3737 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
/*copied from "https://developer.microsoft.com/en-us/windows/holographic/holograms_101"*/ | |
using UnityEngine; | |
public class TapToPlaceParent : MonoBehaviour | |
{ | |
bool placing = false; | |
// Called by GazeGestureManager when the user performs a Select gesture | |
void OnSelect() | |
{ | |
// On each Select gesture, toggle whether the user is in placing mode. | |
placing = !placing; | |
// If the user is in placing mode, display the spatial mapping mesh. | |
if (placing) | |
{ | |
SpatialMapping.Instance.DrawVisualMeshes = true; | |
} | |
// If the user is not in placing mode, hide the spatial mapping mesh. | |
else | |
{ | |
SpatialMapping.Instance.DrawVisualMeshes = false; | |
} | |
} | |
// Update is called once per frame | |
void Update() | |
{ | |
// If the user is in placing mode, | |
// update the placement to match the user's gaze. | |
if (placing) | |
{ | |
// Do a raycast into the world that will only hit the Spatial Mapping mesh. | |
var headPosition = Camera.main.transform.position; | |
var gazeDirection = Camera.main.transform.forward; | |
RaycastHit hitInfo; | |
if (Physics.Raycast(headPosition, gazeDirection, out hitInfo, | |
30.0f, SpatialMapping.PhysicsRaycastMask)) | |
{ | |
// Move this object's parent object to | |
// where the raycast hit the Spatial Mapping mesh. | |
this.transform.parent.position = hitInfo.point; | |
// Rotate this object's parent object to face the user. | |
Quaternion toQuat = Camera.main.transform.localRotation; | |
toQuat.x = 0; | |
toQuat.z = 0; | |
this.transform.parent.rotation = toQuat; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment