Skip to content

Commit bb912a2

Browse files
committed
fix: Boundary with matrix
1 parent 3973941 commit bb912a2

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

Assets/JCSUnity/Scripts/Actions/JCS_Boundary.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ public class JCS_Boundary : MonoBehaviour
3434
private void OnDrawGizmosSelected()
3535
{
3636
Gizmos.color = mWireColor;
37-
Gizmos.DrawWireCube(transform.position, transform.localScale);
37+
Gizmos.matrix = transform.localToWorldMatrix;
38+
Gizmos.DrawWireCube(Vector3.zero, Vector3.one);
3839
}
3940
#endif
4041

@@ -43,7 +44,21 @@ private void OnDrawGizmosSelected()
4344
/// </summary>
4445
public Bounds GetBounds()
4546
{
46-
return new Bounds(transform.position, transform.localScale);
47+
Matrix4x4 matrix = transform.localToWorldMatrix;
48+
49+
// Transform each corner to world space
50+
Vector3 worldCorner = matrix.MultiplyPoint3x4(JCS_Constants.CORNERS_CUBE[0]);
51+
52+
var bounds = new Bounds(worldCorner, Vector3.zero);
53+
54+
for (int index = 1; index < JCS_Constants.CORNERS_CUBE.Length; ++index)
55+
{
56+
worldCorner = matrix.MultiplyPoint3x4(JCS_Constants.CORNERS_CUBE[index]);
57+
58+
bounds.Encapsulate(worldCorner);
59+
}
60+
61+
return bounds;
4762
}
4863
}
4964
}

Assets/JCSUnity/Scripts/JCS_Constants.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* $Notice: See LICENSE.txt for modification and distribution information
77
* Copyright (c) 2016 by Shen, Jen-Chieh $
88
*/
9+
using UnityEngine;
910

1011
namespace JCSUnity
1112
{
@@ -16,6 +17,8 @@ public static class JCS_Constants
1617
{
1718
/* Variables */
1819

20+
#region System
21+
1922
// The time delay to be invoked for the first frame.
2023
//
2124
// First frame invocation can't be set to 0; therefore, we set
@@ -25,6 +28,27 @@ public static class JCS_Constants
2528
// See https://docs.unity3d.com/6000.1/Documentation/ScriptReference/MonoBehaviour.Invoke.html
2629
public const float FIRST_FRAME_INVOKE_TIME = 0.001f;
2730

31+
#endregion
32+
33+
#region Matrix
34+
35+
// Define the 8 corners of a unit cube centered at `Vector3.zero`.
36+
public static readonly Vector3[] CORNERS_CUBE = new Vector3[]
37+
{
38+
new Vector3(-0.5f, -0.5f, -0.5f),
39+
new Vector3(-0.5f, -0.5f, 0.5f),
40+
new Vector3(-0.5f, 0.5f, -0.5f),
41+
new Vector3(-0.5f, 0.5f, 0.5f),
42+
new Vector3( 0.5f, -0.5f, -0.5f),
43+
new Vector3( 0.5f, -0.5f, 0.5f),
44+
new Vector3( 0.5f, 0.5f, -0.5f),
45+
new Vector3( 0.5f, 0.5f, 0.5f),
46+
};
47+
48+
#endregion
49+
50+
#region Effect
51+
2852
// The minimum friction value.
2953
public const float FRICTION_MIN = 0.01f;
3054

@@ -34,6 +58,8 @@ public static class JCS_Constants
3458
// Below this threshold is consider close enough.
3559
public const float NEAR_THRESHOLD = 0.01f;
3660

61+
#endregion
62+
3763
/* Setter & Getter */
3864

3965
/* Functions */

0 commit comments

Comments
 (0)