GitBucket
4.21.2
Toggle navigation
Snippets
Sign in
Files
Branches
1
Releases
Issues
Pull requests
Labels
Priorities
Milestones
Wiki
Forks
jack.wynne
/
HoloLens_Scripts_and_Docs
Browse code
ttp extended
master
1 parent
f9c880c
commit
5451cb11b28f769eedcbf19a95b089a2592c9a10
wynja439@student.otago
authored
on 13 Jul 2017
Patch
Showing
1 changed file
TapToPlace_MoveUpByHalfHeight.cs
Ignore Space
Show notes
View
TapToPlace_MoveUpByHalfHeight.cs
0 → 100644
using HoloToolkit.Unity.SpatialMapping; using System.Collections; using System.Collections.Generic; using UnityEngine; public class TapToPlace_MoveUpByHalfHeight : TapToPlace { protected override void Update () { // If the user is in placing mode, // update the placement to match the user's gaze. if (IsBeingPlaced) { // Do a raycast into the world that will only hit the Spatial Mapping mesh. Vector3 headPosition = Camera.main.transform.position; Vector3 gazeDirection = Camera.main.transform.forward; RaycastHit hitInfo; if (Physics.Raycast(headPosition, gazeDirection, out hitInfo, 30.0f, spatialMappingManager.LayerMask)) { // Rotate this object to face the user. Quaternion toQuat = Camera.main.transform.localRotation; toQuat.x = 0; toQuat.z = 0; float halfY = (gameObject.GetComponent<Collider>().bounds.size.y) / 2; Vector3 pos = hitInfo.point; pos.y = hitInfo.point.y + halfY; // Move this object to where the raycast // hit the Spatial Mapping mesh. if (PlaceParentOnTap) { // Place the parent object as well but keep the focus on the current game object Vector3 currentMovement = hitInfo.point - gameObject.transform.position; ParentGameObjectToPlace.transform.position += currentMovement; ParentGameObjectToPlace.transform.rotation = toQuat; } else { gameObject.transform.position = pos; gameObject.transform.rotation = toQuat; } } } } }
Show line notes below