Skip to content

Commit

Permalink
Maybe fix unit test?
Browse files Browse the repository at this point in the history
  • Loading branch information
mtheall committed May 5, 2024
1 parent 8ee9a33 commit 09c8d07
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
2 changes: 1 addition & 1 deletion python-mtheall/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ wheel: build
$(PYTHON) ../setup.py bdist_wheel --py-limited-api=cp34

install: wheel
$(PYTHON) -m pip install --force-reinstall --user ./dist/RocketSim-2.1.0a3-cp34-abi3-linux_x86_64.whl
$(PYTHON) -m pip install --force-reinstall --user ./dist/RocketSim-2.1.0a4-cp34-abi3-linux_x86_64.whl

clean:
$(RM) -r build/ dist/ RocketSim.egg-info/
26 changes: 18 additions & 8 deletions python-mtheall/unit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1771,12 +1771,14 @@ def compare_quat(q1: np.ndarray, q2: np.ndarray) -> bool:
def pyr_to_mat3(pyr: np.ndarray) -> np.ndarray:
# what
pitch, yaw, roll = pyr
q = glm.normalize(glm.angleAxis(yaw, z))
q = q * glm.normalize(glm.angleAxis(pitch, y))
q = q * glm.normalize(glm.angleAxis(roll, -x))

q = glm.rotate(glm.quat(), yaw, z)
q = glm.rotate(q, pitch, y)
q = glm.rotate(q, -roll, x)

return np.array(glm.mat3_cast(q))

def check_pyr(pyr: np.ndarray) -> bool:
def check_pyr(pyr: np.ndarray, m: glm.mat3) -> bool:
pitch, yaw, roll = pyr

if abs(pitch) > math.pi / 2.0:
Expand All @@ -1791,6 +1793,16 @@ def check_pyr(pyr: np.ndarray) -> bool:
print(roll)
return False

x = glm.vec3(1, 0, 0)
y = glm.vec3(0, 1, 0)
z = glm.vec3(0, 0, 1)

pyr_mat = glm.mat3(pyr_to_mat3(pyr))

self.assertAlmostEqual(glm.dot(pyr_mat * x, m * x), 1.0, 5)
self.assertAlmostEqual(glm.dot(pyr_mat * y, m * y), 1.0, 5)
self.assertAlmostEqual(glm.dot(pyr_mat * z, m * z), 1.0, 5)

return True

for mode in (rs.GameMode.SOCCAR, rs.GameMode.HOOPS, rs.GameMode.HEATSEEKER, rs.GameMode.SNOWDAY, rs.GameMode.THE_VOID):
Expand Down Expand Up @@ -1935,8 +1947,7 @@ def check_pyr(pyr: np.ndarray) -> bool:
q = glm.quat_cast(m)
pyr = gym_state[33:36]
compare_quat(gym_state[14:18], np.array(q))
self.assertAlmostEqual(np.array(m), pyr_to_mat3(pyr), 4)
self.assertTrue(check_pyr(pyr))
self.assertTrue(check_pyr(pyr, m))

self.assertAlmostEqual(glm.dot(car_dir_x, m * x), 1.0, 5)
self.assertAlmostEqual(glm.dot(car_dir_y, m * y), 1.0, 5)
Expand Down Expand Up @@ -1967,8 +1978,7 @@ def check_pyr(pyr: np.ndarray) -> bool:
q = glm.quat_cast(m)
pyr = gym_state[33:36]
compare_quat(gym_state[14:18], np.array(q))
self.assertAlmostEqual(np.array(m), pyr_to_mat3(pyr), 4)
self.assertTrue(check_pyr(pyr))
self.assertTrue(check_pyr(pyr, m))

self.assertAlmostEqual(glm.dot(invert_vector(car_dir_x), m * x), 1.0, 5)
self.assertAlmostEqual(glm.dot(invert_vector(car_dir_y), m * y), 1.0, 5)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def build_extension(self, ext):

setup(
name = "RocketSim",
version = "2.1.0a3",
version = "2.1.0a4",
description = "This is Rocket League!",
cmdclass = {"build_ext": build_ext_ex},
ext_modules = [RocketSim],
Expand Down

0 comments on commit 09c8d07

Please sign in to comment.