From 8ab7abf5af7e74d39480ed8f09371dfd3400ac94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A1lint=20Hodossy?= Date: Tue, 25 Jun 2024 14:12:04 +0100 Subject: [PATCH] Use MuJoCo calculated cartesian axes for hinge and slide --- unity/Runtime/Components/Joints/MjHingeJoint.cs | 9 ++++++++- unity/Runtime/Components/Joints/MjSlideJoint.cs | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/unity/Runtime/Components/Joints/MjHingeJoint.cs b/unity/Runtime/Components/Joints/MjHingeJoint.cs index 8549c738..9a997b6c 100644 --- a/unity/Runtime/Components/Joints/MjHingeJoint.cs +++ b/unity/Runtime/Components/Joints/MjHingeJoint.cs @@ -37,7 +37,14 @@ namespace Mujoco { public MjJointSettings Settings = MjJointSettings.Default; // World space rotation axis. - public Vector3 RotationAxis => transform.rotation * Vector3.right; + public unsafe Vector3 RotationAxis { + get { + if (MjScene.InstanceExists) { + return MjEngineTool.UnityVector3(MjScene.Instance.Data->xaxis + 3 * MujocoId); + } + return transform.rotation * Vector3.right; + } + } protected override unsafe void OnBindToRuntime(MujocoLib.mjModel_* model, MujocoLib.mjData_* data) { base.OnBindToRuntime(model, data); diff --git a/unity/Runtime/Components/Joints/MjSlideJoint.cs b/unity/Runtime/Components/Joints/MjSlideJoint.cs index fa63c6b2..a32895b0 100644 --- a/unity/Runtime/Components/Joints/MjSlideJoint.cs +++ b/unity/Runtime/Components/Joints/MjSlideJoint.cs @@ -35,7 +35,14 @@ namespace Mujoco { public MjJointSettings Settings = MjJointSettings.Default; // World space slide axis. - public Vector3 SlideAxis => transform.rotation * Vector3.right; + public unsafe Vector3 SlideAxis { + get { + if (MjScene.InstanceExists) { + return MjEngineTool.UnityVector3(MjScene.Instance.Data->xaxis + 3 * MujocoId); + } + return transform.rotation * Vector3.right; + } + } protected override unsafe void OnBindToRuntime(MujocoLib.mjModel_* model, MujocoLib.mjData_* data) { base.OnBindToRuntime(model, data);