Blender  V2.93
BLI_float4x4.hh
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 
17 #pragma once
18 
19 #include "BLI_float3.hh"
20 #include "BLI_math_matrix.h"
21 
22 namespace blender {
23 
24 struct float4x4 {
25  float values[4][4];
26 
27  float4x4() = default;
28 
29  float4x4(const float *matrix)
30  {
31  memcpy(values, matrix, sizeof(float) * 16);
32  }
33 
34  float4x4(const float matrix[4][4]) : float4x4(static_cast<const float *>(matrix[0]))
35  {
36  }
37 
38  /* Assumes an XYZ euler order. */
39  static float4x4 from_loc_eul_scale(const float3 location,
40  const float3 rotation,
41  const float3 scale)
42  {
43  float4x4 mat;
44  loc_eul_size_to_mat4(mat.values, location, rotation, scale);
45  return mat;
46  }
47 
48  static float4x4 identity()
49  {
50  float4x4 mat;
51  unit_m4(mat.values);
52  return mat;
53  }
54 
55  operator float *()
56  {
57  return &values[0][0];
58  }
59 
60  operator const float *() const
61  {
62  return &values[0][0];
63  }
64 
65  using c_style_float4x4 = float[4][4];
67  {
68  return values;
69  }
70 
71  const c_style_float4x4 &ptr() const
72  {
73  return values;
74  }
75 
76  friend float4x4 operator*(const float4x4 &a, const float4x4 &b)
77  {
79  mul_m4_m4m4(result.values, a.values, b.values);
80  return result;
81  }
82 
87  friend float3 operator*(const float4x4 &m, const float3 &v)
88  {
89  float3 result;
91  return result;
92  }
93 
94  friend float3 operator*(const float4x4 &m, const float (*v)[3])
95  {
96  return m * float3(v);
97  }
98 
100  {
101  return float3(values[3]);
102  }
103 
104  /* Assumes XYZ rotation order. */
105  float3 to_euler() const
106  {
107  float3 euler;
108  mat4_to_eul(euler, values);
109  return euler;
110  }
111 
112  float3 scale() const
113  {
114  float3 scale;
116  return scale;
117  }
118 
120  {
122  invert_m4_m4(result.values, values);
123  return result;
124  }
125 
130  {
131  BLI_assert(values[0][3] == 0.0f && values[1][3] == 0.0f && values[2][3] == 0.0f &&
132  values[3][3] == 1.0f);
133  return this->inverted();
134  }
135 
137  {
139  transpose_m4_m4(result.values, values);
140  return result;
141  }
142 
144  {
145  return this->inverted_affine().transposed();
146  }
147 
148  struct float3x3_ref {
149  const float4x4 &data;
150 
151  friend float3 operator*(const float3x3_ref &m, const float3 &v)
152  {
153  float3 result;
155  return result;
156  }
157  };
158 
160  {
161  return {*this};
162  }
163 
164  static float4x4 interpolate(const float4x4 &a, const float4x4 &b, float t)
165  {
166  float result[4][4];
167  interp_m4_m4m4(result, a.values, b.values, t);
168  return result;
169  }
170 
171  uint64_t hash() const
172  {
173  uint64_t h = 435109;
174  for (int i = 0; i < 16; i++) {
175  float value = (static_cast<const float *>(values[0]))[i];
176  h = h * 33 + *reinterpret_cast<const uint32_t *>(&value);
177  }
178  return h;
179  }
180 };
181 
182 } // namespace blender
typedef float(TangentPoint)[2]
#define BLI_assert(a)
Definition: BLI_assert.h:58
void mul_m4_m4m4(float R[4][4], const float A[4][4], const float B[4][4])
Definition: math_matrix.c:262
void transpose_m4_m4(float R[4][4], const float M[4][4])
Definition: math_matrix.c:1384
void unit_m4(float m[4][4])
Definition: rct.c:1140
bool invert_m4_m4(float R[4][4], const float A[4][4])
Definition: math_matrix.c:1278
void interp_m4_m4m4(float R[4][4], const float A[4][4], const float B[4][4], const float t)
Definition: math_matrix.c:2562
void mul_v3_m4v3(float r[3], const float M[4][4], const float v[3])
Definition: math_matrix.c:742
void loc_eul_size_to_mat4(float R[4][4], const float loc[3], const float eul[3], const float size[3])
Definition: math_matrix.c:2653
void mat4_to_size(float size[3], const float M[4][4])
Definition: math_matrix.c:2145
void mul_v3_mat3_m4v3(float r[3], const float M[4][4], const float v[3])
Definition: math_matrix.c:804
void mat4_to_eul(float eul[3], const float mat[4][4])
_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 GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble y2 _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat y2 _GL_VOID_RET _GL_VOID GLint GLint GLint y2 _GL_VOID_RET _GL_VOID GLshort GLshort GLshort y2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLuint *buffer _GL_VOID_RET _GL_VOID GLdouble t _GL_VOID_RET _GL_VOID GLfloat t _GL_VOID_RET _GL_VOID GLint t _GL_VOID_RET _GL_VOID GLshort t _GL_VOID_RET _GL_VOID GLdouble t
ATTR_WARN_UNUSED_RESULT const BMVert * v
static unsigned a[3]
Definition: RandGen.cpp:92
unsigned int uint32_t
Definition: stdint.h:83
unsigned __int64 uint64_t
Definition: stdint.h:93
friend float3 operator*(const float3x3_ref &m, const float3 &v)
float3 scale() const
c_style_float4x4 & ptr()
Definition: BLI_float4x4.hh:66
float4x4 inverted_transposed_affine() const
friend float3 operator*(const float4x4 &m, const float3 &v)
Definition: BLI_float4x4.hh:87
float4x4 inverted_affine() const
static float4x4 from_loc_eul_scale(const float3 location, const float3 rotation, const float3 scale)
Definition: BLI_float4x4.hh:39
float[4][4] c_style_float4x4
Definition: BLI_float4x4.hh:65
uint64_t hash() const
float values[4][4]
Definition: BLI_float4x4.hh:25
float4x4(const float matrix[4][4])
Definition: BLI_float4x4.hh:34
float4x4()=default
float3 translation() const
Definition: BLI_float4x4.hh:99
static float4x4 identity()
Definition: BLI_float4x4.hh:48
friend float4x4 operator*(const float4x4 &a, const float4x4 &b)
Definition: BLI_float4x4.hh:76
friend float3 operator*(const float4x4 &m, const float(*v)[3])
Definition: BLI_float4x4.hh:94
float4x4(const float *matrix)
Definition: BLI_float4x4.hh:29
float4x4 inverted() const
static float4x4 interpolate(const float4x4 &a, const float4x4 &b, float t)
float3 to_euler() const
float3x3_ref ref_3x3() const
const c_style_float4x4 & ptr() const
Definition: BLI_float4x4.hh:71
float4x4 transposed() const