39 Quaternion invQ = Quaternion.Inverse(this.rotation);
40 return new Pose(invQ * -this.position, invQ.ToNormalized());
50 this.rotation = this.rotation.ToNormalized();
51 return Matrix4x4.TRS(this.position, this.rotation, Vector3.one);
60 return new Pose(
A.position + (
A.rotation *
B.position),
61 A.rotation *
B.rotation);
71 return new Pose(
A.position +
B.position,
72 A.rotation *
B.rotation);
85 return pose *
new Pose(Vector3.zero, localRotation);
89 return new Pose(Vector3.zero, parentRotation) * localPose;
108 if (t >= 1f)
return b;
109 if (t <= 0f)
return a;
111 Quaternion.Lerp(Quaternion.Slerp(a.
rotation, b.
rotation, t), Quaternion.identity, 0f));
129 float extrapolateTime) {
130 return LerpUnclamped(a, b, extrapolateTime.MapUnclamped(aTime, bTime, 0f, 1f));
134 return "[Pose | Position: " + this.position.ToString()
135 +
", Rotation: " + this.rotation.ToString() +
"]";
139 return "[Pose | Position: " + this.position.ToString(format)
140 +
", Rotation: " + this.rotation.ToString(format) +
"]";
143 public override bool Equals(
object obj) {
144 if (!(obj is
Pose))
return false;
145 else return this.
Equals((Pose)obj);
148 return other.
position == this.position &&
180 centripetal:
false).PositionAt(t);
187 public static class PoseExtensions {
192 public static Pose ToLocalPose(
this Transform t) {
193 return new Pose(t.localPosition, t.localRotation);
199 public static Pose ToPose(
this Transform t) {
200 return new Pose(t.position, t.rotation);
206 public static Pose GetPose(
this Transform t) {
207 return new Pose(t.position, t.rotation);
213 public static Pose ToWorldPose(
this Transform t) {
221 public static void SetLocalPose(
this Transform t, Pose localPose) {
222 t.localPosition = localPose.position;
223 t.localRotation = localPose.rotation;
229 public static void SetPose(
this Transform t, Pose worldPose) {
230 t.position = worldPose.position;
231 t.rotation = worldPose.rotation;
238 public static void SetWorldPose(
this Transform t, Pose worldPose) {
239 t.SetPose(worldPose);
245 public static Pose GetPose(
this Matrix4x4 m) {
246 return new Pose(position: m.MultiplyPoint3x4(
Vector3.zero),
247 rotation: m.GetQuaternion());
259 public static Pose WithRotation(
this Pose pose, Quaternion newRotation) {
260 return new Pose(pose.position, newRotation);
267 public static Pose WithPosition(
this Pose pose, Vector3 newPosition) {
268 return new Pose(newPosition, pose.rotation);
271 public const float EPSILON = 0.0001f;
273 public static bool ApproxEquals(
this Vector3 v0, Vector3 v1) {
274 return (v0 - v1).magnitude < EPSILON;
277 public static bool ApproxEquals(
this Quaternion q0, Quaternion q1) {
278 return (q0.ToAngleAxisVector() - q1.ToAngleAxisVector()).magnitude < EPSILON;
An interface that signifies this class can interpolate via the standard techniques
A position and rotation. You can multiply two poses; this acts like Matrix4x4 multiplication,...
static bool operator==(Pose a, Pose b)
bool FillSplined(Pose a, Pose b, Pose c, Pose d, float t)
static Pose operator+(Pose A, Pose B)
Returns the accumulation of the two poses: The positions summed, and with rotation A....
Pose(Quaternion rotation)
static Pose LerpUnclampedTimed(Pose a, float aTime, Pose b, float bTime, float extrapolateTime)
As LerpUnclamped, but extrapolates using time values for a and b, and a target time at which to deter...
bool FillLerped(Pose a, Pose b, float t)
override string ToString()
static Pose LerpUnclamped(Pose a, Pose b, float t)
As Lerp, but doesn't clamp t between 0 and 1. Values above one extrapolate forwards beyond b,...
Pose(Vector3 position, Quaternion rotation)
Matrix4x4 matrix
Returns a Matrix4x4 corresponding to this pose's translation and rotation, with unit scale.
static Pose operator*(Pose A, Pose B)
Returns Pose B transformed by Pose A, like a transform hierarchy with A as the parent of B.
override int GetHashCode()
string ToString(string format)
bool ApproxEquals(Pose other)
static Pose Lerp(Pose a, Pose b, float t)
Returns a pose interpolated (Lerp for position, Slerp, NOT Lerp for rotation) between a and b by t fr...
override bool Equals(object obj)
static readonly Pose identity
static bool operator!=(Pose a, Pose b)