[Bf-blender-cvs] [409fb4d] master: Code cleanup: remove redundant matrix initialization

Campbell Barton noreply at git.blender.org
Tue Apr 29 10:15:51 CEST 2014


Commit: 409fb4da0ce671d9c5cf54cb327770d6b4e97cb2
Author: Campbell Barton
Date:   Tue Apr 29 18:12:44 2014 +1000
https://developer.blender.org/rB409fb4da0ce671d9c5cf54cb327770d6b4e97cb2

Code cleanup: remove redundant matrix initialization

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

M	source/blender/blenkernel/intern/armature.c
M	source/blender/blenkernel/intern/object.c
M	source/blender/blenlib/intern/math_geom.c
M	source/blender/editors/sculpt_paint/sculpt.c
M	source/blender/editors/space_view3d/view3d_snap.c
M	source/blender/editors/transform/transform.c
M	source/blender/editors/transform/transform_constraints.c
M	source/blender/editors/transform/transform_manipulator.c
M	source/blender/python/mathutils/mathutils_Matrix.c
M	source/blender/render/intern/source/zbuf.c

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

diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c
index 3920f59..6d01d9f 100644
--- a/source/blender/blenkernel/intern/armature.c
+++ b/source/blender/blenkernel/intern/armature.c
@@ -594,7 +594,6 @@ static void pchan_b_bone_defmats(bPoseChannel *pchan, bPoseChanDeform *pdef_info
 	Mat4 b_bone[MAX_BBONE_SUBDIV], b_bone_rest[MAX_BBONE_SUBDIV];
 	Mat4 *b_bone_mats;
 	DualQuat *b_bone_dual_quats = NULL;
-	float tmat[4][4] = MAT4_UNITY;
 	int a;
 
 	b_bone_spline_setup(pchan, 0, b_bone);
@@ -620,6 +619,8 @@ static void pchan_b_bone_defmats(bPoseChannel *pchan, bPoseChanDeform *pdef_info
 	 * - transform back into global space */
 
 	for (a = 0; a < bone->segments; a++) {
+		float tmat[4][4];
+
 		invert_m4_m4(tmat, b_bone_rest[a].mat);
 
 		mul_serie_m4(b_bone_mats[a + 1].mat, pchan->chan_mat, bone->arm_mat, b_bone[a].mat, tmat, b_bone_mats[0].mat,
@@ -1108,10 +1109,11 @@ void BKE_armature_mat_world_to_pose(Object *ob, float inmat[4][4], float outmat[
  *       pose-channel into its local space (i.e. 'visual'-keyframing) */
 void BKE_armature_loc_world_to_pose(Object *ob, const float inloc[3], float outloc[3])
 {
-	float xLocMat[4][4] = MAT4_UNITY;
+	float xLocMat[4][4];
 	float nLocMat[4][4];
 
 	/* build matrix for location */
+	unit_m4(xLocMat);
 	copy_v3_v3(xLocMat[3], inloc);
 
 	/* get bone-space cursor matrix and extract location */
@@ -1277,10 +1279,11 @@ void BKE_armature_mat_bone_to_pose(bPoseChannel *pchan, float inmat[4][4], float
  *       pose-channel into its local space (i.e. 'visual'-keyframing) */
 void BKE_armature_loc_pose_to_bone(bPoseChannel *pchan, const float inloc[3], float outloc[3])
 {
-	float xLocMat[4][4] = MAT4_UNITY;
+	float xLocMat[4][4];
 	float nLocMat[4][4];
 
 	/* build matrix for location */
+	unit_m4(xLocMat);
 	copy_v3_v3(xLocMat[3], inloc);
 
 	/* get bone-space cursor matrix and extract location */
diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c
index f601840..6f4fe63 100644
--- a/source/blender/blenkernel/intern/object.c
+++ b/source/blender/blenkernel/intern/object.c
@@ -2323,7 +2323,7 @@ void BKE_object_where_is_calc_time_ex(Scene *scene, Object *ob, float ctime,
 	
 	if (ob->parent) {
 		Object *par = ob->parent;
-		float slowmat[4][4] = MAT4_UNITY;
+		float slowmat[4][4];
 		
 		/* calculate parent matrix */
 		solve_parenting(scene, ob, par, ob->obmat, slowmat, r_originmat, true);
@@ -2369,9 +2369,10 @@ void BKE_object_where_is_calc_time(Scene *scene, Object *ob, float ctime)
  * used for bundles orientation in 3d space relative to parented blender camera */
 void BKE_object_where_is_calc_mat4(Scene *scene, Object *ob, float obmat[4][4])
 {
-	float slowmat[4][4] = MAT4_UNITY;
 
 	if (ob->parent) {
+		float slowmat[4][4];
+
 		Object *par = ob->parent;
 		
 		solve_parenting(scene, ob, par, obmat, slowmat, NULL, false);
diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c
index a128960..58bb7c1 100644
--- a/source/blender/blenlib/intern/math_geom.c
+++ b/source/blender/blenlib/intern/math_geom.c
@@ -2996,9 +2996,10 @@ void polarview_m4(float Vm[4][4], float dist, float azimuth, float incidence, fl
 void lookat_m4(float mat[4][4], float vx, float vy, float vz, float px, float py, float pz, float twist)
 {
 	float sine, cosine, hyp, hyp1, dx, dy, dz;
-	float mat1[4][4] = MAT4_UNITY;
+	float mat1[4][4];
 
 	unit_m4(mat);
+	unit_m4(mat1);
 
 	rotate_m4(mat, 'Z', -twist);
 
diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c
index d8816e7..b2e5207 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -781,7 +781,8 @@ static float calc_overlap(StrokeCache *cache, const char symm, const char axis,
 	flip_v3_v3(mirror, cache->true_location, symm);
 
 	if (axis != 0) {
-		float mat[4][4] = MAT4_UNITY;
+		float mat[4][4];
+		unit_m4(mat);
 		rotate_m4(mat, axis, angle);
 		mul_m4_v3(mat, mirror);
 	}
diff --git a/source/blender/editors/space_view3d/view3d_snap.c b/source/blender/editors/space_view3d/view3d_snap.c
index 26ebd1d..8e6deed 100644
--- a/source/blender/editors/space_view3d/view3d_snap.c
+++ b/source/blender/editors/space_view3d/view3d_snap.c
@@ -414,7 +414,7 @@ static void bundle_midpoint(Scene *scene, Object *ob, float vec[3])
 	MovieTracking *tracking;
 	MovieTrackingObject *object;
 	bool ok = false;
-	float min[3], max[3], mat[4][4], pos[3], cammat[4][4] = MAT4_UNITY;
+	float min[3], max[3], mat[4][4], pos[3], cammat[4][4];
 
 	if (!clip)
 		return;
diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c
index b52fba3..2cec4d6 100644
--- a/source/blender/editors/transform/transform.c
+++ b/source/blender/editors/transform/transform.c
@@ -945,7 +945,6 @@ static void transform_event_xyz_constraint(TransInfo *t, short key_type, char cm
 
 int transformEvent(TransInfo *t, const wmEvent *event)
 {
-	float mati[3][3] = MAT3_UNITY;
 	char cmode = constraintModeToChar(t);
 	bool handled = false;
 
@@ -1306,7 +1305,9 @@ int transformEvent(TransInfo *t, const wmEvent *event)
 							}
 							else {
 								/* bit hackish... but it prevents mmb select to print the orientation from menu */
+								float mati[3][3];
 								strcpy(t->spacename, "global");
+								unit_m3(mati);
 								initSelectConstraint(t, mati);
 							}
 							postSelectConstraint(t);
diff --git a/source/blender/editors/transform/transform_constraints.c b/source/blender/editors/transform/transform_constraints.c
index 4cc8833..749c45e 100644
--- a/source/blender/editors/transform/transform_constraints.c
+++ b/source/blender/editors/transform/transform_constraints.c
@@ -625,8 +625,9 @@ void setUserConstraint(TransInfo *t, short orientation, int mode, const char fte
 	switch (orientation) {
 		case V3D_MANIP_GLOBAL:
 		{
-			float mtx[3][3] = MAT3_UNITY;
+			float mtx[3][3];
 			BLI_snprintf(text, sizeof(text), ftext, IFACE_("global"));
+			unit_m3(mtx);
 			setConstraint(t, mtx, mode, text);
 			break;
 		}
diff --git a/source/blender/editors/transform/transform_manipulator.c b/source/blender/editors/transform/transform_manipulator.c
index a2b53da..aaa67e5 100644
--- a/source/blender/editors/transform/transform_manipulator.c
+++ b/source/blender/editors/transform/transform_manipulator.c
@@ -1507,7 +1507,9 @@ static void draw_manipulator_rotate_cyl(
 
 	/* Screen aligned view rot circle */
 	if (drawflags & MAN_ROT_V) {
-		float unitmat[4][4] = MAT4_UNITY;
+		float unitmat[4][4];
+
+		unit_m4(unitmat);
 
 		if (is_picksel) glLoadName(MAN_ROT_V);
 		UI_ThemeColor(TH_TRANSFORM);
diff --git a/source/blender/python/mathutils/mathutils_Matrix.c b/source/blender/python/mathutils/mathutils_Matrix.c
index 1c8718a..3b526f8 100644
--- a/source/blender/python/mathutils/mathutils_Matrix.c
+++ b/source/blender/python/mathutils/mathutils_Matrix.c
@@ -550,7 +550,9 @@ PyDoc_STRVAR(C_Matrix_Translation_doc,
 );
 static PyObject *C_Matrix_Translation(PyObject *cls, PyObject *value)
 {
-	float mat[4][4] = MAT4_UNITY;
+	float mat[4][4];
+
+	unit_m4(mat);
 
 	if (mathutils_array_parse(mat[3], 3, 4, value, "mathutils.Matrix.Translation(vector), invalid vector arg") == -1)
 		return NULL;
@@ -1013,7 +1015,7 @@ PyDoc_STRVAR(Matrix_resize_4x4_doc,
 );
 static PyObject *Matrix_resize_4x4(MatrixObject *self)
 {
-	float mat[4][4] = MAT4_UNITY;
+	float mat[4][4];
 	int col;
 
 	if (self->wrapped == Py_WRAP) {
@@ -1029,7 +1031,7 @@ static PyObject *Matrix_resize_4x4(MatrixObject *self)
 		return NULL;
 	}
 
-	self->matrix = PyMem_Realloc(self->matrix, (sizeof(float) * 16));
+	self->matrix = PyMem_Realloc(self->matrix, (sizeof(float) * (MATRIX_MAX_DIM * MATRIX_MAX_DIM)));
 	if (self->matrix == NULL) {
 		PyErr_SetString(PyExc_MemoryError,
 		                "Matrix.resize_4x4(): "
@@ -1037,6 +1039,8 @@ static PyObject *Matrix_resize_4x4(MatrixObject *self)
 		return NULL;
 	}
 
+	unit_m4(mat);
+
 	for (col = 0; col < self->num_col; col++) {
 		memcpy(mat[col], MATRIX_COL_PTR(self, col), self->num_row * sizeof(float));
 	}
@@ -1177,10 +1181,7 @@ static PyObject *Matrix_invert(MatrixObject *self)
 
 	int x, y, z = 0;
 	float det = 0.0f;
-	float mat[16] = {0.0f, 0.0f, 0.0f, 0.0f,
-	                 0.0f, 0.0f, 0.0f, 0.0f,
-	                 0.0f, 0.0f, 0.0f, 0.0f,
-	                 0.0f, 0.0f, 0.0f, 1.0f};
+	float mat[MATRIX_MAX_DIM * MATRIX_MAX_DIM];
 
 	if (BaseMath_ReadCallback(self) == -1)
 		return NULL;
@@ -1811,7 +1812,7 @@ static PyObject *Matrix_item_col(MatrixObject *self, int col)
 static int Matrix_ass_item_row(MatrixObject *self, int row, PyObject *value)
 {
 	int col;
-	float vec[4];
+	float vec[MATRIX_MAX_DIM];
 	if (BaseMath_ReadCallback(self) == -1)
 		return -1;
 
@@ -1836,7 +1837,7 @@ static int Matrix_ass_item_row(MatrixObject *self, int row, PyObject *value)
 static int Matrix_ass_item_col(MatrixObject *self, int col, PyObject *value)
 {
 	int row;
-	float vec[4];
+	float vec[MATRIX_MAX_DIM];
 	if (BaseMath_ReadCallback(self) == -1)
 		return -1;
 
@@ -1904,7 +1905,7 @@ static int Matrix_ass_slice(MatrixObject *self, int begin, int end, PyObject *va
 	else {
 		const int size = end - begin;
 		int row, col;
-		float mat[16];
+		float mat[MATRIX_MAX_DIM * MATRIX_MAX_DIM];
 		float vec[4];
 
 		if (PySequence_Fast_GET_SIZE(value_fast) != size) {
@@ -1946,7 +1947,7 @@ static int Matrix_ass_slice(MatrixObject *self, int begin, int end, PyObject *va
  *------------------------obj + obj------------------------------*/
 static PyObject *Matrix_add(PyObject *m1, PyObject *m2)
 {
-	float mat[16];
+	float mat[MATRIX_MAX_DIM * MATRIX_MAX_DIM];
 	MatrixObject *mat1 = NULL, *mat2 = NULL;
 
 	mat1 = (MatrixObject *)m1;
@@ -1978,7 +1979,7 @@ static PyObject *Matrix_add(PyObject *m1, PyObject *m2)
  * subtraction */
 static PyObject *Matrix_sub(PyObject *m1, PyObject *m2)
 {
-	float mat[16];
+	float mat[MATRIX_MAX_DIM * MATRIX_MAX_DIM];
 	MatrixObject *mat1 = NULL, *mat2 = NULL;
 
 	mat1 = (MatrixObject *)m1;
@@ -2010,7 +2011,7 @@ static PyObject *Matrix_sub(PyObject *m1, PyObject *m2)
  * multiplication */
 static PyObject *matrix_mul_float(MatrixObject *ma

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list