| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | using System; |
| | using UnityEngine; |
| |
|
| | namespace Mujoco { |
| |
|
| | |
| | |
| | public struct MjTransformation { |
| | public Vector3 Translation; |
| | public Quaternion Rotation; |
| |
|
| | public MjTransformation(Vector3 translation, Quaternion rotation) { |
| | Translation = translation; |
| | Rotation = rotation; |
| | } |
| |
|
| | public void Set(Vector3 translation, Quaternion rotation) { |
| | Translation = translation; |
| | Rotation = rotation; |
| | } |
| |
|
| | |
| | public static MjTransformation LoadGlobal(Transform transform) { |
| | if (transform != null) { |
| | return new MjTransformation(transform.position, transform.rotation); |
| | } else { |
| | return new MjTransformation(Vector3.zero, Quaternion.identity); |
| | } |
| | } |
| |
|
| | |
| | public static MjTransformation LoadLocal(Transform transform) { |
| | if (transform != null) { |
| | return new MjTransformation(transform.localPosition, transform.localRotation); |
| | } else { |
| | return new MjTransformation(Vector3.zero, Quaternion.identity); |
| | } |
| | } |
| |
|
| | |
| | public void StoreGlobal(Transform transform) { |
| | transform.position = Translation; |
| | transform.rotation = Rotation; |
| | } |
| |
|
| | |
| | public void StoreLocal(Transform transform) { |
| | transform.localPosition = Translation; |
| | transform.localRotation = Rotation; |
| | } |
| |
|
| | |
| | |
| | public static MjTransformation operator *( |
| | MjTransformation lhs, MjTransformation rhs) { |
| | return new MjTransformation( |
| | lhs.Translation + lhs.Rotation * rhs.Translation, lhs.Rotation * rhs.Rotation); |
| | } |
| |
|
| | |
| | public MjTransformation Inverse() { |
| | var inverseRotation = Quaternion.Inverse(Rotation); |
| | return new MjTransformation(inverseRotation * Translation * -1.0f, inverseRotation); |
| | } |
| |
|
| | public override string ToString() { |
| | return $"[{Translation}, {Rotation}]"; |
| | } |
| | } |
| | } |
| |
|