1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
|
using Unity.Mathematics;
using UnityEngine;
namespace Pathfinding.Util {
/// <summary>
/// Transforms to and from world space to a 2D movement plane.
/// The transformation is guaranteed to be purely a rotation
/// so no scale or offset is used. This interface is primarily
/// used to make it easier to write movement scripts which can
/// handle movement both in the XZ plane and in the XY plane.
///
/// See: <see cref="Pathfinding.Util.GraphTransform"/>
/// </summary>
public interface IMovementPlane {
Vector2 ToPlane(Vector3 p);
Vector2 ToPlane(Vector3 p, out float elevation);
Vector3 ToWorld(Vector2 p, float elevation = 0);
SimpleMovementPlane ToSimpleMovementPlane();
}
/// <summary>
/// A matrix wrapper which can be used to project points from world space to a movement plane.
///
/// In contrast to <see cref="NativeMovementPlane"/>, this is represented by a matrix instead of a quaternion.
/// This means it is less space efficient (36 bytes instead of 16 bytes) but it is more performant when
/// you need to do a lot of ToPlane conversions.
/// </summary>
public readonly struct ToPlaneMatrix {
public readonly float3x3 matrix;
public ToPlaneMatrix (NativeMovementPlane plane) => this.matrix = new float3x3(math.conjugate(plane.rotation));
/// <summary>
/// Transforms from world space to the 'ground' plane of the graph.
/// The transformation is purely a rotation so no scale or offset is used.
///
/// See: <see cref="NativeMovementPlane.ToPlane(float3)"/>
/// </summary>
public float2 ToPlane(float3 p) => math.mul(matrix, p).xz;
/// <summary>
/// Transforms from world space to the 'ground' plane of the graph.
/// The transformation is purely a rotation so no scale or offset is used.
///
/// The elevation coordinate will be returned as the y coordinate of the returned vector.
///
/// See: <see cref="NativeMovementPlane.ToPlane(float3)"/>
/// </summary>
public float3 ToXZPlane(float3 p) => math.mul(matrix, p);
/// <summary>
/// Transforms from world space to the 'ground' plane of the graph.
/// The transformation is purely a rotation so no scale or offset is used.
///
/// See: <see cref="NativeMovementPlane.ToPlane(float3)"/>
/// </summary>
public float2 ToPlane (float3 p, out float elevation) {
var v = math.mul(matrix, p);
elevation = v.y;
return v.xz;
}
}
/// <summary>
/// A matrix wrapper which can be used to project points from a movement plane to world space.
///
/// In contrast to <see cref="NativeMovementPlane"/>, this is represented by a matrix instead of a quaternion.
/// This means it is less space efficient (36 bytes instead of 16 bytes) but it is more performant when
/// you need to do a lot of ToWorld conversions.
/// </summary>
public readonly struct ToWorldMatrix {
public readonly float3x3 matrix;
public ToWorldMatrix (NativeMovementPlane plane) => this.matrix = new float3x3(plane.rotation);
public ToWorldMatrix (float3x3 matrix) => this.matrix = matrix;
public float3 ToWorld(float2 p, float elevation = 0) => math.mul(matrix, new float3(p.x, elevation, p.y));
/// <summary>
/// Transforms a bounding box from local space to world space.
///
/// The Y coordinate of the bounding box is the elevation coordinate.
///
/// See: https://zeux.io/2010/10/17/aabb-from-obb-with-component-wise-abs/
/// </summary>
public Bounds ToWorld (Bounds bounds) {
Bounds result = default;
result.center = math.mul(matrix, (float3)bounds.center);
result.extents = math.mul(new float3x3(
math.abs(matrix.c0),
math.abs(matrix.c1),
math.abs(matrix.c2)
), (float3)bounds.extents);
return result;
}
}
/// <summary>A variant of <see cref="SimpleMovementPlane"/> that can be passed to burst functions</summary>
public readonly struct NativeMovementPlane {
/// <summary>
/// The rotation of the plane.
/// The plane is defined by the XZ-plane rotated by this quaternion.
///
/// Should always be normalized.
/// </summary>
public readonly quaternion rotation;
/// <summary>Normal of the plane</summary>
// TODO: Check constructor for float3x3(quaternion), seems smarter, at least in burst
public float3 up => 2 * new float3(rotation.value.x * rotation.value.y - rotation.value.w * rotation.value.z, 0.5f - rotation.value.x * rotation.value.x - rotation.value.z * rotation.value.z, rotation.value.w * rotation.value.x + rotation.value.y * rotation.value.z); // math.mul(rotation, Vector3.up);
public NativeMovementPlane(quaternion rotation) {
// We need to normalize to make sure that math.inverse(rotation) == math.conjugate(rotation).
// We want to use conjugate because it's faster.
this.rotation = math.normalizesafe(rotation);
}
public NativeMovementPlane(SimpleMovementPlane plane) : this(plane.rotation) {}
public ToPlaneMatrix AsWorldToPlaneMatrix() => new ToPlaneMatrix(this);
public ToWorldMatrix AsPlaneToWorldMatrix() => new ToWorldMatrix(this);
public float ProjectedLength(float3 v) => math.length(ToPlane(v));
/// <summary>
/// Transforms from world space to the 'ground' plane of the graph.
/// The transformation is purely a rotation so no scale or offset is used.
///
/// For a graph rotated with the rotation (-90, 0, 0) this will transform
/// a coordinate (x,y,z) to (x,y). For a graph with the rotation (0,0,0)
/// this will tranform a coordinate (x,y,z) to (x,z). More generally for
/// a graph with a quaternion rotation R this will transform a vector V
/// to inverse(R) * V (i.e rotate the vector V using the inverse of rotation R).
/// </summary>
public float2 ToPlane (float3 p) {
return math.mul(math.conjugate(rotation), p).xz;
}
/// <summary>Transforms from world space to the 'ground' plane of the graph</summary>
public float2 ToPlane (float3 p, out float elevation) {
p = math.mul(math.conjugate(rotation), p);
elevation = p.y;
return p.xz;
}
/// <summary>
/// Transforms from the 'ground' plane of the graph to world space.
/// The transformation is purely a rotation so no scale or offset is used.
/// </summary>
public float3 ToWorld (float2 p, float elevation = 0f) {
return math.mul(rotation, new float3(p.x, elevation, p.y));
}
/// <summary>
/// Projects a rotation onto the plane.
///
/// The returned angle is such that
///
/// <code>
/// var angle = ...;
/// var q = math.mul(plane.rotation, quaternion.RotateY(angle));
/// AstarMath.DeltaAngle(plane.ToPlane(q), -angle) == 0; // or at least approximately equal
/// </code>
///
/// See: <see cref="ToWorldRotation"/>
/// See: <see cref="ToWorldRotationDelta"/>
/// </summary>
/// <param name="rotation">the rotation to project</param>
public float ToPlane (quaternion rotation) {
var inPlaneRotation = math.mul(math.conjugate(this.rotation), rotation);
// Ensure the rotation axis is always along +Y
if (inPlaneRotation.value.y < 0) inPlaneRotation.value = -inPlaneRotation.value;
var twist = math.normalizesafe(new quaternion(0, inPlaneRotation.value.y, 0, inPlaneRotation.value.w));
return -VectorMath.QuaternionAngle(twist);
}
public quaternion ToWorldRotation (float angle) {
return math.mul(rotation, quaternion.RotateY(-angle));
}
public quaternion ToWorldRotationDelta (float deltaAngle) {
return quaternion.AxisAngle(ToWorld(float2.zero, 1), -deltaAngle);
}
/// <summary>
/// Transforms a bounding box from local space to world space.
///
/// The Y coordinate of the bounding box is the elevation coordinate.
/// </summary>
public Bounds ToWorld(Bounds bounds) => AsPlaneToWorldMatrix().ToWorld(bounds);
}
/// <summary>
/// Represents the orientation of a plane.
///
/// When a character walks around in the world, it may not necessarily walk on the XZ-plane.
/// It may be the case that the character is on a spherical world, or maybe it walks on a wall or upside down on the ceiling.
///
/// A movement plane is used to handle this. It contains functions for converting a 3D point into a 2D point on that plane, and functions for converting back to 3D.
///
/// See: NativeMovementPlane
/// </summary>
#if MODULE_COLLECTIONS_2_0_0_OR_NEWER && UNITY_2022_2_OR_NEWER
[Unity.Collections.GenerateTestsForBurstCompatibility]
#endif
public readonly struct SimpleMovementPlane : IMovementPlane {
public readonly Quaternion rotation;
public readonly Quaternion inverseRotation;
readonly byte plane;
public bool isXY => plane == 1;
public bool isXZ => plane == 2;
/// <summary>A plane that spans the X and Y axes</summary>
public static readonly SimpleMovementPlane XYPlane = new SimpleMovementPlane(Quaternion.Euler(-90, 0, 0));
/// <summary>A plane that spans the X and Z axes</summary>
public static readonly SimpleMovementPlane XZPlane = new SimpleMovementPlane(Quaternion.identity);
public SimpleMovementPlane (Quaternion rotation) {
this.rotation = rotation;
// TODO: Normalize #rotation and compute inverse every time instead (less memory)
inverseRotation = Quaternion.Inverse(rotation);
// Some short circuiting code for the movement plane calculations
if (rotation == XYPlane.rotation) plane = 1;
else if (rotation == Quaternion.identity) plane = 2;
else plane = 0;
}
/// <summary>
/// Transforms from world space to the 'ground' plane of the graph.
/// The transformation is purely a rotation so no scale or offset is used.
///
/// For a graph rotated with the rotation (-90, 0, 0) this will transform
/// a coordinate (x,y,z) to (x,y). For a graph with the rotation (0,0,0)
/// this will tranform a coordinate (x,y,z) to (x,z). More generally for
/// a graph with a quaternion rotation R this will transform a vector V
/// to inverse(R) * V (i.e rotate the vector V using the inverse of rotation R).
/// </summary>
public Vector2 ToPlane (Vector3 point) {
// These special cases cover most graph orientations used in practice.
// Having them here improves performance in those cases by a factor of
// 2.5 without impacting the generic case in any significant way.
if (isXY) return new Vector2(point.x, point.y);
if (!isXZ) point = inverseRotation * point;
return new Vector2(point.x, point.z);
}
/// <summary>
/// Transforms from world space to the 'ground' plane of the graph.
/// The transformation is purely a rotation so no scale or offset is used.
///
/// For a graph rotated with the rotation (-90, 0, 0) this will transform
/// a coordinate (x,y,z) to (x,y). For a graph with the rotation (0,0,0)
/// this will tranform a coordinate (x,y,z) to (x,z). More generally for
/// a graph with a quaternion rotation R this will transform a vector V
/// to inverse(R) * V (i.e rotate the vector V using the inverse of rotation R).
/// </summary>
public float2 ToPlane (float3 point) {
return ((float3)(inverseRotation * (Vector3)point)).xz;
}
/// <summary>
/// Transforms from world space to the 'ground' plane of the graph.
/// The transformation is purely a rotation so no scale or offset is used.
/// </summary>
public Vector2 ToPlane (Vector3 point, out float elevation) {
if (!isXZ) point = inverseRotation * point;
elevation = point.y;
return new Vector2(point.x, point.z);
}
/// <summary>
/// Transforms from world space to the 'ground' plane of the graph.
/// The transformation is purely a rotation so no scale or offset is used.
/// </summary>
public float2 ToPlane (float3 point, out float elevation) {
point = math.mul(inverseRotation, point);
elevation = point.y;
return point.xz;
}
/// <summary>
/// Transforms from the 'ground' plane of the graph to world space.
/// The transformation is purely a rotation so no scale or offset is used.
/// </summary>
public Vector3 ToWorld (Vector2 point, float elevation = 0) {
return rotation * new Vector3(point.x, elevation, point.y);
}
/// <summary>
/// Transforms from the 'ground' plane of the graph to world space.
/// The transformation is purely a rotation so no scale or offset is used.
/// </summary>
public float3 ToWorld (float2 point, float elevation = 0) {
return rotation * new Vector3(point.x, elevation, point.y);
}
public SimpleMovementPlane ToSimpleMovementPlane () {
return this;
}
public static bool operator== (SimpleMovementPlane lhs, SimpleMovementPlane rhs) {
return lhs.rotation == rhs.rotation;
}
public static bool operator!= (SimpleMovementPlane lhs, SimpleMovementPlane rhs) {
return lhs.rotation != rhs.rotation;
}
public override bool Equals (System.Object other) {
if (!(other is SimpleMovementPlane)) return false;
return rotation == ((SimpleMovementPlane)other).rotation;
}
public override int GetHashCode () {
return rotation.GetHashCode();
}
}
/// <summary>Generic 3D coordinate transformation</summary>
public interface ITransform {
Vector3 Transform(Vector3 position);
Vector3 InverseTransform(Vector3 position);
}
/// <summary>Like <see cref="Pathfinding.Util.GraphTransform"/>, but mutable</summary>
public class MutableGraphTransform : GraphTransform {
public MutableGraphTransform (Matrix4x4 matrix) : base(matrix) {}
/// <summary>Replace this transform with the given matrix transformation</summary>
public void SetMatrix (Matrix4x4 matrix) {
Set(matrix);
}
}
/// <summary>
/// Defines a transformation from graph space to world space.
/// This is essentially just a simple wrapper around a matrix, but it has several utilities that are useful.
/// </summary>
public class GraphTransform : IMovementPlane, ITransform {
/// <summary>True if this transform is the identity transform (i.e it does not do anything)</summary>
public bool identity { get { return isIdentity; } }
/// <summary>True if this transform is a pure translation without any scaling or rotation</summary>
public bool onlyTranslational { get { return isOnlyTranslational; } }
bool isXY;
bool isXZ;
bool isOnlyTranslational;
bool isIdentity;
public Matrix4x4 matrix { get; private set; }
public Matrix4x4 inverseMatrix { get; private set; }
Vector3 up;
Vector3 translation;
Int3 i3translation;
public Quaternion rotation { get; private set; }
Quaternion inverseRotation;
public static readonly GraphTransform identityTransform = new GraphTransform(Matrix4x4.identity);
/// <summary>Transforms from the XZ plane to the XY plane</summary>
public static readonly GraphTransform xyPlane = new GraphTransform(Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(-90, 0, 0), Vector3.one));
/// <summary>Transforms from the XZ plane to the XZ plane (i.e. an identity transformation)</summary>
public static readonly GraphTransform xzPlane = new GraphTransform(Matrix4x4.identity);
public GraphTransform (Matrix4x4 matrix) {
Set(matrix);
}
protected void Set (Matrix4x4 matrix) {
this.matrix = matrix;
inverseMatrix = matrix.inverse;
isIdentity = matrix.isIdentity;
isOnlyTranslational = MatrixIsTranslational(matrix);
up = matrix.MultiplyVector(Vector3.up).normalized;
translation = matrix.MultiplyPoint3x4(Vector3.zero);
i3translation = (Int3)translation;
// Extract the rotation from the matrix. This is only correct if the matrix has no skew, but we only
// want to use it for the movement plane so as long as the Up axis is parpendicular to the Forward
// axis everything should be ok. In fact the only case in the project when all three axes are not
// perpendicular is when hexagon or isometric grid graphs are used, but in those cases only the
// X and Z axes are not perpendicular.
rotation = Quaternion.LookRotation(TransformVector(Vector3.forward), TransformVector(Vector3.up));
inverseRotation = Quaternion.Inverse(rotation);
// Some short circuiting code for the movement plane calculations
isXY = rotation == Quaternion.Euler(-90, 0, 0);
isXZ = rotation == Quaternion.Euler(0, 0, 0);
}
public Vector3 WorldUpAtGraphPosition (Vector3 point) {
return up;
}
static bool MatrixIsTranslational (Matrix4x4 matrix) {
return matrix.GetColumn(0) == new Vector4(1, 0, 0, 0) && matrix.GetColumn(1) == new Vector4(0, 1, 0, 0) && matrix.GetColumn(2) == new Vector4(0, 0, 1, 0) && matrix.m33 == 1;
}
public Vector3 Transform (Vector3 point) {
if (onlyTranslational) return point + translation;
return matrix.MultiplyPoint3x4(point);
}
public Vector3 TransformVector (Vector3 dir) {
if (onlyTranslational) return dir;
return matrix.MultiplyVector(dir);
}
public void Transform (Int3[] arr) {
if (onlyTranslational) {
for (int i = arr.Length - 1; i >= 0; i--) arr[i] += i3translation;
} else {
for (int i = arr.Length - 1; i >= 0; i--) arr[i] = (Int3)matrix.MultiplyPoint3x4((Vector3)arr[i]);
}
}
public void Transform (UnsafeSpan<Int3> arr) {
if (onlyTranslational) {
for (int i = arr.Length - 1; i >= 0; i--) arr[i] += i3translation;
} else {
for (int i = arr.Length - 1; i >= 0; i--) arr[i] = (Int3)matrix.MultiplyPoint3x4((Vector3)arr[i]);
}
}
public void Transform (Vector3[] arr) {
if (onlyTranslational) {
for (int i = arr.Length - 1; i >= 0; i--) arr[i] += translation;
} else {
for (int i = arr.Length - 1; i >= 0; i--) arr[i] = matrix.MultiplyPoint3x4(arr[i]);
}
}
public Vector3 InverseTransform (Vector3 point) {
if (onlyTranslational) return point - translation;
return inverseMatrix.MultiplyPoint3x4(point);
}
public Vector3 InverseTransformVector (Vector3 dir) {
if (onlyTranslational) return dir;
return inverseMatrix.MultiplyVector(dir);
}
public Int3 InverseTransform (Int3 point) {
if (onlyTranslational) return point - i3translation;
return (Int3)inverseMatrix.MultiplyPoint3x4((Vector3)point);
}
public void InverseTransform (Int3[] arr) {
for (int i = arr.Length - 1; i >= 0; i--) arr[i] = (Int3)inverseMatrix.MultiplyPoint3x4((Vector3)arr[i]);
}
public void InverseTransform (UnsafeSpan<Int3> arr) {
for (int i = arr.Length - 1; i >= 0; i--) arr[i] = (Int3)inverseMatrix.MultiplyPoint3x4((Vector3)arr[i]);
}
public static GraphTransform operator * (GraphTransform lhs, Matrix4x4 rhs) {
return new GraphTransform(lhs.matrix * rhs);
}
public static GraphTransform operator * (Matrix4x4 lhs, GraphTransform rhs) {
return new GraphTransform(lhs * rhs.matrix);
}
public Bounds Transform (Bounds bounds) {
if (onlyTranslational) return new Bounds(bounds.center + translation, bounds.size);
var corners = ArrayPool<Vector3>.Claim(8);
var extents = bounds.extents;
corners[0] = Transform(bounds.center + new Vector3(extents.x, extents.y, extents.z));
corners[1] = Transform(bounds.center + new Vector3(extents.x, extents.y, -extents.z));
corners[2] = Transform(bounds.center + new Vector3(extents.x, -extents.y, extents.z));
corners[3] = Transform(bounds.center + new Vector3(extents.x, -extents.y, -extents.z));
corners[4] = Transform(bounds.center + new Vector3(-extents.x, extents.y, extents.z));
corners[5] = Transform(bounds.center + new Vector3(-extents.x, extents.y, -extents.z));
corners[6] = Transform(bounds.center + new Vector3(-extents.x, -extents.y, extents.z));
corners[7] = Transform(bounds.center + new Vector3(-extents.x, -extents.y, -extents.z));
var min = corners[0];
var max = corners[0];
for (int i = 1; i < 8; i++) {
min = Vector3.Min(min, corners[i]);
max = Vector3.Max(max, corners[i]);
}
ArrayPool<Vector3>.Release(ref corners);
return new Bounds((min+max)*0.5f, max - min);
}
public Bounds InverseTransform (Bounds bounds) {
if (onlyTranslational) return new Bounds(bounds.center - translation, bounds.size);
var corners = ArrayPool<Vector3>.Claim(8);
var extents = bounds.extents;
corners[0] = InverseTransform(bounds.center + new Vector3(extents.x, extents.y, extents.z));
corners[1] = InverseTransform(bounds.center + new Vector3(extents.x, extents.y, -extents.z));
corners[2] = InverseTransform(bounds.center + new Vector3(extents.x, -extents.y, extents.z));
corners[3] = InverseTransform(bounds.center + new Vector3(extents.x, -extents.y, -extents.z));
corners[4] = InverseTransform(bounds.center + new Vector3(-extents.x, extents.y, extents.z));
corners[5] = InverseTransform(bounds.center + new Vector3(-extents.x, extents.y, -extents.z));
corners[6] = InverseTransform(bounds.center + new Vector3(-extents.x, -extents.y, extents.z));
corners[7] = InverseTransform(bounds.center + new Vector3(-extents.x, -extents.y, -extents.z));
var min = corners[0];
var max = corners[0];
for (int i = 1; i < 8; i++) {
min = Vector3.Min(min, corners[i]);
max = Vector3.Max(max, corners[i]);
}
ArrayPool<Vector3>.Release(ref corners);
return new Bounds((min+max)*0.5f, max - min);
}
#region IMovementPlane implementation
/// <summary>
/// Transforms from world space to the 'ground' plane of the graph.
/// The transformation is purely a rotation so no scale or offset is used.
///
/// For a graph rotated with the rotation (-90, 0, 0) this will transform
/// a coordinate (x,y,z) to (x,y). For a graph with the rotation (0,0,0)
/// this will tranform a coordinate (x,y,z) to (x,z). More generally for
/// a graph with a quaternion rotation R this will transform a vector V
/// to R * V (i.e rotate the vector V using the rotation R).
/// </summary>
Vector2 IMovementPlane.ToPlane (Vector3 point) {
// These special cases cover most graph orientations used in practice.
// Having them here improves performance in those cases by a factor of
// 2.5 without impacting the generic case in any significant way.
if (isXY) return new Vector2(point.x, point.y);
if (!isXZ) point = inverseRotation * point;
return new Vector2(point.x, point.z);
}
/// <summary>
/// Transforms from world space to the 'ground' plane of the graph.
/// The transformation is purely a rotation so no scale or offset is used.
/// </summary>
Vector2 IMovementPlane.ToPlane (Vector3 point, out float elevation) {
if (!isXZ) point = inverseRotation * point;
elevation = point.y;
return new Vector2(point.x, point.z);
}
/// <summary>
/// Transforms from the 'ground' plane of the graph to world space.
/// The transformation is purely a rotation so no scale or offset is used.
/// </summary>
Vector3 IMovementPlane.ToWorld (Vector2 point, float elevation) {
return rotation * new Vector3(point.x, elevation, point.y);
}
public SimpleMovementPlane ToSimpleMovementPlane () {
return new SimpleMovementPlane(rotation);
}
#endregion
/// <summary>Copies the data in this transform to another mutable graph transform</summary>
public void CopyTo (MutableGraphTransform graphTransform) {
graphTransform.isXY = isXY;
graphTransform.isXZ = isXZ;
graphTransform.isOnlyTranslational = isOnlyTranslational;
graphTransform.isIdentity = isIdentity;
graphTransform.matrix = matrix;
graphTransform.inverseMatrix = inverseMatrix;
graphTransform.up = up;
graphTransform.translation = translation;
graphTransform.i3translation = i3translation;
graphTransform.rotation = rotation;
graphTransform.inverseRotation = inverseRotation;
}
}
}
|