This repository has been archived by the owner on Aug 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ported extension changes from pointer offset (#314)
- Loading branch information
1 parent
4254ee8
commit d05d79d
Showing
9 changed files
with
495 additions
and
237 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright (c) XRTK. All rights reserved. | ||
// Licensed under the MIT License. See LICENSE in the project root for license information. | ||
using UnityEngine; | ||
|
||
namespace XRTK.Extensions.XRTK.Extensions | ||
{ | ||
/// <summary> | ||
/// Extension methods for Unity's <see cref="BoxCollider"/> | ||
/// </summary> | ||
public static class BoxColliderExtensions | ||
{ | ||
/// <summary> | ||
/// Gets all the corner points of the collider's bounds in world space. | ||
/// </summary> | ||
/// <param name="collider"></param> | ||
/// <param name="transform"></param> | ||
/// <param name="positions"></param> | ||
public static void GetCornerPositionsWorldSpace(this BoxCollider collider, Transform transform, ref Vector3[] positions) | ||
{ | ||
// Store current rotation then zero out the rotation so that the bounds | ||
// are computed when the object is in its 'axis aligned orientation'. | ||
var currentRotation = transform.rotation; | ||
transform.rotation = Quaternion.identity; | ||
Physics.SyncTransforms(); // Update collider bounds | ||
|
||
var bounds = collider.bounds; | ||
bounds.GetCornerPositions(ref positions); | ||
|
||
// After bounds are computed, restore rotation... | ||
// ReSharper disable once Unity.InefficientPropertyAccess | ||
transform.rotation = currentRotation; | ||
Physics.SyncTransforms(); | ||
|
||
// Rotate our points in case the object is also rotated. | ||
for (int i = 0; i < positions.Length; i++) | ||
{ | ||
positions[i] = positions[i].RotateAroundPoint(bounds.center, transform.rotation); | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.