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
|
/*
* Copyright 2009, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
namespace o3d {
typedef Shape[] ShapeArray;
%[
The Transform defines parent child relationship and a localMatrix..
A Transform can have one or no parents and
an arbitrary number of children.
%]
[nocpp, include="core/cross/transform.h"] class Transform
: ParamObject {
%[
The Visibility for this transform.
%]
[getter, setter] bool visible_;
%[
Sets the parent of the transform by re-parenting the transform under
parent. Setting parent to null removes the transform and the
entire subtree below it from the transform graph.
If the operation would create a cycle it fails.
%]
[setter, userglue_setter] Transform? parent_;
%[
The immediate children of this Transform.
Each access to this field gets the entire list, so it is best to get it
just once. For example:
\code
var children = transform.children;
for (var i = 0; i < children.length; i++) {
var child = children[i];
}
\endcode
Note that modifications to this array [e.g. additions to it] will not affect
the underlying Transform, while modifications to the members of the array
<strong>will</strong> affect them.
%]
[userglue_getter, getter] TransformArray children_;
%[
Returns all the transforms under this transform including this one.
Note that modifications to this array [e.g. additions to it] will not affect
the underlying Transform, while modifications to the members of the array
<strong>will</strong> affect them.
\return An array containing the transforms of the subtree.
%]
TransformArray GetTransformsInTree();
%[
Searches for transforms that match the given name in the hierarchy under and
including this transform. Since there can be more than one transform with a
given name, results are returned in an array.
Note that modifications to this array [e.g. additions to it] will not affect
the underlying Transform, while modifications to the members of the array
<strong>will</strong> affect them.
\param name Transform name to look for.
\return An array containing the transforms of the under and including this
transform matching the given name.
%]
TransformArray GetTransformsByNameInTree(String name);
%[
Evaluates and returns the current world matrix.
\return The updated world matrix.
%]
Vectormath::Aos::Matrix4 GetUpdatedWorldMatrix();
%[
Adds a shape do this transform.
\param shape Shape to add.
%]
void AddShape(Shape shape);
%[
Removes a shape from this transform.
\param shape Shape to remove.
\return true if successful, false if shape was not in this transform.
%]
bool RemoveShape(Shape shape);
%[
Gets the shapes owned by this transform.
Each access to this field gets the entire list so it is best to get it
just once. For example:
\code
var shapes = transform.shapes;
for (var i = 0; i < shapes.length; i++) {
var shape = shapes[i];
}
\endcode
Note that modifications to this array [e.g. additions to it] will not affect
the underlying Transform, while modifications to the members of the array
<strong>will</strong> affect them.
%]
[userglue_getter, getter, userglue_setter, setter]
ShapeArray shapes_;
%[
Walks the tree of transforms starting with this transform and creates
draw elements. If an Element already has a DrawElement that uses material a
new DrawElement will not be created.
\param pack Pack used to manage created elements.
\param material Material to use for each element. If you pass null, it will
use the material on the element to which a draw element is being added.
In other words, a DrawElement will use the material of the
corresponding Element if material is null. This allows you to easily
setup the default (just draw as is) by passing null or setup a shadow
pass by passing in a shadow material.
%]
void CreateDrawElements(Pack pack,
Material? material);
%[
World (model) matrix as it was last computed.
%]
[getter] Vectormath::Aos::Matrix4 world_matrix;
%[
Local transformation matrix.
%]
[getter, setter, nocpp] Vectormath::Aos::Matrix4 local_matrix;
%[
The cull setting for this transform. If true this Transform will be culled
by having its bounding box compared to the view frustum of any draw context
it is used with.
%]
[getter, setter] bool cull_;
%[
The BoundingBox for this Transform. If culling is on this bounding box will
be tested against the view frustum of any draw context used to with this
Transform.
%]
[getter, setter] BoundingBox bounding_box_;
%[
Sets the local matrix of this transform to the identity matrix.
%]
[userglue] void identity();
%[
Pre-composes the local matrix of this Transform with a translation. For
example, if the local matrix is a rotation then new local matrix will
translate by the given vector and then rotated.
\param translation vector of 3 entries by which to translate.
%]
[userglue] void translate(Vectormath::Aos::Vector3 translation);
%[
Pre-composes the local matrix of this Transform with a translation. For
example, if the local matrix is a rotation then the new local matrix will
translate by the given amounts and then rotate.
\param x amount to translate in x.
\param y amount to translate in y.
\param z amount to translate in z.
%]
[userglue] void translate(float x, float y, float z);
%[
Pre-composes the local matrix of this Transform with a rotation about the
x-axis. For example, if the local matrix is a tranlsation, the new local
matrix will rotate around the x-axis and then translate.
\param radians The number of radians to rotate around x-axis.
%]
[userglue] void rotateX(float radians);
%[
Pre-composes the local matrix of this Transform with a rotation about the
y-axis. For example, if the local matrix is a translation, the new local
matrix will rotate around the y-axis and then translate.
\param radians The number of radians to rotate around y-axis.
%]
[userglue] void rotateY(float radians);
%[
Pre-composes the local matrix of this Transform with a rotation about the
z-axis. For example, if the local matrix is a translation, the new local
matrix will rotate around the z-axis and then translate.
\param radians The number of radians to rotate around z-axis.
%]
[userglue] void rotateZ(float radians);
%[
Pre-composes the local matrix of this Transform with a rotation.
Interprets the three entries of the given vector as angles by which to
rotate around the x, y and z axes. Rotates around the x-axis first,
then the y-axis, then the z-axis.
\param radiansXYZ A vector of angles (in radians) by which to rotate
around the x, y and z axes.
%]
[userglue] void rotateZYX(Vectormath::Aos::Vector3 radiansXYZ);
%[
Pre-composes the local matrix of this Transform with a rotation around the
given axis. For example, if the local matrix is a translation, the new
local matrix will rotate around the given axis and then translate.
\param radians The number of radians to rotate.
\param axis a non-zero vector representing the axis around which to rotate.
%]
[userglue] void axisRotate(Vectormath::Aos::Vector3 axis, float radians);
%[
Pre-composes the local matrix of this Transform with a rotation defined by
the given quaternion.
\param unit_quat A non-zero quaternion to be interpreted as a rotation.
%]
[userglue] void quaternionRotate(Vectormath::Aos::Quat unit_quat);
%[
Pre-composes the local matrix of this transform by a scaling transformation.
For example, if the local matrix is a rotation, the new local matrix will
scale and then rotate.
\param scale amount to scale.
%]
[userglue] void scale(Vectormath::Aos::Vector3 scale);
%[
Pre-composes the local matrix of this transform by a scaling transformation.
For example, if the local matrix is a rotation, the new local matrix will
scale and then rotate.
\param x amount to scale in the x dimension.
\param y amount to scale in the y dimension.
\param z amount to scale in the z dimension.
%]
[userglue] void scale(float x, float y, float z);
[verbatim=cpp_glue] %{
void userglue_setter_parent_(
o3d::Transform* _this,
o3d::Transform* parent) {
_this->SetParent(parent);
}
o3d::TransformArray userglue_getter_children_(
o3d::Transform *self) {
return self->GetChildren();
}
o3d::ShapeArray userglue_getter_shapes_(
o3d::Transform *self) {
return self->GetShapes();
}
void userglue_setter_shapes_(
o3d::Transform *self,
const o3d::ShapeArray& shapes) {
self->SetShapes(shapes);
}
void userglue_method_identity(o3d::Transform* self) {
self->set_local_matrix(Vectormath::Aos::Matrix4::identity());
}
void userglue_method_translate(
o3d::Transform* self,
const Vectormath::Aos::Vector3& translation) {
self->set_local_matrix(
self->local_matrix() *
Vectormath::Aos::Matrix4::translation(translation));
}
void userglue_method_translate(o3d::Transform* self,
float x,
float y,
float z) {
self->set_local_matrix(self->local_matrix() *
Vectormath::Aos::Matrix4::translation(
Vectormath::Aos::Vector3(x, y, z)));
}
void userglue_method_rotateX(o3d::Transform* self,
float radians) {
self->set_local_matrix(self->local_matrix() *
Vectormath::Aos::Matrix4::rotationX(radians));
}
void userglue_method_rotateY(o3d::Transform* self,
float radians) {
self->set_local_matrix(self->local_matrix() *
Vectormath::Aos::Matrix4::rotationY(radians));
}
void userglue_method_rotateZ(o3d::Transform* self,
float radians) {
self->set_local_matrix(self->local_matrix() *
Vectormath::Aos::Matrix4::rotationZ(radians));
}
void userglue_method_rotateZYX(o3d::Transform* self,
const Vectormath::Aos::Vector3& radiansXYZ) {
self->set_local_matrix(self->local_matrix() *
Vectormath::Aos::Matrix4::rotationZYX(radiansXYZ));
}
void userglue_method_axisRotate(o3d::Transform* self,
const Vectormath::Aos::Vector3& axis,
float radians) {
self->set_local_matrix(
self->local_matrix() *
Vectormath::Aos::Matrix4::rotation(radians,
Vectormath::Aos::normalize(axis)));
}
void userglue_method_quaternionRotate(o3d::Transform* self,
const Vectormath::Aos::Quat& quat) {
self->set_local_matrix(self->local_matrix() *
Vectormath::Aos::Matrix4::rotation(
Vectormath::Aos::normalize(quat)));
}
void userglue_method_scale(
o3d::Transform* self,
const Vectormath::Aos::Vector3& scale) {
self->set_local_matrix(self->local_matrix() *
Vectormath::Aos::Matrix4::scale(scale));
}
void userglue_method_scale(o3d::Transform* self,
float x,
float y,
float z) {
self->set_local_matrix(
self->local_matrix() *
Vectormath::Aos::Matrix4::scale(Vectormath::Aos::Vector3(x, y, z)));
}
%}
}; // Transform
%[
TransformArray is a typdef for an array of Transforms.
%]
typedef Transform[] TransformArray;
} // namespace o3d
|