-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding TapToPlace #31
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. See LICENSE in the project root for license information. | ||
|
||
using UnityEngine; | ||
|
||
namespace HoloToolkit.Unity | ||
{ | ||
/// <summary> | ||
/// The TapToPlace class is a basic way to enable users to move objects | ||
/// and place them on real world surfaces. | ||
/// Put this script on the object you want to be able to move. | ||
/// Users will be able to select objects, gaze elsewhere, and perform the | ||
/// select gesture again to place. | ||
/// This script is used in conjunction with GazeManager, GestureManager, | ||
/// and SpatialMappingManager. | ||
/// </summary> | ||
|
||
public partial class TapToPlace : MonoBehaviour | ||
{ | ||
bool placing = false; | ||
|
||
// Called by GazeGestureManager when the user performs a Select gesture. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ... performs a Tap 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) | ||
{ | ||
SpatialMappingManager.Instance.DrawVisualMeshes = true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if SpatialMappingManager is null? |
||
} | ||
// If the user is not in placing mode, hide the spatial mapping mesh. | ||
else | ||
{ | ||
SpatialMappingManager.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, SpatialMappingManager.Instance.LayerMask)) | ||
{ | ||
// Move this object to where the raycast | ||
// hit the Spatial Mapping mesh. | ||
// Here is where you might consider adding intelligence | ||
// to how the object is placed. For example, consider | ||
// placing based on the bottom of the object's | ||
// collider so it sits properly on surfaces. | ||
this.transform.position = hitInfo.point; | ||
|
||
// Rotate this object to face the user. | ||
Quaternion toQuat = Camera.main.transform.localRotation; | ||
toQuat.x = 0; | ||
toQuat.z = 0; | ||
this.transform.rotation = toQuat; | ||
} | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tap gesture