[Bf-blender-cvs] [4d3cfce00f1] soc-2021-adaptive-cloth: bli: float2x2: linear_blend()

ishbosamiya noreply at git.blender.org
Mon Jul 26 08:17:39 CEST 2021


Commit: 4d3cfce00f1e39206938e50e6cf6db9a72437830
Author: ishbosamiya
Date:   Mon Jul 19 21:55:32 2021 +0530
Branches: soc-2021-adaptive-cloth
https://developer.blender.org/rB4d3cfce00f1e39206938e50e6cf6db9a72437830

bli: float2x2: linear_blend()

Linearly blend between the 2 matrices.

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

M	source/blender/blenlib/BLI_float2x2.hh

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

diff --git a/source/blender/blenlib/BLI_float2x2.hh b/source/blender/blenlib/BLI_float2x2.hh
index 70090ea44ad..cf8ac9dc23c 100644
--- a/source/blender/blenlib/BLI_float2x2.hh
+++ b/source/blender/blenlib/BLI_float2x2.hh
@@ -16,6 +16,7 @@
 
 #pragma once
 
+#include "BLI_assert.h"
 #include "BLI_float2.hh"
 #include "BLI_math_matrix.h"
 
@@ -109,6 +110,20 @@ struct float2x2 {
     return float2x2(res);
   }
 
+  float2x2 linear_blend(const float2x2 &other, float factor) const
+  {
+    BLI_assert(factor >= 0.0 && factor <= 1.0);
+    const float inv_factor = 1.0 - factor;
+    float2x2 res;
+
+    res.ptr()[0][0] = this->ptr()[0][0] * factor + other.ptr()[0][0] * inv_factor;
+    res.ptr()[0][1] = this->ptr()[0][1] * factor + other.ptr()[0][1] * inv_factor;
+    res.ptr()[1][0] = this->ptr()[1][0] * factor + other.ptr()[1][0] * inv_factor;
+    res.ptr()[1][1] = this->ptr()[1][1] * factor + other.ptr()[1][1] * inv_factor;
+
+    return float2x2(res);
+  }
+
   uint64_t hash() const
   {
     uint64_t h = 435109;



More information about the Bf-blender-cvs mailing list