Code cleanup - Shuffled solve_parenting() function around to remove need for

forward def/local prototype
This commit is contained in:
Joshua Leung 2012-06-07 05:39:28 +00:00
parent e69ec8be55
commit ffd75901f3

@ -115,8 +115,6 @@
#include "GPU_material.h"
/* Local function protos */
static void solve_parenting(Scene *scene, Object *ob, Object *par, float obmat[][4], float slowmat[][4], int simul);
float originmat[3][3]; /* after BKE_object_where_is_calc(), can be used in other functions (bad!) */
void BKE_object_workob_clear(Object *workob)
@ -1904,88 +1902,6 @@ static void ob_parvert3(Object *ob, Object *par, float mat[][4])
}
}
static int where_is_object_parslow(Object *ob, float obmat[4][4], float slowmat[4][4])
{
float *fp1, *fp2;
float fac1, fac2;
int a;
// include framerate
fac1 = (1.0f / (1.0f + fabsf(ob->sf)) );
if (fac1 >= 1.0f) return 0;
fac2 = 1.0f - fac1;
fp1 = obmat[0];
fp2 = slowmat[0];
for (a = 0; a < 16; a++, fp1++, fp2++) {
fp1[0] = fac1 * fp1[0] + fac2 * fp2[0];
}
return 1;
}
void BKE_object_where_is_calc_time(Scene *scene, Object *ob, float ctime)
{
float slowmat[4][4] = MAT4_UNITY;
if (ob == NULL) return;
/* execute drivers only, as animation has already been done */
BKE_animsys_evaluate_animdata(scene, &ob->id, ob->adt, ctime, ADT_RECALC_DRIVERS);
if (ob->parent) {
Object *par = ob->parent;
/* calculate parent matrix */
solve_parenting(scene, ob, par, ob->obmat, slowmat, 0);
/* "slow parent" is definitely not threadsafe, and may also give bad results jumping around
* An old-fashioned hack which probably doesn't really cut it anymore
*/
if (ob->partype & PARSLOW) {
if (!where_is_object_parslow(ob, ob->obmat, slowmat))
return;
}
}
else {
BKE_object_to_mat4(ob, ob->obmat);
}
/* solve constraints */
if (ob->constraints.first && !(ob->transflag & OB_NO_CONSTRAINTS)) {
bConstraintOb *cob;
cob = constraints_make_evalob(scene, ob, NULL, CONSTRAINT_OBTYPE_OBJECT);
solve_constraints(&ob->constraints, cob, ctime);
constraints_clear_evalob(cob);
}
/* set negative scale flag in object */
if (is_negative_m4(ob->obmat)) ob->transflag |= OB_NEG_SCALE;
else ob->transflag &= ~OB_NEG_SCALE;
}
/* get object transformation matrix without recalculating dependencies and
* constraints -- assume dependencies are already solved by depsgraph.
* no changes to object and it's parent would be done.
* 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) {
Object *par = ob->parent;
solve_parenting(scene, ob, par, obmat, slowmat, 1);
if (ob->partype & PARSLOW)
where_is_object_parslow(ob, obmat, slowmat);
}
else {
BKE_object_to_mat4(ob, obmat);
}
}
static void solve_parenting(Scene *scene, Object *ob, Object *par, float obmat[][4], float slowmat[][4], int simul)
{
float totmat[4][4];
@ -2007,11 +1923,11 @@ static void solve_parenting(Scene *scene, Object *ob, Object *par, float obmat[]
ok = 1;
}
}
if (ok) mul_serie_m4(totmat, par->obmat, tmat,
NULL, NULL, NULL, NULL, NULL, NULL);
else copy_m4_m4(totmat, par->obmat);
break;
case PARBONE:
ob_parbone(ob, par, tmat);
@ -2031,7 +1947,7 @@ static void solve_parenting(Scene *scene, Object *ob, Object *par, float obmat[]
break;
case PARVERT3:
ob_parvert3(ob, par, tmat);
mul_serie_m4(totmat, par->obmat, tmat,
NULL, NULL, NULL, NULL, NULL, NULL);
break;
@ -2062,7 +1978,87 @@ static void solve_parenting(Scene *scene, Object *ob, Object *par, float obmat[]
copy_v3_v3(ob->orig, totmat[3]);
}
}
}
static int where_is_object_parslow(Object *ob, float obmat[4][4], float slowmat[4][4])
{
float *fp1, *fp2;
float fac1, fac2;
int a;
// include framerate
fac1 = (1.0f / (1.0f + fabsf(ob->sf)) );
if (fac1 >= 1.0f) return 0;
fac2 = 1.0f - fac1;
fp1 = obmat[0];
fp2 = slowmat[0];
for (a = 0; a < 16; a++, fp1++, fp2++) {
fp1[0] = fac1 * fp1[0] + fac2 * fp2[0];
}
return 1;
}
void BKE_object_where_is_calc_time(Scene *scene, Object *ob, float ctime)
{
if (ob == NULL) return;
/* execute drivers only, as animation has already been done */
BKE_animsys_evaluate_animdata(scene, &ob->id, ob->adt, ctime, ADT_RECALC_DRIVERS);
if (ob->parent) {
Object *par = ob->parent;
float slowmat[4][4] = MAT4_UNITY;
/* calculate parent matrix */
solve_parenting(scene, ob, par, ob->obmat, slowmat, 0);
/* "slow parent" is definitely not threadsafe, and may also give bad results jumping around
* An old-fashioned hack which probably doesn't really cut it anymore
*/
if (ob->partype & PARSLOW) {
if (!where_is_object_parslow(ob, ob->obmat, slowmat))
return;
}
}
else {
BKE_object_to_mat4(ob, ob->obmat);
}
/* solve constraints */
if (ob->constraints.first && !(ob->transflag & OB_NO_CONSTRAINTS)) {
bConstraintOb *cob;
cob = constraints_make_evalob(scene, ob, NULL, CONSTRAINT_OBTYPE_OBJECT);
solve_constraints(&ob->constraints, cob, ctime);
constraints_clear_evalob(cob);
}
/* set negative scale flag in object */
if (is_negative_m4(ob->obmat)) ob->transflag |= OB_NEG_SCALE;
else ob->transflag &= ~OB_NEG_SCALE;
}
/* get object transformation matrix without recalculating dependencies and
* constraints -- assume dependencies are already solved by depsgraph.
* no changes to object and it's parent would be done.
* 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) {
Object *par = ob->parent;
solve_parenting(scene, ob, par, obmat, slowmat, 1);
if (ob->partype & PARSLOW)
where_is_object_parslow(ob, obmat, slowmat);
}
else {
BKE_object_to_mat4(ob, obmat);
}
}
void BKE_object_where_is_calc(struct Scene *scene, Object *ob)
@ -2070,7 +2066,6 @@ void BKE_object_where_is_calc(struct Scene *scene, Object *ob)
BKE_object_where_is_calc_time(scene, ob, (float)scene->r.cfra);
}
void BKE_object_where_is_calc_simul(Scene *scene, Object *ob)
/* was written for the old game engine (until 2.04) */
/* It seems that this function is only called