Skip to content

Commit bf12114

Browse files
committed
fix: boundary calculation
1 parent bb912a2 commit bf12114

File tree

3 files changed

+17
-15
lines changed

3 files changed

+17
-15
lines changed

Assets/JCSUnity/Scripts/Actions/JCS_Boundary.cs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ public class JCS_Boundary : MonoBehaviour
3434
private void OnDrawGizmosSelected()
3535
{
3636
Gizmos.color = mWireColor;
37-
Gizmos.matrix = transform.localToWorldMatrix;
38-
Gizmos.DrawWireCube(Vector3.zero, Vector3.one);
37+
Bounds b = GetBounds();
38+
Gizmos.DrawWireCube(b.center, b.size);
3939
}
4040
#endif
4141

@@ -44,20 +44,22 @@ private void OnDrawGizmosSelected()
4444
/// </summary>
4545
public Bounds GetBounds()
4646
{
47-
Matrix4x4 matrix = transform.localToWorldMatrix;
47+
// Transform all corners into world space
48+
Vector3 min = Vector3.positiveInfinity;
49+
Vector3 max = Vector3.negativeInfinity;
4850

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)
51+
foreach (Vector3 corner in JCS_Constants.CORNERS_CUBE)
5552
{
56-
worldCorner = matrix.MultiplyPoint3x4(JCS_Constants.CORNERS_CUBE[index]);
53+
// Scale, then rotate and translate
54+
Vector3 worldCorner = transform.TransformPoint(corner);
5755

58-
bounds.Encapsulate(worldCorner);
56+
min = Vector3.Min(min, worldCorner);
57+
max = Vector3.Max(max, worldCorner);
5958
}
6059

60+
var bounds = new Bounds();
61+
bounds.SetMinMax(min, max);
62+
6163
return bounds;
6264
}
6365
}

Assets/JCSUnity/Scripts/JCS_Camera.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ public Vector3 CanvasToWorldSpace(Vector2 targetCanvasPos)
607607
//first you need the RectTransform component of your canvas
608608
RectTransform canvasRect = JCS_Canvas.GuessCanvas().AppRect;
609609

610-
Vector2 canvasObject_WorldPosition = new Vector2(
610+
var canvasObject_WorldPosition = new Vector2(
611611
((targetCanvasPos.x + (canvasRect.sizeDelta.x * JCS_Mathf.T_HALF)) / canvasRect.sizeDelta.x),
612612
((targetCanvasPos.y + (canvasRect.sizeDelta.y * JCS_Mathf.T_HALF)) / canvasRect.sizeDelta.y));
613613

Assets/_Project/Scenes/Action/CameraBoundary.unity

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -449,13 +449,13 @@ Transform:
449449
m_PrefabAsset: {fileID: 0}
450450
m_GameObject: {fileID: 430542425}
451451
serializedVersion: 2
452-
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
453-
m_LocalPosition: {x: 0, y: 0, z: 0}
452+
m_LocalRotation: {x: 0, y: 0.38268343, z: 0, w: 0.92387956}
453+
m_LocalPosition: {x: 2.084, y: 0, z: 2.604}
454454
m_LocalScale: {x: 2.1457, y: 1.4936, z: 1}
455455
m_ConstrainProportionsScale: 0
456456
m_Children: []
457457
m_Father: {fileID: 0}
458-
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
458+
m_LocalEulerAnglesHint: {x: 0, y: 45, z: 0}
459459
--- !u!114 &430542427
460460
MonoBehaviour:
461461
m_ObjectHideFlags: 0

0 commit comments

Comments
 (0)