Blender V4.3
NodeTransform.cpp
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2008-2022 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
11#include "NodeTransform.h"
12
13#include "BLI_math_base.h"
14#include "BLI_sys_types.h"
15
16namespace Freestyle {
17
19{
20 _Matrix(0, 3) += x;
21 _Matrix(1, 3) += y;
22 _Matrix(2, 3) += z;
23}
24
26{
27 // Normalize the x,y,z vector;
28 real norm = (real)sqrt(x * x + y * y + z * z);
29 if (0 == norm) {
30 return;
31 }
32
33 x /= norm;
34 y /= norm;
35 z /= norm;
36
37 /* find the corresponding matrix with the Rodrigues formula:
38 * R = I + sin(iAngle)*Ntilda + (1-cos(iAngle))*Ntilda*Ntilda
39 */
40 Matrix33r Ntilda;
41 Ntilda(0, 0) = Ntilda(1, 1) = Ntilda(2, 2) = 0.0f;
42 Ntilda(0, 1) = -z;
43 Ntilda(0, 2) = y;
44 Ntilda(1, 0) = z;
45 Ntilda(1, 2) = -x;
46 Ntilda(2, 0) = -y;
47 Ntilda(2, 1) = x;
48
49 const Matrix33r Ntilda2(Ntilda * Ntilda);
50
51 const real sinAngle = (real)sin((iAngle / 180.0f) * M_PI);
52 const real cosAngle = (real)cos((iAngle / 180.0f) * M_PI);
53
54 Matrix33r NS(Ntilda * sinAngle);
55 Matrix33r NC(Ntilda2 * (1.0f - cosAngle));
58 R += NS + NC;
59
60 // R4 is the corresponding 4x4 matrix
61 Matrix44r R4;
63
64 for (int i = 0; i < 3; i++) {
65 for (int j = 0; j < 3; j++) {
66 R4(i, j) = R(i, j);
67 }
68 }
69
70 // Finally, we multiply our current matrix by R4:
71 Matrix44r mat_tmp(_Matrix);
72 _Matrix = mat_tmp * R4;
73}
74
76{
77 _Matrix(0, 0) *= x;
78 _Matrix(1, 1) *= y;
79 _Matrix(2, 2) *= z;
80
81 _Scaled = true;
82}
83
85{
86 Matrix44r mat_tmp(_Matrix);
87 _Matrix = mat_tmp * iMatrix;
88}
89
91{
92 _Matrix = iMatrix;
93 if (isScaled(iMatrix)) {
94 _Scaled = true;
95 }
96}
97
99{
100 v.visitNodeTransform(*this);
101
102 v.visitNodeTransformBefore(*this);
103 for (vector<Node *>::iterator node = _Children.begin(), end = _Children.end(); node != end;
104 ++node)
105 {
106 (*node)->accept(v);
107 }
108 v.visitNodeTransformAfter(*this);
109}
110
112{
113 Vec3r oldMin(iBBox.getMin());
114 Vec3r oldMax(iBBox.getMax());
115
116 // compute the 8 corners of the bbox
117 HVec3r box[8];
118 box[0] = HVec3r(iBBox.getMin());
119 box[1] = HVec3r(oldMax[0], oldMin[1], oldMin[2]);
120 box[2] = HVec3r(oldMax[0], oldMax[1], oldMin[2]);
121 box[3] = HVec3r(oldMin[0], oldMax[1], oldMin[2]);
122 box[4] = HVec3r(oldMin[0], oldMin[1], oldMax[2]);
123 box[5] = HVec3r(oldMax[0], oldMin[1], oldMax[2]);
124 box[6] = HVec3r(oldMax[0], oldMax[1], oldMax[2]);
125 box[7] = HVec3r(oldMin[0], oldMax[1], oldMax[2]);
126
127 // Computes the transform iBBox
128 HVec3r tbox[8];
129 uint i;
130 for (i = 0; i < 8; i++) {
131 tbox[i] = _Matrix * box[i];
132 }
133
134 Vec3r newMin(tbox[0]);
135 Vec3r newMax(tbox[0]);
136 for (i = 0; i < 8; i++) {
137 for (uint j = 0; j < 3; j++) {
138 if (newMin[j] > tbox[i][j]) {
139 newMin[j] = tbox[i][j];
140 }
141 if (newMax[j] < tbox[i][j]) {
142 newMax[j] = tbox[i][j];
143 }
144 }
145 }
146
147 BBox<Vec3r> transformBox(newMin, newMax);
148
149 Node::AddBBox(transformBox);
150}
151
153{
154 for (uint j = 0; j < 3; j++) {
155 real norm = 0;
156 for (uint i = 0; i < 3; i++) {
157 norm += M(i, j) * M(i, j);
158 }
159 if ((norm > 1.01) || (norm < 0.99)) {
160 return true;
161 }
162 }
163
164 return false;
165}
166
167} /* namespace Freestyle */
sqrt(x)+1/max(0
#define M_PI
unsigned int uint
Class to represent a transform node. A Transform node contains one or several children,...
ATTR_WARN_UNUSED_RESULT const BMVert * v
SIMD_FORCE_INLINE const btScalar & z() const
Return the z value.
Definition btQuadWord.h:117
SIMD_FORCE_INLINE btScalar norm() const
Return the norm (length) of the vector.
Definition btVector3.h:263
const Point & getMin() const
Definition BBox.h:69
const Point & getMax() const
Definition BBox.h:74
vector< Node * > _Children
Definition NodeGroup.h:62
virtual void accept(SceneVisitor &v)
void setMatrix(const Matrix44r &iMatrix)
void MultiplyMatrix(const Matrix44r &iMatrix)
void Translate(real x, real y, real z)
virtual void AddBBox(const BBox< Vec3r > &iBBox)
void Scale(real x, real y, real z)
bool isScaled(const Matrix44r &M)
void Rotate(real iAngle, real x, real y, real z)
virtual void AddBBox(const BBox< Vec3r > &iBox)
Definition Node.h:63
static SquareMatrix< T, N > identity()
Definition VecMat.h:771
OperationNode * node
ccl_device_inline float3 cos(float3 v)
#define M
#define R
VecMat::HVec3< real > HVec3r
Definition Geom.h:36
inherits from class Rep
Definition AppCanvas.cpp:20
static uint x[3]
Definition RandGen.cpp:77
double real
Definition Precision.h:14