Skip to content
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

Merged
merged 4 commits into from
May 12, 2016
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions Assets/HoloToolkit/SpatialMapping/Scripts/TapToPlace.cs
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.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tap gesture

/// 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.
Copy link

Choose a reason for hiding this comment

The 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;
Copy link

Choose a reason for hiding this comment

The 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;
}
}
}
}
}
12 changes: 12 additions & 0 deletions Assets/HoloToolkit/SpatialMapping/Scripts/TapToPlace.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading