Skip to content

Commit

Permalink
fix to cached object oriented bounds rotation assignment
Browse files Browse the repository at this point in the history
-fixing bug where the cached object oriented bounds for pickupable and moveable sim objects was not assigning the rotation of the bounds correctly.

-the boundingBox child object's `rotation` was being set, where the `localRotation` should have been being set

-This should fix all sim objects having more accurate placement in all actions requiring the cached bounding box values (PutObject, InitialRandomSpawn, etc)
  • Loading branch information
winthos committed Jan 10, 2022
1 parent 4741805 commit ba31911
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
2 changes: 1 addition & 1 deletion unity/Assets/Scripts/SimObjPhysics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ private ObjectOrientedBoundingBox objectOrientedBoundingBox() {

// Update SimObject's BoundingBox collider to match new bounds
this.BoundingBox.transform.localPosition = Vector3.zero;
this.BoundingBox.transform.rotation = Quaternion.identity;
this.BoundingBox.transform.localRotation = Quaternion.identity;
this.BoundingBox.GetComponent<BoxCollider>().center = newBB.center;
this.BoundingBox.GetComponent<BoxCollider>().size = newBB.extents * 2.0f;

Expand Down
42 changes: 42 additions & 0 deletions unity/Assets/UnitTests/TestCachedObjectOrientedBoundsRotation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;
using System;
using UnityEngine;
using UnityEngine.TestTools;
using UnityStandardAssets.Characters.FirstPerson;

namespace Tests {
public class TestCachedObjectOrientedBoundsRotation : TestBase
{

//check to make sure the automatic caching of the object oriented bounds is assigning
//the localRotation of the BoundingBox child object of any given SimObject is set to
//(0,0,0) or Quaternion.identity, correctly
[UnityTest]
public IEnumerator TestCachedBoundsRotation() {
Dictionary<string, object> action = new Dictionary<string, object>();

action["action"] = "Initialize";
action["fieldOfView"] = 90f;
action["snapToGrid"] = true;
yield return step(action);

GameObject book = GameObject.Find("Book_3d15d052");

bool result = false;
GameObject boundingBox = book.transform.Find("BoundingBox").gameObject;

result = Mathf.Approximately(boundingBox.transform.localRotation.x, 0.0f);
Assert.AreEqual(result, true);

result = Mathf.Approximately(boundingBox.transform.localRotation.y, 0.0f);
Assert.AreEqual(result, true);

result = Mathf.Approximately(boundingBox.transform.localRotation.z, 0.0f);
Assert.AreEqual(result, true);
}
}
}


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

0 comments on commit ba31911

Please sign in to comment.