[Bf-blender-cvs] [9933b5bc27e] functions: move float4x4 into separate file

Jacques Lucke noreply at git.blender.org
Thu Feb 13 18:58:46 CET 2020


Commit: 9933b5bc27e6620de86a8295b3e22eae5b1a394c
Author: Jacques Lucke
Date:   Thu Feb 13 17:53:03 2020 +0100
Branches: functions
https://developer.blender.org/rB9933b5bc27e6620de86a8295b3e22eae5b1a394c

move float4x4 into separate file

===================================================================

A	source/blender/blenlib/BLI_float4x4.h
M	source/blender/blenlib/BLI_math_cxx.h
M	source/blender/blenlib/CMakeLists.txt

===================================================================

diff --git a/source/blender/blenlib/BLI_float4x4.h b/source/blender/blenlib/BLI_float4x4.h
new file mode 100644
index 00000000000..51d3e54d027
--- /dev/null
+++ b/source/blender/blenlib/BLI_float4x4.h
@@ -0,0 +1,85 @@
+#ifndef __BLI_FLOAT4X4_H__
+#define __BLI_FLOAT4X4_H__
+
+#include "BLI_float3.h"
+
+namespace BLI {
+
+struct float4x4 {
+  float values[4][4];
+
+  float4x4() = default;
+
+  float4x4(float *matrix)
+  {
+    memcpy(values, matrix, sizeof(float) * 16);
+  }
+
+  float4x4(float matrix[4][4]) : float4x4((float *)matrix)
+  {
+  }
+
+  operator float *()
+  {
+    return (float *)this;
+  }
+
+  float4x4 inverted() const
+  {
+    float result[4][4];
+    invert_m4_m4(result, values);
+    return result;
+  }
+
+  float4x4 inverted__LocRotScale() const
+  {
+    return this->inverted();
+  }
+
+  float3 transform_position(float3 position) const
+  {
+    mul_m4_v3(values, position);
+    return position;
+  }
+
+  float3 transform_direction(float3 direction) const
+  {
+    mul_mat3_m4_v3(values, direction);
+    return direction;
+  }
+
+  static void transform_positions(ArrayRef<float4x4> matrices,
+                                  ArrayRef<float3> positions,
+                                  MutableArrayRef<float3> r_results)
+  {
+    uint amount = matrices.size();
+    BLI_assert(amount == positions.size());
+    BLI_assert(amount == r_results.size());
+    for (uint i = 0; i < amount; i++) {
+      r_results[i] = matrices[i].transform_position(positions[i]);
+    }
+  }
+
+  static void transform_directions(ArrayRef<float4x4> matrices,
+                                   ArrayRef<float3> directions,
+                                   MutableArrayRef<float3> r_results)
+  {
+    uint amount = matrices.size();
+    BLI_assert(amount == directions.size());
+    BLI_assert(amount == r_results.size());
+    for (uint i = 0; i < amount; i++) {
+      r_results[i] = matrices[i].transform_direction(directions[i]);
+    }
+  }
+
+  static float4x4 interpolate(float4x4 a, float4x4 b, float t)
+  {
+    float result[4][4];
+    interp_m4_m4m4(result, a.values, b.values, t);
+    return result;
+  }
+};
+
+}  // namespace BLI
+
+#endif /* __BLI_FLOAT4X4_H__ */
diff --git a/source/blender/blenlib/BLI_math_cxx.h b/source/blender/blenlib/BLI_math_cxx.h
index 59becd4c9ba..ced75708c18 100644
--- a/source/blender/blenlib/BLI_math_cxx.h
+++ b/source/blender/blenlib/BLI_math_cxx.h
@@ -30,87 +30,13 @@
 #include "BLI_math_matrix.h"
 #include "BLI_float3.h"
 #include "BLI_float2.h"
+#include "BLI_float4x4.h"
 
 namespace BLI {
 
 struct rgba_f;
 struct rgba_b;
 
-struct float4x4 {
-  float values[4][4];
-
-  float4x4() = default;
-
-  float4x4(float *matrix)
-  {
-    memcpy(values, matrix, sizeof(float) * 16);
-  }
-
-  float4x4(float matrix[4][4]) : float4x4((float *)matrix)
-  {
-  }
-
-  operator float *()
-  {
-    return (float *)this;
-  }
-
-  float4x4 inverted() const
-  {
-    float result[4][4];
-    invert_m4_m4(result, values);
-    return result;
-  }
-
-  float4x4 inverted__LocRotScale() const
-  {
-    return this->inverted();
-  }
-
-  float3 transform_position(float3 position) const
-  {
-    mul_m4_v3(values, position);
-    return position;
-  }
-
-  float3 transform_direction(float3 direction) const
-  {
-    mul_mat3_m4_v3(values, direction);
-    return direction;
-  }
-
-  static void transform_positions(ArrayRef<float4x4> matrices,
-                                  ArrayRef<float3> positions,
-                                  MutableArrayRef<float3> r_results)
-  {
-    uint amount = matrices.size();
-    BLI_assert(amount == positions.size());
-    BLI_assert(amount == r_results.size());
-    for (uint i = 0; i < amount; i++) {
-      r_results[i] = matrices[i].transform_position(positions[i]);
-    }
-  }
-
-  static void transform_directions(ArrayRef<float4x4> matrices,
-                                   ArrayRef<float3> directions,
-                                   MutableArrayRef<float3> r_results)
-  {
-    uint amount = matrices.size();
-    BLI_assert(amount == directions.size());
-    BLI_assert(amount == r_results.size());
-    for (uint i = 0; i < amount; i++) {
-      r_results[i] = matrices[i].transform_direction(directions[i]);
-    }
-  }
-
-  static float4x4 interpolate(float4x4 a, float4x4 b, float t)
-  {
-    float result[4][4];
-    interp_m4_m4m4(result, a.values, b.values, t);
-    return result;
-  }
-};
-
 struct rgba_f {
   float r, g, b, a;
 
diff --git a/source/blender/blenlib/CMakeLists.txt b/source/blender/blenlib/CMakeLists.txt
index 2660528745f..b1df32b4880 100644
--- a/source/blender/blenlib/CMakeLists.txt
+++ b/source/blender/blenlib/CMakeLists.txt
@@ -273,6 +273,8 @@ set(SRC
   BLI_rand_cxx.h
   BLI_buffer_cache.h
   BLI_float3.h
+  BLI_float2.h
+  BLI_float4x4.h
 )
 
 set(LIB



More information about the Bf-blender-cvs mailing list