[Bf-blender-cvs] [590d2872fc9] collada: Refactor: Collada: Moved matrix functions from BCSample to BCMatrix
Gaia Clary
noreply at git.blender.org
Wed Mar 28 21:31:24 CEST 2018
Commit: 590d2872fc9701b9e4b61b3950873bcf421316a9
Author: Gaia Clary
Date: Sun Mar 25 15:50:54 2018 +0200
Branches: collada
https://developer.blender.org/rB590d2872fc9701b9e4b61b3950873bcf421316a9
Refactor: Collada: Moved matrix functions from BCSample to BCMatrix
The affected methods:
rotaiton()
location()
scale()
quad()
decompose()
These methods really did not belong to the BCSample itself. That
was just a left over from previous changes to the BCSample class.
Moved to BCMatrix where they belong to.
===================================================================
M source/blender/collada/BCAnimationCurveContainer.cpp
M source/blender/collada/BCSampleData.cpp
M source/blender/collada/BCSampleData.h
===================================================================
diff --git a/source/blender/collada/BCAnimationCurveContainer.cpp b/source/blender/collada/BCAnimationCurveContainer.cpp
index 2137c27b72f..876496ea85d 100644
--- a/source/blender/collada/BCAnimationCurveContainer.cpp
+++ b/source/blender/collada/BCAnimationCurveContainer.cpp
@@ -46,8 +46,6 @@ extern "C" {
static std::string EMPTY_STRING;
static BCAnimationCurveMap BCEmptyAnimationCurves;
-static const BCSample UNIT_SAMPLE;
-static const BCMatrix UNIT_MATRIX;
/*
BCAnimationSampler
diff --git a/source/blender/collada/BCSampleData.cpp b/source/blender/collada/BCSampleData.cpp
index 827847b9805..9d7f0d27a58 100644
--- a/source/blender/collada/BCSampleData.cpp
+++ b/source/blender/collada/BCSampleData.cpp
@@ -26,11 +26,6 @@
#include "BCSampleData.h"
#include "collada_utils.h"
-BCSample::BCSample()
-{
- unit();
-}
-
BCSample::BCSample(double(&mat)[4][4])
{
set_matrix(mat);
@@ -196,17 +191,17 @@ const bool BCSample::get_value(BC_animation_transform_type channel, const int ar
/* Object animation */
case BC_ANIMATION_TYPE_LOCATION:
- *val = location()[array_index];
+ *val = matrix.location()[array_index];
break;
case BC_ANIMATION_TYPE_SCALE:
- *val = scale()[array_index];
+ *val = matrix.scale()[array_index];
break;
case BC_ANIMATION_TYPE_ROTATION:
case BC_ANIMATION_TYPE_ROTATION_EULER:
- *val = rotation()[array_index];
+ *val = matrix.rotation()[array_index];
break;
case BC_ANIMATION_TYPE_ROTATION_QUAT:
- *val = quat()[array_index];
+ *val = matrix.quat()[array_index];
break;
@@ -247,7 +242,7 @@ const bool BCSample::get_value(BC_animation_transform_type channel, const int ar
return true;
}
-void BCSample::copy(float(&r)[4][4], float(&a)[4][4])
+void BCMatrix::copy(float(&r)[4][4], float(&a)[4][4])
{
/* destination comes first: */
memcpy(r, a, sizeof(float[4][4]));
@@ -263,9 +258,9 @@ void BCSample::sanitize(float(&matrix)[4][4], int precision)
bc_sanitize_mat(matrix, precision);
}
-void BCSample::unit()
+void BCMatrix::unit()
{
- unit_m4(matrix.matrix);
+ unit_m4(matrix);
}
void BCSample::set_matrix(double(&mat)[4][4])
@@ -300,13 +295,9 @@ void BCMatrix::get_matrix(double(&mat)[4][4], const bool transposed, const int p
}
}
-void BCSample::get_matrix(float(&mat)[4][4]) const
+const float(&BCSample::get_matrix() const)[4][4]
{
- // copy_m4_m4(mat, matrix); // does not work because copy_m4_m4 does not declare 2nd parameter as const
-
- for (int i = 0; i < 4; i++)
- for (int j = 0; j < 4; j++)
- mat[i][j] = matrix.matrix[i][j];
+ return matrix.matrix;
}
bool BCSample::in_range(const BCSample &other, float distance) const
@@ -333,16 +324,14 @@ const bool BCMatrix::in_range(const BCMatrix &other, float distance) const
return true;
}
-void BCSample::decompose() const
+void BCMatrix::decompose() const
{
- float mat[4][4];
- get_matrix(mat);
- mat4_decompose(loc, q, size, mat);
+ mat4_decompose(loc, q, size, matrix);
quat_to_eul(rot, q);
decomposed = true;
}
-const float(&BCSample::location() const)[3]
+float(&BCMatrix::location() const)[3]
{
if (!decomposed)
decompose();
@@ -350,7 +339,7 @@ const float(&BCSample::location() const)[3]
return loc;
}
-const float(&BCSample::rotation() const)[3]
+float(&BCMatrix::rotation() const)[3]
{
if (!decomposed)
decompose();
@@ -359,7 +348,7 @@ return rot;
}
-const float(&BCSample::scale() const)[3]
+float(&BCMatrix::scale() const)[3]
{
if (!decomposed)
decompose();
@@ -367,7 +356,7 @@ const float(&BCSample::scale() const)[3]
return size;
}
-const float(&BCSample::quat() const)[4]
+float(&BCMatrix::quat() const)[4]
{
if (!decomposed)
decompose();
diff --git a/source/blender/collada/BCSampleData.h b/source/blender/collada/BCSampleData.h
index b9d1f6f5130..7e35b0341e8 100644
--- a/source/blender/collada/BCSampleData.h
+++ b/source/blender/collada/BCSampleData.h
@@ -100,18 +100,60 @@ public:
float znear;
};
-typedef float(Matrix)[4][4];
+/*
+* BCMatrix is a neat helper class to handle float matrix[4][4] items
+* in a convenient way.
+* Actually i could not figure out how to make BCMatrix an equivalent
+* of a float matrix[4][4] That is why i added the Matrix typedef
+* below.
+*
+* As the code stands now, i must do this for example:
+*
+* float mat[4][4];
+* BCMatrix obmat;
+* copy_m4_m4(obmat.matrix, mat);
+*
+* I would prefer if i had only BCMatrix and do:
+*
+* float mat[4][4];
+* BCMatrix obmat;
+* copy_m4_m4(obmat, mat);
+*
+* Can this be achieved ?
+*/
+
+typedef float(Matrix)[4][4];
class BCMatrix {
+
+ mutable float size[3];
+ mutable float rot[3];
+ mutable float loc[3];
+ mutable float q[4];
+ mutable bool decomposed = false;
+
+ /* Private methods */
+ void decompose() const;
+ void unit();
+ void copy(float(&r)[4][4], float(&a)[4][4]);
+
public:
- Matrix matrix;
+ mutable float matrix[4][4];
+
+ float(&location() const)[3];
+ float(&rotation() const)[3];
+ float(&scale() const)[3];
+ float(&quat() const)[4];
+ BCMatrix()
+ {
+ unit();
+ }
void get_matrix(double(&mat)[4][4], const bool transposed = false, const int precision = -1) const;
const bool in_range(const BCMatrix &other, float distance) const;
};
typedef std::map<int, BCMaterial *> BCMaterialMap;
-typedef std::map<int, BCMatrix *> BCMatrixMap;
typedef std::map<Bone *, BCMatrix *> BCBoneMatrixMap;
class BCSample{
@@ -119,11 +161,6 @@ private:
/* For Object Transformations */
BCMatrix matrix;
- mutable float size[3];
- mutable float rot[3];
- mutable float loc[3];
- mutable float q[4];
- mutable bool decomposed = false;
/* XXX: The following parts are exclusive, each BCSample has
at most one of those filled with data.
@@ -134,18 +171,8 @@ private:
BCLamp lamp; /* For Lamp channels */
BCCamera camera; /* For Camera channels */
- /* Private methods */
- void decompose() const;
- void unit();
- void copy(float(&r)[4][4], float(&a)[4][4]);
-
- const float(&location() const)[3];
- const float(&rotation() const)[3];
- const float(&scale() const)[3];
- const float(&quat() const)[4];
public:
- BCSample();
BCSample(double(&mat)[4][4]);
BCSample(float(&mat)[4][4]);
~BCSample();
@@ -161,7 +188,7 @@ public:
const bool set_vector(BC_animation_transform_type channel, float val[3]);
const bool set_value(BC_animation_transform_type channel, const int array_index, float val);
- void get_matrix(float(&mat)[4][4]) const;
+ const float(&get_matrix() const)[4][4];
const bool get_value(BC_animation_transform_type channel, const int array_index, float *val) const;
const bool get_value(int ma_index, BC_animation_transform_type channel, const int array_index, float *val) const;
More information about the Bf-blender-cvs
mailing list