Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Leung <aligorith@gmail.com>2007-07-15 07:35:37 +0400
committerJoshua Leung <aligorith@gmail.com>2007-07-15 07:35:37 +0400
commitaf55d208f48017872e30faa76a66d777c983106d (patch)
tree818c07d693d001230e7730efd10575813f98f178 /source/blender/blenlib
parent0f692d999a3529b73d6b153f6beaf9b570396d36 (diff)
== Constraints System ==
After just over a week of coding, I've finished doing a major refactor/cleanup of the constraints code. In the process, quite a few old kludges and ugly hacks have been removed. Also, some new features which will greatly benefit riggers have been implemented. === What's New === * The long-awaited ``ChildOf Constraint'': This allows you to animate parent influences, and choose which transformation channels the parent affects the child on (i.e. no translation/rotation/scaling). It should be noted that disabling some combinations may not totally work as expected. Also, the 'Set Inverse' and 'Clear Inverse' buttons at the bottom of this constraint's panel set/clear the inverse correction for the parent's effects. Use these to make the owner not stick/be glued to the parent. * Constraint/Target Evaluation Spaces: In some constraints, there are now 1-2 combo boxes at the bottom of their panel, which allows you to pick which `co-ordinate space' they are evaluated in. This is much more flexible than the old 'local' options for bones only were. * Action Constraint - Loc/Rot/Size Inputs The Action Constraint can finally use the target's location/rotation/scaling transforms as input, to control the owner of the constraint. This should work much more reliably than it used to. The target evaluation should now also be more accurate due to the new space conversion stuff. * Transform - No longer in Crazy Space (TM) Transforming objects/bones with constraints applied should no longer occur in Crazy Space. They are now correctly inverse-corrected. This also applies to old-style object tracking. === General Code Changes === * solve_constraints is now in constraints.c. I've removed the old `blend consecutive constraints of same type' junk, which made the code more complex than it needed to be. * evaluate_constraint is now only passed the constraint, and two matrices. A few unused variables have been removed from here. * A tempolary struct, bConstraintOb, is now passed to solve_constraints instead of relying on an ugly, static workobject in some cases. This works much better. * Made the formatting of constraint code consistent * There's a version patch for older files so that constraint settings are correctly converted to the new system. This is currently done for MajorVersion <= 244, and SubVersion < 3. I've bumped up the subversion to 3 for this purpose. However, with the imminent 2.45 release, this may need to be adjusted accordingly. * LocEulSizeToMat4 and LocQuatSizeToMat4 now work in the order Size, Rot, Location. I've also added a few other math functions. * Mat4BlendMat4 is now in arithb. I've modified it's method slightly, to use other arithb functions, instead of its crazy blending scheme. * Moved some of the RigidBodyJoint constraint's code out of blenkernel, and into src. It shouldn't be setting its target in its data initialisation function based + accessing scene stuff where it was doing so. === Future Work === * Geometry to act as targets for constraints. A space has been reserved for this already. * Tidy up UI buttons of constraints
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r--source/blender/blenlib/BLI_arithb.h2
-rw-r--r--source/blender/blenlib/intern/arithb.c107
2 files changed, 58 insertions, 51 deletions
diff --git a/source/blender/blenlib/BLI_arithb.h b/source/blender/blenlib/BLI_arithb.h
index 1c476c08984..4ee01f7fe33 100644
--- a/source/blender/blenlib/BLI_arithb.h
+++ b/source/blender/blenlib/BLI_arithb.h
@@ -221,6 +221,7 @@ void Mat3TransMulVecfl(float mat[][3], float *vec);
void VecUpMat3old(float *vec, float mat[][3], short axis);
void VecUpMat3(float *vec, float mat[][3], short axis);
void VecRotToMat3(float *vec, float phi, float mat[][3]);
+void VecRotToMat4(float *vec, float phi, float mat[][4]);
void VecCopyf(float *v1, float *v2);
int VecLen(int *v1, int *v2);
@@ -325,6 +326,7 @@ void i_rotate(float angle, char axis, float mat[][4]);
void MinMax3(float *min, float *max, float *vec);
void SizeToMat3(float *size, float mat[][3]);
+void SizeToMat4(float *size, float mat[][4]);
void printmatrix3(char *str, float m[][3]);
void printmatrix4(char *str, float m[][4]);
diff --git a/source/blender/blenlib/intern/arithb.c b/source/blender/blenlib/intern/arithb.c
index c700f901ea3..125c24a7ada 100644
--- a/source/blender/blenlib/intern/arithb.c
+++ b/source/blender/blenlib/intern/arithb.c
@@ -765,39 +765,22 @@ void Mat4BlendMat4(float out[][4], float dst[][4], float src[][4], float srcweig
float squat[4], dquat[4], fquat[4];
float ssize[3], dsize[3], fsize[4];
float sloc[3], dloc[3], floc[3];
- float mat3[3][3], dstweight;
- float qmat[3][3], smat[3][3];
- int i;
-
- dstweight = 1.0F-srcweight;
-
- Mat3CpyMat4(mat3, dst);
- Mat3ToQuat(mat3, dquat);
- Mat3ToSize(mat3, dsize);
+
+ Mat4ToQuat(dst, dquat);
+ Mat4ToSize(dst, dsize);
VecCopyf(dloc, dst[3]);
- Mat3CpyMat4(mat3, src);
- Mat3ToQuat(mat3, squat);
- Mat3ToSize(mat3, ssize);
+ Mat4ToQuat(src, squat);
+ Mat4ToSize(src, ssize);
VecCopyf(sloc, src[3]);
- /* Do the actual blend */
- for (i=0; i<3; i++){
- floc[i] = (dloc[i]*dstweight) + (sloc[i]*srcweight);
- fsize[i] = 1.0f + ((dsize[i]-1.0f)*dstweight) + ((ssize[i]-1.0f)*srcweight);
- fquat[i+1] = (dquat[i+1]*dstweight) + (squat[i+1]*srcweight);
- }
-
- /* Do one more iteration for the quaternions only and normalize the quaternion if needed */
- fquat[0] = 1.0f + ((dquat[0]-1.0f)*dstweight) + ((squat[0]-1.0f)*srcweight);
- NormalQuat (fquat);
+ /* do blending */
+ VecLerpf(floc, dloc, sloc, srcweight);
+ QuatInterpol(fquat, dquat, squat, srcweight);
+ VecLerpf(fsize, dsize, ssize, srcweight);
- QuatToMat3(fquat, qmat);
- SizeToMat3(fsize, smat);
-
- Mat3MulMat3(mat3, qmat, smat);
- Mat4CpyMat3(out, mat3);
- VecCopyf(out[3], floc);
+ /* compose new matrix */
+ LocQuatSizeToMat4(out, floc, fquat, fsize);
}
void Mat4Clr(float *m)
@@ -2428,6 +2411,15 @@ void VecRotToMat3( float *vec, float phi, float mat[][3])
}
+void VecRotToMat4( float *vec, float phi, float mat[][4])
+{
+ float tmat[3][3];
+
+ VecRotToMat3(vec, phi, tmat);
+ Mat4One(mat);
+ Mat4CpyMat3(mat, tmat);
+}
+
void VecRotToQuat( float *vec, float phi, float *quat)
{
/* rotation of phi radials around vec */
@@ -2436,7 +2428,7 @@ void VecRotToQuat( float *vec, float phi, float *quat)
quat[1]= vec[0];
quat[2]= vec[1];
quat[3]= vec[2];
-
+
if( Normalize(quat+1) == 0.0) {
QuatOne(quat);
}
@@ -2614,6 +2606,15 @@ void SizeToMat3( float *size, float mat[][3])
mat[2][0]= 0.0;
}
+void SizeToMat4( float *size, float mat[][4])
+{
+ float tmat[3][3];
+
+ SizeToMat3(size, tmat);
+ Mat4One(mat);
+ Mat4CpyMat3(mat, tmat);
+}
+
void Mat3ToSize( float mat[][3], float *size)
{
float vec[3];
@@ -3286,43 +3287,47 @@ int point_in_tri_prism(float p[3], float v1[3], float v2[3], float v3[3])
/********************************************************/
/* make a 4x4 matrix out of 3 transform components */
+/* matrices are made in the order: scale * rot * loc */
void LocEulSizeToMat4(float mat[][4], float loc[3], float eul[3], float size[3])
{
- float tmat[3][3];
+ float rmat[3][3], smat[3][3], tmat[3][3];
- /* make base matrix */
- EulToMat3(eul, tmat);
-
- /* make new matrix */
+ /* initialise new matrix */
Mat4One(mat);
- mat[0][0] = tmat[0][0] * size[0];
- mat[0][1] = tmat[0][1] * size[1];
- mat[0][2] = tmat[0][2] * size[2];
-
- mat[1][0] = tmat[1][0] * size[0];
- mat[1][1] = tmat[1][1] * size[1];
- mat[1][2] = tmat[1][2] * size[2];
+ /* make rotation + scaling part */
+ EulToMat3(eul, rmat);
+ SizeToMat3(size, smat);
+ Mat3MulMat3(tmat, rmat, smat);
- mat[2][0] = tmat[2][0] * size[0];
- mat[2][1] = tmat[2][1] * size[1];
- mat[2][2] = tmat[2][2] * size[2];
+ /* copy rot/scale part to output matrix*/
+ Mat4CpyMat3(mat, tmat);
+ /* copy location to matrix */
mat[3][0] = loc[0];
mat[3][1] = loc[1];
mat[3][2] = loc[2];
}
/* make a 4x4 matrix out of 3 transform components */
+/* matrices are made in the order: scale * rot * loc */
void LocQuatSizeToMat4(float mat[][4], float loc[3], float quat[4], float size[3])
{
- float eul[3];
+ float rmat[3][3], smat[3][3], tmat[3][3];
- /* convert quaternion component to euler
- * NOTE: not as good as using quat directly. Todo for later.
- */
- QuatToEul(quat, eul);
+ /* initialise new matrix */
+ Mat4One(mat);
+
+ /* make rotation + scaling part */
+ QuatToMat3(quat, rmat);
+ SizeToMat3(size, smat);
+ Mat3MulMat3(tmat, rmat, smat);
+
+ /* copy rot/scale part to output matrix*/
+ Mat4CpyMat3(mat, tmat);
- /* make into matrix using exisiting code */
- LocEulSizeToMat4(mat, loc, eul, size);
+ /* copy location to matrix */
+ mat[3][0] = loc[0];
+ mat[3][1] = loc[1];
+ mat[3][2] = loc[2];
}