Revision: 23084 http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=23084 Author: blendix Date: 2009-09-09 20:09:03 +0200 (Wed, 09 Sep 2009)
Log Message: ----------- Small code cleanup related to curves, to avoid cryptic names: renamed set_four_ipo -> key_curve_position_weights renamed set_afgeleide_four_ipo -> key_curve_tangent_weights added key_curve_normal_weights Modified Paths: -------------- trunk/blender/source/blender/blenkernel/BKE_key.h trunk/blender/source/blender/blenkernel/intern/anim.c trunk/blender/source/blender/blenkernel/intern/curve.c trunk/blender/source/blender/blenkernel/intern/key.c trunk/blender/source/blender/blenkernel/intern/lattice.c trunk/blender/source/blender/blenkernel/intern/object.c trunk/blender/source/blender/blenkernel/intern/particle.c trunk/blender/source/blender/blenkernel/intern/texture.c trunk/blender/source/blender/blenloader/intern/readfile.c trunk/blender/source/blender/render/intern/source/strand.c Modified: trunk/blender/source/blender/blenkernel/BKE_key.h =================================================================== --- trunk/blender/source/blender/blenkernel/BKE_key.h 2009-09-09 17:39:19 UTC (rev 23083) +++ trunk/blender/source/blender/blenkernel/BKE_key.h 2009-09-09 18:09:03 UTC (rev 23084) @@ -51,8 +51,9 @@ void make_local_key(struct Key *key); void sort_keys(struct Key *key); -void set_four_ipo(float d, float *data, int type); -void set_afgeleide_four_ipo(float d, float *data, int type); +void key_curve_position_weights(float t, float *data, int type); +void key_curve_tangent_weights(float t, float *data, int type); +void key_curve_normal_weights(float t, float *data, int type); /* only exported to curve.c! */ void cp_cu_key(struct Curve *cu, struct KeyBlock *kb, int start, int end); Modified: trunk/blender/source/blender/blenkernel/intern/anim.c =================================================================== --- trunk/blender/source/blender/blenkernel/intern/anim.c 2009-09-09 17:39:19 UTC (rev 23083) +++ trunk/blender/source/blender/blenkernel/intern/anim.c 2009-09-09 18:09:03 UTC (rev 23084) @@ -253,7 +253,7 @@ /* note, commented out for follow constraint */ //if(cu->flag & CU_FOLLOW) { - set_afgeleide_four_ipo(1.0f-fac, data, KEY_BSPLINE); + 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] ; @@ -268,10 +268,10 @@ nu= cu->nurb.first; /* make sure that first and last frame are included in the vectors here */ - if((nu->type & 7)==CU_POLY) set_four_ipo(1.0f-fac, data, KEY_LINEAR); - else if((nu->type & 7)==CU_BEZIER) set_four_ipo(1.0f-fac, data, KEY_LINEAR); - else if(s0==s1 || p2==p3) set_four_ipo(1.0f-fac, data, KEY_CARDINAL); - else set_four_ipo(1.0f-fac, data, KEY_BSPLINE); + if((nu->type & 7)==CU_POLY) key_curve_position_weights(1.0f-fac, data, KEY_LINEAR); + else if((nu->type & 7)==CU_BEZIER) key_curve_position_weights(1.0f-fac, data, KEY_LINEAR); + 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] ; Modified: trunk/blender/source/blender/blenkernel/intern/curve.c =================================================================== --- trunk/blender/source/blender/blenkernel/intern/curve.c 2009-09-09 17:39:19 UTC (rev 23083) +++ trunk/blender/source/blender/blenkernel/intern/curve.c 2009-09-09 18:09:03 UTC (rev 23084) @@ -1476,7 +1476,7 @@ if (nu->tilt_interp==3) { /* May as well support for tilt also 2.47 ease interp */ tilt_array[a] = prevbezt->alfa + (bezt->alfa - prevbezt->alfa)*(3.0f*fac*fac - 2.0f*fac*fac*fac); } else { - set_four_ipo(fac, t, nu->tilt_interp); + key_curve_position_weights(fac, t, nu->tilt_interp); tilt_array[a]= t[0]*pprev->alfa + t[1]*prevbezt->alfa + t[2]*bezt->alfa + t[3]*next->alfa; } } @@ -1491,7 +1491,7 @@ /* reuse interpolation from tilt if we can */ if (tilt_array==NULL || nu->tilt_interp != nu->radius_interp) { - set_four_ipo(fac, t, nu->radius_interp); + key_curve_position_weights(fac, t, nu->radius_interp); } radius_array[a]= t[0]*pprev->radius + t[1]*prevbezt->radius + t[2]*bezt->radius + t[3]*next->radius; } Modified: trunk/blender/source/blender/blenkernel/intern/key.c =================================================================== --- trunk/blender/source/blender/blenkernel/intern/key.c 2009-09-09 17:39:19 UTC (rev 23083) +++ trunk/blender/source/blender/blenkernel/intern/key.c 2009-09-09 18:09:03 UTC (rev 23084) @@ -258,67 +258,92 @@ /**************** do the key ****************/ +void key_curve_position_weights(float t, float *data, int type) +{ + float t2, t3, fc; + + if(type==KEY_LINEAR) { + data[0]= 0.0f; + data[1]= -t + 1.0f; + data[2]= t; + data[3]= 0.0f; + } + else if(type==KEY_CARDINAL) { + t2= t*t; + t3= t2*t; + fc= 0.71f; + + data[0]= -fc*t3 + 2.0f*fc*t2 - fc*t; + data[1]= (2.0f-fc)*t3 + (fc-3.0f)*t2 + 1.0f; + data[2]= (fc-2.0f)*t3 + (3.0f-2.0f*fc)*t2 + fc*t; + data[3]= fc*t3 - fc*t2; + } + else if(type==KEY_BSPLINE) { + t2= t*t; + t3= t2*t; -void set_four_ipo(float d, float *data, int type) + data[0]= -0.16666666f*t3 + 0.5f*t2 - 0.5f*t + 0.16666666f; + data[1]= 0.5f*t3 - t2 + 0.6666666f; + data[2]= -0.5f*t3 + 0.5f*t2 + 0.5f*t + 0.16666666f; + data[3]= 0.16666666f*t3; + } +} + +/* first derivative */ +void key_curve_tangent_weights(float t, float *data, int type) { - float d2, d3, fc; + float t2, fc; if(type==KEY_LINEAR) { data[0]= 0.0f; - data[1]= 1.0f-d; - data[2]= d; + data[1]= -1.0f; + data[2]= 1.0f; data[3]= 0.0f; } - else { - d2= d*d; - d3= d2*d; + else if(type==KEY_CARDINAL) { + t2= t*t; + fc= 0.71f; - if(type==KEY_CARDINAL) { + data[0]= -3.0f*fc*t2 +4.0f*fc*t - fc; + data[1]= 3.0f*(2.0f-fc)*t2 +2.0f*(fc-3.0f)*t; + data[2]= 3.0f*(fc-2.0f)*t2 +2.0f*(3.0f-2.0f*fc)*t + fc; + data[3]= 3.0f*fc*t2 -2.0f*fc*t; + } + else if(type==KEY_BSPLINE) { + t2= t*t; - fc= 0.71f; - - data[0]= -fc*d3 +2.0f*fc*d2 -fc*d; - data[1]= (2.0f-fc)*d3 +(fc-3.0f)*d2 +1.0f; - data[2]= (fc-2.0f)*d3 +(3.0f-2.0f*fc)*d2 +fc*d; - data[3]= fc*d3 -fc*d2; - } - else if(type==KEY_BSPLINE) { - - data[0]= -0.16666666f*d3 +0.5f*d2 -0.5f*d +0.16666666f; - data[1]= 0.5f*d3 -d2 +0.6666666f; - data[2]= -0.5f*d3 +0.5f*d2 +0.5f*d +0.16666666f; - data[3]= 0.16666666f*d3 ; - } + data[0]= -0.5f*t2 + t - 0.5f; + data[1]= 1.5f*t2 - 2.0f*t; + data[2]= -1.5f*t2 + t + 0.5f; + data[3]= 0.5f*t2; } } -void set_afgeleide_four_ipo(float d, float *data, int type) +/* second derivative */ +void key_curve_normal_weights(float t, float *data, int type) { - float d2, fc; + float fc; if(type==KEY_LINEAR) { - + data[0]= 0.0f; + data[1]= 0.0f; + data[2]= 0.0f; + data[3]= 0.0f; } - else { - d2= d*d; + else if(type==KEY_CARDINAL) { + fc= 0.71f; - if(type==KEY_CARDINAL) { - - fc= 0.71f; - - data[0]= -3.0f*fc*d2 +4.0f*fc*d -fc; - data[1]= 3.0f*(2.0f-fc)*d2 +2.0f*(fc-3.0f)*d; - data[2]= 3.0f*(fc-2.0f)*d2 +2.0f*(3.0f-2.0f*fc)*d +fc; - data[3]= 3.0f*fc*d2 -2.0f*fc*d; - } - else if(type==KEY_BSPLINE) { - - data[0]= -0.16666666f*3.0f*d2 +d -0.5f; - data[1]= 1.5f*d2 -2.0f*d; - data[2]= -1.5f*d2 +d +0.5f; - data[3]= 0.16666666f*3.0f*d2 ; - } + data[0]= -6.0f*fc*t + 4.0f*fc; + data[1]= 6.0f*(2.0f-fc)*t + 2.0f*(fc-3.0f); + data[2]= 6.0f*(fc-2.0f)*t + 2.0f*(3.0f-2.0f*fc); + data[3]= 6.0f*fc*t - 2.0f*fc; } + else if(type==KEY_BSPLINE) { + data[0]= -1.0f*t + 1.0f; + data[1]= 3.0f*t - 2.0f; + data[2]= -3.0f*t + 1.0f; + data[3]= 1.0f*t; + } } static int setkeys(float fac, ListBase *lb, KeyBlock *k[], float *t, int cycl) @@ -428,10 +453,10 @@ /* interpolation */ - set_four_ipo(d, t, k[1]->type); + key_curve_position_weights(d, t, k[1]->type); if(k[1]->type != k[2]->type) { - set_four_ipo(d, fval, k[2]->type); + key_curve_position_weights(d, fval, k[2]->type); temp= 1.0f-d; t[0]= temp*t[0]+ d*fval[0]; Modified: trunk/blender/source/blender/blenkernel/intern/lattice.c =================================================================== --- trunk/blender/source/blender/blenkernel/intern/lattice.c 2009-09-09 17:39:19 UTC (rev 23083) +++ trunk/blender/source/blender/blenkernel/intern/lattice.c 2009-09-09 18:09:03 UTC (rev 23084) @@ -367,7 +367,7 @@ u= (vec[0]-lt->fu)/lt->du; ui= (int)floor(u); u -= ui; - set_four_ipo(u, tu, lt->typeu); + key_curve_position_weights(u, tu, lt->typeu); } else { tu[0]= tu[2]= tu[3]= 0.0; tu[1]= 1.0; @@ -378,7 +378,7 @@ v= (vec[1]-lt->fv)/lt->dv; vi= (int)floor(v); v -= vi; - set_four_ipo(v, tv, lt->typev); + key_curve_position_weights(v, tv, lt->typev); } else { tv[0]= tv[2]= tv[3]= 0.0; tv[1]= 1.0; @@ -389,7 +389,7 @@ w= (vec[2]-lt->fw)/lt->dw; wi= (int)floor(w); w -= wi; - set_four_ipo(w, tw, lt->typew); + key_curve_position_weights(w, tw, lt->typew); } else { tw[0]= tw[2]= tw[3]= 0.0; tw[1]= 1.0; Modified: trunk/blender/source/blender/blenkernel/intern/object.c =================================================================== --- trunk/blender/source/blender/blenkernel/intern/object.c 2009-09-09 17:39:19 UTC (rev 23083) +++ trunk/blender/source/blender/blenkernel/intern/object.c 2009-09-09 18:09:03 UTC (rev 23084) @@ -2312,7 +2312,7 @@ if(ob->recalc & OB_RECALC_DATA) { - // printf("recalcdata %s\n", ob->id.name+2); + printf("recalc data %s\n", ob->id.name); /* includes all keys and modifiers */ if(ob->type==OB_MESH) { Modified: trunk/blender/source/blender/blenkernel/intern/particle.c =================================================================== --- trunk/blender/source/blender/blenkernel/intern/particle.c 2009-09-09 17:39:19 UTC (rev 23083) +++ trunk/blender/source/blender/blenkernel/intern/particle.c 2009-09-09 18:09:03 UTC (rev 23084) @@ -873,7 +873,7 @@ VecfCubicInterpol(keys[1].co, keys[1].vel, keys[2].co, keys[2].vel, dt, result->co, result->vel); } else { - set_four_ipo(dt, t, type); + key_curve_position_weights(dt, t, type); weighted_particle_vector(keys[0].co, keys[1].co, keys[2].co, keys[3].co, t, result->co); @@ -881,12 +881,12 @@ float temp[3]; if(dt>0.999f){ - set_four_ipo(dt-0.001f, t, type); + key_curve_position_weights(dt-0.001f, t, type); weighted_particle_vector(keys[0].co, keys[1].co, keys[2].co, keys[3].co, t, temp); VECSUB(result->vel, result->co, temp); } else{ - set_four_ipo(dt+0.001f, t, type); + key_curve_position_weights(dt+0.001f, t, type); weighted_particle_vector(keys[0].co, keys[1].co, keys[2].co, keys[3].co, t, temp); VECSUB(result->vel, temp, result->co); } Modified: trunk/blender/source/blender/blenkernel/intern/texture.c =================================================================== --- trunk/blender/source/blender/blenkernel/intern/texture.c 2009-09-09 17:39:19 UTC (rev 23083) +++ trunk/blender/source/blender/blenkernel/intern/texture.c 2009-09-09 18:09:03 UTC (rev 23084) @@ -368,9 +368,9 @@ CLAMP(fac, 0.0f, 1.0f); if(coba->ipotype==3) @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org http://lists.blender.org/mailman/listinfo/bf-blender-cvs