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