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.
This commit is contained in:
Bastien Montagne 2015-07-11 00:04:27 +02:00
parent bf3fe67862
commit 909fa34c5f
Notes: blender-bot 2023-02-14 08:53:19 +01:00
Referenced by issue #45900, Blender replacing spaces in filename with underscore
Referenced by issue #45444, Mask becomes "local"?
2 changed files with 29 additions and 0 deletions

View File

@ -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]);

View File

@ -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);