Blender  V2.93
NodeTransform.cpp
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
23 #include "NodeTransform.h"
24 
25 #include "BLI_math.h"
26 
27 namespace Freestyle {
28 
30 {
31  _Matrix(0, 3) += x;
32  _Matrix(1, 3) += y;
33  _Matrix(2, 3) += z;
34 }
35 
37 {
38  // Normalize the x,y,z vector;
39  real norm = (real)sqrt(x * x + y * y + z * z);
40  if (0 == norm) {
41  return;
42  }
43 
44  x /= norm;
45  y /= norm;
46  z /= norm;
47 
48  /* find the corresponding matrix with the Rodrigues formula:
49  * R = I + sin(iAngle)*Ntilda + (1-cos(iAngle))*Ntilda*Ntilda
50  */
51  Matrix33r Ntilda;
52  Ntilda(0, 0) = Ntilda(1, 1) = Ntilda(2, 2) = 0.0f;
53  Ntilda(0, 1) = -z;
54  Ntilda(0, 2) = y;
55  Ntilda(1, 0) = z;
56  Ntilda(1, 2) = -x;
57  Ntilda(2, 0) = -y;
58  Ntilda(2, 1) = x;
59 
60  const Matrix33r Ntilda2(Ntilda * Ntilda);
61 
62  const real sinAngle = (real)sin((iAngle / 180.0f) * M_PI);
63  const real cosAngle = (real)cos((iAngle / 180.0f) * M_PI);
64 
65  Matrix33r NS(Ntilda * sinAngle);
66  Matrix33r NC(Ntilda2 * (1.0f - cosAngle));
67  Matrix33r R;
69  R += NS + NC;
70 
71  // R4 is the corresponding 4x4 matrix
72  Matrix44r R4;
73  R4 = Matrix44r::identity();
74 
75  for (int i = 0; i < 3; i++) {
76  for (int j = 0; j < 3; j++) {
77  R4(i, j) = R(i, j);
78  }
79  }
80 
81  // Finally, we multiply our current matrix by R4:
82  Matrix44r mat_tmp(_Matrix);
83  _Matrix = mat_tmp * R4;
84 }
85 
87 {
88  _Matrix(0, 0) *= x;
89  _Matrix(1, 1) *= y;
90  _Matrix(2, 2) *= z;
91 
92  _Scaled = true;
93 }
94 
96 {
97  Matrix44r mat_tmp(_Matrix);
98  _Matrix = mat_tmp * iMatrix;
99 }
100 
102 {
103  _Matrix = iMatrix;
104  if (isScaled(iMatrix)) {
105  _Scaled = true;
106  }
107 }
108 
110 {
111  v.visitNodeTransform(*this);
112 
113  v.visitNodeTransformBefore(*this);
114  for (vector<Node *>::iterator node = _Children.begin(), end = _Children.end(); node != end;
115  ++node) {
116  (*node)->accept(v);
117  }
118  v.visitNodeTransformAfter(*this);
119 }
120 
122 {
123  Vec3r oldMin(iBBox.getMin());
124  Vec3r oldMax(iBBox.getMax());
125 
126  // compute the 8 corners of the bbox
127  HVec3r box[8];
128  box[0] = HVec3r(iBBox.getMin());
129  box[1] = HVec3r(oldMax[0], oldMin[1], oldMin[2]);
130  box[2] = HVec3r(oldMax[0], oldMax[1], oldMin[2]);
131  box[3] = HVec3r(oldMin[0], oldMax[1], oldMin[2]);
132  box[4] = HVec3r(oldMin[0], oldMin[1], oldMax[2]);
133  box[5] = HVec3r(oldMax[0], oldMin[1], oldMax[2]);
134  box[6] = HVec3r(oldMax[0], oldMax[1], oldMax[2]);
135  box[7] = HVec3r(oldMin[0], oldMax[1], oldMax[2]);
136 
137  // Computes the transform iBBox
138  HVec3r tbox[8];
139  unsigned int i;
140  for (i = 0; i < 8; i++) {
141  tbox[i] = _Matrix * box[i];
142  }
143 
144  Vec3r newMin(tbox[0]);
145  Vec3r newMax(tbox[0]);
146  for (i = 0; i < 8; i++) {
147  for (unsigned int j = 0; j < 3; j++) {
148  if (newMin[j] > tbox[i][j]) {
149  newMin[j] = tbox[i][j];
150  }
151  if (newMax[j] < tbox[i][j]) {
152  newMax[j] = tbox[i][j];
153  }
154  }
155  }
156 
157  BBox<Vec3r> transformBox(newMin, newMax);
158 
159  Node::AddBBox(transformBox);
160 }
161 
163 {
164  for (unsigned int j = 0; j < 3; j++) {
165  real norm = 0;
166  for (unsigned int i = 0; i < 3; i++) {
167  norm += M(i, j) * M(i, j);
168  }
169  if ((norm > 1.01) || (norm < 0.99)) {
170  return true;
171  }
172  }
173 
174  return false;
175 }
176 
177 } /* namespace Freestyle */
sqrt(x)+1/max(0
#define M_PI
Definition: BLI_math_base.h:38
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble z
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
Class to represent a transform node. A Transform node contains one or several children,...
ATTR_WARN_UNUSED_RESULT const BMVert * v
SIMD_FORCE_INLINE btScalar norm() const
Return the norm (length) of the vector.
Definition: btVector3.h:263
const Point & getMax() const
Definition: BBox.h:86
const Point & getMin() const
Definition: BBox.h:81
vector< Node * > _Children
Definition: NodeGroup.h:78
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:79
static SquareMatrix< T, N > identity()
Definition: VecMat.h:816
OperationNode * node
#define M
#define R
VecMat::HVec3< real > HVec3r
Definition: Geom.h:48
inherits from class Rep
Definition: AppCanvas.cpp:32
static unsigned x[3]
Definition: RandGen.cpp:87
double real
Definition: Precision.h:26
INLINE Rall1d< T, V, S > cos(const Rall1d< T, V, S > &arg)
Definition: rall1d.h:319
INLINE Rall1d< T, V, S > sin(const Rall1d< T, V, S > &arg)
Definition: rall1d.h:311