52 void rotate(
const Vector3& p_axis,real_t p_phi);
53 void rotate_basis(
const Vector3& p_axis,real_t p_phi);
58 void scale(
const Vector3& p_scale);
60 void scale_basis(
const Vector3& p_scale);
61 void translate( real_t p_tx, real_t p_ty, real_t p_tz );
62 void translate(
const Vector3& p_translation );
65 const Matrix3& get_basis()
const {
return basis; }
66 void set_basis(
const Matrix3& p_basis) { basis=p_basis; }
68 const Vector3& get_origin()
const {
return origin; }
69 void set_origin(
const Vector3& p_origin) { origin=p_origin; }
71 void orthonormalize();
74 bool operator==(
const Transform& p_transform)
const;
75 bool operator!=(
const Transform& p_transform)
const;
80 _FORCE_INLINE_
Plane xform(
const Plane& p_plane)
const;
81 _FORCE_INLINE_
Plane xform_inv(
const Plane& p_plane)
const;
83 _FORCE_INLINE_
AABB xform(
const AABB& p_aabb)
const;
84 _FORCE_INLINE_
AABB xform_inv(
const AABB& p_aabb)
const;
86 void operator*=(
const Transform& p_transform);
94 return Transform(basis.transpose_xform(t.basis),
98 void set(real_t xx, real_t xy, real_t xz, real_t yx, real_t yy, real_t yz, real_t zx, real_t zy, real_t zz,real_t tx, real_t ty, real_t tz) {
100 basis.elements[0][0]=xx;
101 basis.elements[0][1]=xy;
102 basis.elements[0][2]=xz;
103 basis.elements[1][0]=yx;
104 basis.elements[1][1]=yy;
105 basis.elements[1][2]=yz;
106 basis.elements[2][0]=zx;
107 basis.elements[2][1]=zy;
108 basis.elements[2][2]=zz;
122 _FORCE_INLINE_
Vector3 Transform::xform(
const Vector3& p_vector)
const {
125 basis[0].dot(p_vector)+origin.x,
126 basis[1].dot(p_vector)+origin.y,
127 basis[2].dot(p_vector)+origin.z
130 _FORCE_INLINE_
Vector3 Transform::xform_inv(
const Vector3& p_vector)
const {
135 (basis.elements[0][0]*v.x ) + ( basis.elements[1][0]*v.y ) + ( basis.elements[2][0]*v.z ),
136 (basis.elements[0][1]*v.x ) + ( basis.elements[1][1]*v.y ) + ( basis.elements[2][1]*v.z ),
137 (basis.elements[0][2]*v.x ) + ( basis.elements[1][2]*v.y ) + ( basis.elements[2][2]*v.z )
141 _FORCE_INLINE_
Plane Transform::xform(
const Plane& p_plane)
const {
144 Vector3 point=p_plane.normal*p_plane.d;
145 Vector3 point_dir=point+p_plane.normal;
147 point_dir=xform(point_dir);
149 Vector3 normal=point_dir-point;
151 real_t d=normal.dot(point);
153 return Plane(normal,d);
156 _FORCE_INLINE_
Plane Transform::xform_inv(
const Plane& p_plane)
const {
158 Vector3 point=p_plane.normal*p_plane.d;
159 Vector3 point_dir=point+p_plane.normal;
161 xform_inv(point_dir);
163 Vector3 normal=point_dir-point;
165 real_t d=normal.dot(point);
167 return Plane(normal,d);
171 _FORCE_INLINE_
AABB Transform::xform(
const AABB& p_aabb)
const {
174 Vector3 x=basis.get_axis(0)*p_aabb.size.x;
175 Vector3 y=basis.get_axis(1)*p_aabb.size.y;
176 Vector3 z=basis.get_axis(2)*p_aabb.size.z;
177 Vector3 pos = xform( p_aabb.pos );
181 new_aabb.expand_to( pos+x );
182 new_aabb.expand_to( pos+y );
183 new_aabb.expand_to( pos+z );
184 new_aabb.expand_to( pos+x+y );
185 new_aabb.expand_to( pos+x+z );
186 new_aabb.expand_to( pos+y+z );
187 new_aabb.expand_to( pos+x+y+z );
193 Vector3(p_aabb.pos.x+p_aabb.size.x, p_aabb.pos.y+p_aabb.size.y, p_aabb.pos.z+p_aabb.size.z),
194 Vector3(p_aabb.pos.x+p_aabb.size.x, p_aabb.pos.y+p_aabb.size.y, p_aabb.pos.z),
195 Vector3(p_aabb.pos.x+p_aabb.size.x, p_aabb.pos.y, p_aabb.pos.z+p_aabb.size.z),
196 Vector3(p_aabb.pos.x+p_aabb.size.x, p_aabb.pos.y, p_aabb.pos.z),
197 Vector3(p_aabb.pos.x, p_aabb.pos.y+p_aabb.size.y, p_aabb.pos.z+p_aabb.size.z),
198 Vector3(p_aabb.pos.x, p_aabb.pos.y+p_aabb.size.y, p_aabb.pos.z),
199 Vector3(p_aabb.pos.x, p_aabb.pos.y, p_aabb.pos.z+p_aabb.size.z),
200 Vector3(p_aabb.pos.x, p_aabb.pos.y, p_aabb.pos.z)
206 ret.pos=xform(vertices[0]);
208 for (
int i=1;i<8;i++) {
210 ret.expand_to( xform(vertices[i]) );
217 _FORCE_INLINE_
AABB Transform::xform_inv(
const AABB& p_aabb)
const {
221 Vector3(p_aabb.pos.x+p_aabb.size.x, p_aabb.pos.y+p_aabb.size.y, p_aabb.pos.z+p_aabb.size.z),
222 Vector3(p_aabb.pos.x+p_aabb.size.x, p_aabb.pos.y+p_aabb.size.y, p_aabb.pos.z),
223 Vector3(p_aabb.pos.x+p_aabb.size.x, p_aabb.pos.y, p_aabb.pos.z+p_aabb.size.z),
224 Vector3(p_aabb.pos.x+p_aabb.size.x, p_aabb.pos.y, p_aabb.pos.z),
225 Vector3(p_aabb.pos.x, p_aabb.pos.y+p_aabb.size.y, p_aabb.pos.z+p_aabb.size.z),
226 Vector3(p_aabb.pos.x, p_aabb.pos.y+p_aabb.size.y, p_aabb.pos.z),
227 Vector3(p_aabb.pos.x, p_aabb.pos.y, p_aabb.pos.z+p_aabb.size.z),
228 Vector3(p_aabb.pos.x, p_aabb.pos.y, p_aabb.pos.z)
234 ret.pos=xform_inv(vertices[0]);
236 for (
int i=1;i<8;i++) {
238 ret.expand_to( xform_inv(vertices[i]) );
245 #ifdef OPTIMIZED_TRANSFORM_IMPL_OVERRIDE 253 _FORCE_INLINE_
void invert() {transform.invert(); }
254 _FORCE_INLINE_
void affine_invert() {transform.affine_invert(); }
255 _FORCE_INLINE_
Vector3 xform(
const Vector3& p_vec)
const {
return transform.xform(p_vec); };
256 _FORCE_INLINE_
Vector3 xform_inv(
const Vector3& p_vec)
const {
return transform.xform_inv(p_vec); };
258 _FORCE_INLINE_
Transform get_transform()
const {
return transform; }
259 _FORCE_INLINE_
void set_transform(
const Transform& p_transform) { transform=p_transform; }
262 transform=p_transform;