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
|
C++RAW
#include "UnityPrefix.h"
#include "Configuration/UnityConfigure.h"
#include "Runtime/Graphics/Transform.h"
#include "Runtime/Scripting/ScriptingUtility.h"
#include "Runtime/Mono/MonoBehaviour.h"
#include "Runtime/Scripting/Scripting.h"
using namespace Unity;
using namespace std;
CSRAW
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Collections;
using UnityEngineInternal;
namespace UnityEngine
{
// Position, rotation and scale of an object.
CSRAW
CLASS Transform : Component, IEnumerable
CSRAW private Transform () { }
// The position of the transform in world space.
CSRAW
AUTO_PROP Vector3 position GetPosition SetPosition
// Position of the transform relative to the parent transform.
CSRAW
AUTO_PROP Vector3 localPosition GetLocalPosition SetLocalPosition
// The rotation as Euler angles in degrees.
CSRAW public Vector3 eulerAngles { get { return rotation.eulerAngles; } set { rotation = Quaternion.Euler(value); } }
// The rotation as Euler angles in degrees relative to the parent transform's rotation.
AUTO_PROP Vector3 localEulerAngles GetLocalEulerAngles SetLocalEulerAngles
// The red axis of the transform in world space.
CSRAW public Vector3 right { get { return rotation * Vector3.right; } set { rotation = Quaternion.FromToRotation(Vector3.right, value); } }
// The green axis of the transform in world space.
CSRAW public Vector3 up { get { return rotation * Vector3.up; } set { rotation = Quaternion.FromToRotation(Vector3.up, value); } }
// The blue axis of the transform in world space.
CSRAW public Vector3 forward { get { return rotation * Vector3.forward; } set { rotation = Quaternion.LookRotation(value); } }
// The rotation of the transform in world space stored as a [[Quaternion]].
AUTO_PROP Quaternion rotation GetRotation SetRotationSafe
// The rotation of the transform relative to the parent transform's rotation.
AUTO_PROP Quaternion localRotation GetLocalRotation SetLocalRotationSafe
// The scale of the transform relative to the parent.
AUTO_PROP Vector3 localScale GetLocalScale SetLocalScale
// The parent of the transform.
CSRAW
AUTO_PTR_PROP Transform parent GetParent SetParent
// Matrix that transforms a point from world space into local space (RO).
AUTO_PROP Matrix4x4 worldToLocalMatrix GetWorldToLocalMatrix
// Matrix that transforms a point from local space into world space (RO).
AUTO_PROP Matrix4x4 localToWorldMatrix GetLocalToWorldMatrix
// Moves the transform in the direction and distance of /translation/.
CSRAW public void Translate (Vector3 translation, Space relativeTo = Space.Self)
{
if (relativeTo == Space.World)
position += translation;
else
position += TransformDirection (translation);
}
// Moves the transform by /x/ along the x axis, /y/ along the y axis, and /z/ along the z axis.
CSRAW public void Translate (float x, float y, float z, Space relativeTo = Space.Self)
{
Translate (new Vector3 (x, y, z), relativeTo);
}
// Moves the transform in the direction and distance of /translation/.
CSRAW public void Translate (Vector3 translation, Transform relativeTo)
{
if (relativeTo)
position += relativeTo.TransformDirection (translation);
else
position += translation;
}
// Moves the transform by /x/ along the x axis, /y/ along the y axis, and /z/ along the z axis.
CSRAW public void Translate (float x, float y, float z, Transform relativeTo)
{
Translate (new Vector3 (x, y, z), relativeTo);
}
// Applies a rotation of /eulerAngles.z/ degrees around the z axis, /eulerAngles.x/ degrees around the x axis, and /eulerAngles.y/ degrees around the y axis (in that order).
CSRAW public void Rotate (Vector3 eulerAngles, Space relativeTo = Space.Self)
{
Quaternion eulerRot = Quaternion.Euler (eulerAngles.x, eulerAngles.y, eulerAngles.z);
if (relativeTo == Space.Self)
localRotation = localRotation * eulerRot;
else
{
rotation = rotation * (Quaternion.Inverse (rotation) * eulerRot * rotation);
}
}
// Applies a rotation of /zAngle/ degrees around the z axis, /xAngle/ degrees around the x axis, and /yAngle/ degrees around the y axis (in that order).
CSRAW public void Rotate (float xAngle, float yAngle, float zAngle, Space relativeTo = Space.Self)
{
Rotate (new Vector3 (xAngle, yAngle, zAngle), relativeTo);
}
CUSTOM internal void RotateAroundInternal (Vector3 axis, float angle) { self->RotateAroundSafe (axis, angle); }
// Rotates the transform around /axis/ by /angle/ degrees.
CSRAW public void Rotate (Vector3 axis, float angle, Space relativeTo = Space.Self)
{
if (relativeTo == Space.Self)
RotateAroundInternal (transform.TransformDirection (axis), angle * Mathf.Deg2Rad);
else
RotateAroundInternal (axis, angle * Mathf.Deg2Rad);
}
// Rotates the transform about /axis/ passing through /point/ in world coordinates by /angle/ degrees.
CSRAW public void RotateAround (Vector3 point, Vector3 axis, float angle)
{
Vector3 worldPos = position;
Quaternion q = Quaternion.AngleAxis (angle , axis);
Vector3 dif = worldPos - point;
dif = q * dif;
worldPos = point + dif;
position = worldPos;
RotateAroundInternal (axis, angle * Mathf.Deg2Rad);
}
// Rotates the transform so the forward vector points at /target/'s current position.
CSRAW public void LookAt (Transform target, Vector3 worldUp = Vector3.up) { if (target) LookAt (target.position, worldUp); }
// Rotates the transform so the forward vector points at /worldPosition/.
CUSTOM void LookAt (Vector3 worldPosition, Vector3 worldUp = Vector3.up)
{
Vector3f forward = worldPosition - self->GetPosition ();
Quaternionf q = Quaternionf::identity ();
if (LookRotationToQuaternion (forward, worldUp, &q))
self->SetRotationSafe (q);
else
{
float mag = Magnitude (forward);
if (mag > Vector3f::epsilon)
{
Matrix3x3f m;
m.SetFromToRotation (Vector3f::zAxis, forward / mag);
MatrixToQuaternion (m, q);
self->SetRotationSafe (q);
}
}
}
// Transforms /direction/ from local space to world space.
AUTO Vector3 TransformDirection (Vector3 direction);
// Transforms direction /x/, /y/, /z/ from local space to world space.
CSRAW public Vector3 TransformDirection (float x, float y, float z) { return TransformDirection (new Vector3 (x, y, z)); }
// Transforms a /direction/ from world space to local space. The opposite of Transform.TransformDirection.
AUTO Vector3 InverseTransformDirection (Vector3 direction);
// Transforms the direction /x/, /y/, /z/ from world space to local space. The opposite of Transform.TransformDirection.
CSRAW public Vector3 InverseTransformDirection (float x, float y, float z) { return InverseTransformDirection (new Vector3 (x, y, z)); }
// Transforms /position/ from local space to world space.
AUTO Vector3 TransformPoint (Vector3 position);
// Transforms the position /x/, /y/, /z/ from local space to world space.
CSRAW public Vector3 TransformPoint (float x, float y, float z) { return TransformPoint (new Vector3 (x, y, z)); }
// Transforms /position/ from world space to local space. The opposite of Transform.TransformPoint.
AUTO Vector3 InverseTransformPoint (Vector3 position);
// Transforms the position /x/, /y/, /z/ from world space to local space. The opposite of Transform.TransformPoint.
CSRAW public Vector3 InverseTransformPoint (float x, float y, float z) { return InverseTransformPoint (new Vector3 (x, y, z)); }
// Returns the topmost transform in the hierarchy.
CUSTOM_PROP Transform root { return Scripting::ScriptingWrapperFor(&self->GetRoot()); }
// The number of children the Transform has.
CUSTOM_PROP int childCount { return self->GetChildrenCount (); }
// Unparents all children.
CUSTOM void DetachChildren ()
{
Transform& transform = *self;
while (transform.begin () != transform.end ())
(**transform.begin ()).SetParent (NULL);
}
// Finds a child by /name/ and returns it.
CUSTOM Transform Find (string name)
{
return Scripting::ScriptingWrapperFor (FindRelativeTransformWithPath (*self, name.AsUTF8().c_str ()));
}
//*undocumented
CONDITIONAL UNITY_EDITOR
CUSTOM internal void SendTransformChangedScale ()
{
self->SendTransformChanged ( Transform::kScaleChanged );
}
// The global scale of the object (RO).
AUTO_PROP Vector3 lossyScale GetWorldScaleLossy
// Is this transform a child of /parent/?
CUSTOM bool IsChildOf (Transform parent)
{
return IsChildOrSameTransform(*self, *parent);
}
// Has the transform changed since the last time the flag was set to 'false'?
CUSTOM_PROP bool hasChanged { return self->GetChangedFlag(); } { self->SetChangedFlag(value); }
//*undocumented*
CSRAW public Transform FindChild (string name) { return Find(name); }
//*undocumented* Documented separately
CSRAW public IEnumerator GetEnumerator ()
{
return new Transform.Enumerator (this);
}
CLASS private Enumerator : IEnumerator
CSRAW
Transform outer;
int currentIndex = -1;
internal Enumerator (Transform outer) { this.outer = outer; }
//*undocumented*
public object Current
{
get { return outer.GetChild (currentIndex); }
}
//*undocumented*
public bool MoveNext ()
{
int childCount = outer.childCount;
return ++currentIndex < childCount;
}
//*undocumented*
public void Reset () { currentIndex = -1; }
END
// *undocumented* DEPRECATED
CSRAW
OBSOLETE warning use Transform.Rotate instead.
CUSTOM void RotateAround (Vector3 axis, float angle) { self->RotateAroundSafe (axis, angle); }
// *undocumented* DEPRECATED
OBSOLETE warning use Transform.Rotate instead.
CUSTOM void RotateAroundLocal (Vector3 axis, float angle) { self->RotateAroundLocalSafe (axis, angle); }
// Get a transform child by index
CUSTOM Transform GetChild (int index)
{
Transform& transform = *self;
if (index >= 0 && index < transform.GetChildrenCount ())
return Scripting::ScriptingWrapperFor (&transform.GetChild (index));
else
{
Scripting::RaiseMonoException ("Transform child out of bounds");
return SCRIPTING_NULL;
}
}
//*undocumented* DEPRECATED
OBSOLETE warning use Transform.childCount instead.
CUSTOM int GetChildCount () { return self->GetChildrenCount (); }
CONDITIONAL UNITY_EDITOR
CUSTOM internal bool IsNonUniformScaleTransform ()
{
Transform& transform = *self;
Matrix4x4f temp;
TransformType scaleType = transform.CalculateTransformMatrix (temp);
return IsNonUniformScaleTransform (scaleType);
}
END
CSRAW }
|