diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2015-07-11 01:04:27 +0300 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2015-07-11 01:04:27 +0300 |
commit | 909fa34c5f8cea52ce5fa469315936c6303f41b1 (patch) | |
tree | 7bc64b5ebd494ba809d5bdf4494b578901ffffe7 /source/blender | |
parent | bf3fe67862e3a42193f45c49d3d6b07724453da7 (diff) |
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.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenlib/BLI_math_matrix.h | 1 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_matrix.c | 28 |
2 files changed, 29 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_math_matrix.h b/source/blender/blenlib/BLI_math_matrix.h index f7eeb1ec7a1..d7a309e0835 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 a9afed7a63d..33d0fb87aca 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); |