new struct PathPoint for each path element (replaces float[4]), Paths now store radius and quaternion

Added optional quat and radius args to anim.c's where_on_path(...), currently unused.

also cleanup some warnings.
This commit is contained in:
2009-09-12 14:12:37 +00:00
parent 3f9d3b2a0b
commit d16bde417f
13 changed files with 88 additions and 49 deletions

View File

@@ -51,7 +51,7 @@ typedef struct DupliObject {
void free_path(struct Path *path);
void calc_curvepath(struct Object *ob);
int interval_test(int min, int max, int p1, int cycl);
int where_on_path(struct Object *ob, float ctime, float *vec, float *dir);
int where_on_path(struct Object *ob, float ctime, float *vec, float *dir, float *quat, float *radius);
struct ListBase *object_duplilist(struct Scene *sce, struct Object *ob);
void free_object_duplilist(struct ListBase *lb);

View File

@@ -87,15 +87,16 @@ void free_path(Path *path)
void calc_curvepath(Object *ob)
{
BevList *bl;
BevPoint *bevp, *bevpn, *bevpfirst, *bevplast, *tempbevp;
BevPoint *bevp, *bevpn, *bevpfirst, *bevplast;
PathPoint *pp;
Curve *cu;
Nurb *nu;
Path *path;
float *fp, *dist, *maxdist, xyz[3];
float fac, d=0, fac1, fac2;
int a, tot, cycl=0;
float *ft;
/* in a path vertices are with equal differences: path->len = number of verts */
/* NOW WITH BEVELCURVE!!! */
@@ -145,7 +146,7 @@ void calc_curvepath(Object *ob)
/* the path verts in path->data */
/* now also with TILT value */
ft= path->data = (float *)MEM_callocN(16*path->len, "pathdata");
pp= path->data = (PathPoint *)MEM_callocN(sizeof(PathPoint)*4*path->len, "pathdata"); // XXX - why *4? - in 2.4x each element was 4 and the size was 16, so better leave for now - Campbell
bevp= bevpfirst;
bevpn= bevp+1;
@@ -175,10 +176,13 @@ void calc_curvepath(Object *ob)
fac1= fac2/fac1;
fac2= 1.0f-fac1;
VecLerpf(ft, bevp->vec, bevpn->vec, fac2);
ft[3]= fac1*bevp->alfa+ fac2*(bevpn)->alfa;
VecLerpf(pp->vec, bevp->vec, bevpn->vec, fac2);
pp->vec[3]= fac1*bevp->alfa + fac2*bevpn->alfa;
pp->radius= fac1*bevp->radius + fac2*bevpn->radius;
QuatInterpol(pp->quat, bevp->quat, bevpn->quat, fac2);
NormalQuat(pp->quat);
ft+= 4;
pp++;
}
MEM_freeN(dist);
@@ -202,13 +206,14 @@ int interval_test(int min, int max, int p1, int cycl)
/* warning, *vec needs FOUR items! */
/* ctime is normalized range <0-1> */
int where_on_path(Object *ob, float ctime, float *vec, float *dir) /* returns OK */
int where_on_path(Object *ob, float ctime, float *vec, float *dir, float *quat, float *radius) /* returns OK */
{
Curve *cu;
Nurb *nu;
BevList *bl;
Path *path;
float *fp, *p0, *p1, *p2, *p3, fac;
PathPoint *pp, *p0, *p1, *p2, *p3;
float fac;
float data[4];
int cycl=0, s0, s1, s2, s3;
@@ -219,7 +224,7 @@ int where_on_path(Object *ob, float ctime, float *vec, float *dir) /* returns OK
return 0;
}
path= cu->path;
fp= path->data;
pp= path->data;
/* test for cyclic */
bl= cu->bev.first;
@@ -238,19 +243,19 @@ int where_on_path(Object *ob, float ctime, float *vec, float *dir) /* returns OK
s2= interval_test(0, path->len-1-cycl, s1+1, cycl);
s3= interval_test(0, path->len-1-cycl, s1+2, cycl);
p0= fp + 4*s0;
p1= fp + 4*s1;
p2= fp + 4*s2;
p3= fp + 4*s3;
p0= pp + s0;
p1= pp + s1;
p2= pp + s2;
p3= pp + s3;
/* note, commented out for follow constraint */
//if(cu->flag & CU_FOLLOW) {
key_curve_tangent_weights(1.0f-fac, data, KEY_BSPLINE);
dir[0]= data[0]*p0[0] + data[1]*p1[0] + data[2]*p2[0] + data[3]*p3[0] ;
dir[1]= data[0]*p0[1] + data[1]*p1[1] + data[2]*p2[1] + data[3]*p3[1] ;
dir[2]= data[0]*p0[2] + data[1]*p1[2] + data[2]*p2[2] + data[3]*p3[2] ;
dir[0]= data[0]*p0->vec[0] + data[1]*p1->vec[0] + data[2]*p2->vec[0] + data[3]*p3->vec[0] ;
dir[1]= data[0]*p0->vec[1] + data[1]*p1->vec[1] + data[2]*p2->vec[1] + data[3]*p3->vec[1] ;
dir[2]= data[0]*p0->vec[2] + data[1]*p1->vec[2] + data[2]*p2->vec[2] + data[3]*p3->vec[2] ;
/* make compatible with vectoquat */
dir[0]= -dir[0];
@@ -266,11 +271,30 @@ int where_on_path(Object *ob, float ctime, float *vec, float *dir) /* returns OK
else if(s0==s1 || p2==p3) key_curve_position_weights(1.0f-fac, data, KEY_CARDINAL);
else key_curve_position_weights(1.0f-fac, data, KEY_BSPLINE);
vec[0]= data[0]*p0[0] + data[1]*p1[0] + data[2]*p2[0] + data[3]*p3[0] ;
vec[1]= data[0]*p0[1] + data[1]*p1[1] + data[2]*p2[1] + data[3]*p3[1] ;
vec[2]= data[0]*p0[2] + data[1]*p1[2] + data[2]*p2[2] + data[3]*p3[2] ;
vec[0]= data[0]*p0->vec[0] + data[1]*p1->vec[0] + data[2]*p2->vec[0] + data[3]*p3->vec[0] ; /* X */
vec[1]= data[0]*p0->vec[1] + data[1]*p1->vec[1] + data[2]*p2->vec[1] + data[3]*p3->vec[1] ; /* Y */
vec[2]= data[0]*p0->vec[2] + data[1]*p1->vec[2] + data[2]*p2->vec[2] + data[3]*p3->vec[2] ; /* Z */
vec[3]= data[0]*p0->vec[3] + data[1]*p1->vec[3] + data[2]*p2->vec[3] + data[3]*p3->vec[3] ; /* Tilt, should not be needed since we have quat still used */
/* Need to verify the quat interpolation is correct - XXX */
vec[3]= data[0]*p0[3] + data[1]*p1[3] + data[2]*p2[3] + data[3]*p3[3] ;
if (quat) {
float totfac, q1[4], q2[4];
totfac= data[0]+data[1];
QuatInterpol(q1, p0->quat, p1->quat, data[0] / totfac);
NormalQuat(q1);
totfac= data[2]+data[3];
QuatInterpol(q2, p2->quat, p3->quat, data[2] / totfac);
NormalQuat(q2);
totfac = data[0]+data[1]+data[2]+data[3];
QuatInterpol(quat, q1, q2, (data[0]+data[1]) / totfac);
NormalQuat(quat);
}
if(radius)
*radius= data[0]*p0->radius + data[1]*p1->radius + data[2]*p2->radius + data[3]*p3->radius;
return 1;
}

View File

@@ -1174,7 +1174,7 @@ static void followpath_get_tarmat (bConstraint *con, bConstraintOb *cob, bConstr
*/
/* only happens on reload file, but violates depsgraph still... fix! */
if (cu->path==NULL || cu->path->data==NULL)
if (cu->path==NULL || cu->path->data==NULL)
makeDispListCurveTypes(cob->scene, ct->tar, 0);
if (cu->path && cu->path->data) {
@@ -1196,7 +1196,7 @@ static void followpath_get_tarmat (bConstraint *con, bConstraintOb *cob, bConstr
curvetime= data->offset; // XXX might need a more sensible value
}
if ( where_on_path(ct->tar, curvetime, vec, dir) ) {
if ( where_on_path(ct->tar, curvetime, vec, dir, NULL, NULL) ) {
if (data->followflag & FOLLOWPATH_FOLLOW) {
vectoquat(dir, (short) data->trackflag, (short) data->upflag, quat);
@@ -2864,7 +2864,7 @@ static void clampto_get_tarmat (bConstraint *con, bConstraintOb *cob, bConstrain
*/
/* only happens on reload file, but violates depsgraph still... fix! */
if (cu->path==NULL || cu->path->data==NULL)
if (cu->path==NULL || cu->path->data==NULL)
makeDispListCurveTypes(cob->scene, ct->tar, 0);
}
@@ -2975,7 +2975,7 @@ static void clampto_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *ta
}
/* 3. position on curve */
if (where_on_path(ct->tar, curvetime, vec, dir) ) {
if (where_on_path(ct->tar, curvetime, vec, dir, NULL, NULL) ) {
Mat4One(totmat);
VECCOPY(totmat[3], vec);

View File

@@ -1039,8 +1039,8 @@ struct chartrans *BKE_text_to_curve(Scene *scene, Object *ob, int mode)
/* calc the right loc AND the right rot separately */
/* vec, tvec need 4 items */
where_on_path(cu->textoncurve, ctime, vec, tvec);
where_on_path(cu->textoncurve, ctime+dtime, tvec, rotvec);
where_on_path(cu->textoncurve, ctime, vec, tvec, NULL, NULL);
where_on_path(cu->textoncurve, ctime+dtime, tvec, rotvec, NULL, NULL);
VecMulf(vec, sizefac);

View File

@@ -472,7 +472,7 @@ static void init_curve_deform(Object *par, Object *ob, CurveDeform *cd, int dloc
}
/* this makes sure we can extend for non-cyclic. *vec needs 4 items! */
static int where_on_path_deform(Object *ob, float ctime, float *vec, float *dir) /* returns OK */
static int where_on_path_deform(Object *ob, float ctime, float *vec, float *dir, float *quat, float *radius) /* returns OK */
{
Curve *cu= ob->data;
BevList *bl;
@@ -490,21 +490,25 @@ static int where_on_path_deform(Object *ob, float ctime, float *vec, float *dir)
else ctime1= ctime;
/* vec needs 4 items */
if(where_on_path(ob, ctime1, vec, dir)) {
if(where_on_path(ob, ctime1, vec, dir, quat, radius)) {
if(cycl==0) {
Path *path= cu->path;
float dvec[3];
if(ctime < 0.0) {
VecSubf(dvec, path->data+4, path->data);
VecSubf(dvec, path->data[1].vec, path->data[0].vec);
VecMulf(dvec, ctime*(float)path->len);
VECADD(vec, vec, dvec);
if(quat) QUATCOPY(quat, path->data[0].quat);
if(radius) *radius= path->data[0].radius;
}
else if(ctime > 1.0) {
VecSubf(dvec, path->data+4*path->len-4, path->data+4*path->len-8);
VecSubf(dvec, path->data[path->len-1].vec, path->data[path->len-2].vec);
VecMulf(dvec, (ctime-1.0)*(float)path->len);
VECADD(vec, vec, dvec);
if(quat) QUATCOPY(quat, path->data[path->len-1].quat);
if(radius) *radius= path->data[path->len-1].radius;
}
}
return 1;
@@ -575,7 +579,7 @@ static int calc_curve_deform(Scene *scene, Object *par, float *co, short axis, C
}
#endif // XXX old animation system
if( where_on_path_deform(par, fac, loc, dir)) { /* returns OK */
if( where_on_path_deform(par, fac, loc, dir, NULL, NULL)) { /* returns OK */
float q[4], mat[3][3], quat[4];
if(cd->no_rot_axis) /* set by caller */

View File

@@ -1114,7 +1114,7 @@ ParticleSystem *copy_particlesystem(ParticleSystem *psys)
}
if(psys->clmd) {
ClothModifierData *nclmd = modifier_new(eModifierType_Cloth);
ClothModifierData *nclmd = (ClothModifierData *)modifier_new(eModifierType_Cloth);
modifier_copyData((ModifierData*)psys->clmd, (ModifierData*)nclmd);
psys->hair_in_dm = psys->hair_out_dm = NULL;
}
@@ -1694,7 +1694,7 @@ static void ob_parcurve(Scene *scene, Object *ob, Object *par, float mat[][4])
/* vec: 4 items! */
if( where_on_path(par, ctime, vec, dir) ) {
if( where_on_path(par, ctime, vec, dir, NULL, NULL) ) {
if(cu->flag & CU_FOLLOW) {
vectoquat(dir, ob->trackflag, ob->upflag, quat);

View File

@@ -60,6 +60,7 @@
#include "BKE_anim.h"
#include "BKE_boids.h"
#include "BKE_cloth.h"
#include "BKE_global.h"
#include "BKE_main.h"
#include "BKE_lattice.h"
@@ -1974,9 +1975,9 @@ int do_guide(Scene *scene, ParticleKey *state, int pa_num, float time, ListBase
}
if(pd->flag & PFIELD_GUIDE_PATH_ADD)
where_on_path(eob, f_force*guidetime, guidevec, guidedir);
where_on_path(eob, f_force*guidetime, guidevec, guidedir, NULL, NULL);
else
where_on_path(eob, guidetime, guidevec, guidedir);
where_on_path(eob, guidetime, guidevec, guidedir, NULL, NULL);
Mat4MulVecfl(ec->ob->obmat,guidevec);
Mat4Mul3Vecfl(ec->ob->obmat,guidedir);

View File

@@ -2536,7 +2536,7 @@ static void precalc_effectors(Scene *scene, Object *ob, ParticleSystem *psys, Pa
&& part->phystype!=PART_PHYS_BOIDS) {
float vec[4];
where_on_path(ec->ob, 0.0, vec, vec2);
where_on_path(ec->ob, 0.0, vec, vec2, NULL, NULL);
Mat4MulVecfl(ec->ob->obmat,vec);
Mat4Mul3Vecfl(ec->ob->obmat,vec2);

View File

@@ -38,6 +38,7 @@
#include <float.h>
#include <math.h>
#include "stdio.h"
#include "string.h" /* memset */
#include "BLI_linklist.h"
#include "BLI_rand.h"

View File

@@ -299,7 +299,7 @@ void Mat3MulMat3(float *m1, float *m3, float *m2);
#endif
void Mat4MulMat34(float (*m1)[4], float (*m3)[3], float (*m2)[4]);
void Mat4CpyMat4(float m1[][4], float m2[][4]);
void Mat4SwapMat4(float *m1, float *m2);
void Mat4SwapMat4(float m1[][4], float m2[][4]);
void Mat3CpyMat3(float m1[][3], float m2[][3]);
void Mat3MulSerie(float answ[][3],

View File

@@ -614,17 +614,17 @@ void Mat4CpyMat4(float m1[][4], float m2[][4])
memcpy(m1, m2, 4*4*sizeof(float));
}
void Mat4SwapMat4(float *m1, float *m2)
void Mat4SwapMat4(float m1[][4], float m2[][4])
{
float t;
int i;
int i, j;
for(i=0;i<16;i++) {
t= *m1;
*m1= *m2;
*m2= t;
m1++;
m2++;
for(i = 0; i < 4; i++) {
for (j = 0; j < 4; j++) {
t = m1[i][j];
m1[i][j] = m2[i][j];
m2[i][j] = t;
}
}
}

View File

@@ -4546,13 +4546,13 @@ static void draw_forcefield(Scene *scene, Object *ob)
/*path end*/
setlinestyle(3);
where_on_path(ob, 1.0f, guidevec1, guidevec2);
where_on_path(ob, 1.0f, guidevec1, guidevec2, NULL, NULL);
UI_ThemeColorBlend(curcol, TH_BACK, 0.5);
drawcircball(GL_LINE_LOOP, guidevec1, mindist, imat);
/*path beginning*/
setlinestyle(0);
where_on_path(ob, 0.0f, guidevec1, guidevec2);
where_on_path(ob, 0.0f, guidevec1, guidevec2, NULL, NULL);
UI_ThemeColorBlend(curcol, TH_BACK, 0.5);
drawcircball(GL_LINE_LOOP, guidevec1, mindist, imat);

View File

@@ -49,12 +49,21 @@ struct AnimData;
struct SelBox;
struct EditFont;
/* These two Lines with # tell makesdna this struct can be excluded. */
#
#
typedef struct PathPoint {
float vec[4]; /* grr, cant get rid of tilt yet */
float quat[4];
float radius;
} PathPoint;
/* These two Lines with # tell makesdna this struct can be excluded. */
#
#
typedef struct Path {
int len;
float *data;
struct PathPoint *data;
float totdist;
} Path;