[Bf-blender-cvs] [909fa34] master: BLI_matrix space_transform: Add a 'local-invariant' setter.

Bastien Montagne noreply at git.blender.org
Sat Jul 11 00:09:11 CEST 2015


Commit: 909fa34c5f8cea52ce5fa469315936c6303f41b1
Author: Bastien Montagne
Date:   Sat Jul 11 00:04:27 2015 +0200
Branches: master
https://developer.blender.org/rB909fa34c5f8cea52ce5fa469315936c6303f41b1

BLI_matrix space_transform: Add a 'local-invariant' setter.

`BLI_space_transform_from_matrices()` defines a 'global-invariant' transform
(same point in global space, two different coordinates in local and target spaces).

New `BLI_space_transform_global_from_matrices()` is kind of opposite, it defines
a 'local-invariant' transform (two different points in global space, same coordinates in local and target spaces).

Useful to 'match' meshes.

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

M	source/blender/blenlib/BLI_math_matrix.h
M	source/blender/blenlib/intern/math_matrix.c

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

diff --git a/source/blender/blenlib/BLI_math_matrix.h b/source/blender/blenlib/BLI_math_matrix.h
index f7eeb1e..d7a309e 100644
--- a/source/blender/blenlib/BLI_math_matrix.h
+++ b/source/blender/blenlib/BLI_math_matrix.h
@@ -241,6 +241,7 @@ typedef struct SpaceTransform {
 } SpaceTransform;
 
 void BLI_space_transform_from_matrices(struct SpaceTransform *data, float local[4][4], float target[4][4]);
+void BLI_space_transform_global_from_matrices(struct SpaceTransform *data, float local[4][4], float target[4][4]);
 void BLI_space_transform_apply(const struct SpaceTransform *data, float co[3]);
 void BLI_space_transform_invert(const struct SpaceTransform *data, float co[3]);
 void BLI_space_transform_apply_normal(const struct SpaceTransform *data, float no[3]);
diff --git a/source/blender/blenlib/intern/math_matrix.c b/source/blender/blenlib/intern/math_matrix.c
index a9afed7..33d0fb8 100644
--- a/source/blender/blenlib/intern/math_matrix.c
+++ b/source/blender/blenlib/intern/math_matrix.c
@@ -2312,6 +2312,16 @@ void invert_m4_m4_safe(float Ainv[4][4], float A[4][4])
  *
  */
 
+/**
+ * Global-invariant transform.
+ *
+ * This defines a matrix transforming a point in local space to a point in target space such that its global
+ * coordinates remain unchanged.
+ *
+ * In other words, if we have a global point P with local coordinates (x, y, z) and global coordinates (X, Y, Z),
+ * this defines a transform matrix TM such that (x', y', z') = TM * (x, y, z)
+ * where (x', y', z') are the coordinates of P' in target space such that it keeps (X, Y, Z) coordinates in global space.
+ */
 void BLI_space_transform_from_matrices(SpaceTransform *data, float local[4][4], float target[4][4])
 {
 	float itarget[4][4];
@@ -2320,6 +2330,24 @@ void BLI_space_transform_from_matrices(SpaceTransform *data, float local[4][4],
 	invert_m4_m4(data->target2local, data->local2target);
 }
 
+/**
+ * Local-invariant transform.
+ *
+ * This defines a matrix transforming a point in global space such that its local coordinates
+ * (from local space to target space) remain unchanged.
+ *
+ * In other words, if we have a local point p with local coordinates (x, y, z) and global coordinates (X, Y, Z),
+ * this defines a transform matrix TM such that (X', Y', Z') = TM * (X, Y, Z)
+ * where (X', Y', Z') are the coordinates of p' in global space such that it keeps (x, y, z) coordinates in target space.
+ */
+void BLI_space_transform_global_from_matrices(SpaceTransform *data, float local[4][4], float target[4][4])
+{
+	float ilocal[4][4];
+	invert_m4_m4(ilocal, local);
+	mul_m4_m4m4(data->local2target, target, ilocal);
+	invert_m4_m4(data->target2local, data->local2target);
+}
+
 void BLI_space_transform_apply(const SpaceTransform *data, float co[3])
 {
 	mul_v3_m4v3(co, ((SpaceTransform *)data)->local2target, co);




More information about the Bf-blender-cvs mailing list