Revision: 23338
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=23338
Author:   campbellbarton
Date:     2009-09-18 18:39:45 +0200 (Fri, 18 Sep 2009)

Log Message:
-----------
Move some static math functions out of paint_image.c into arithb.c
* VecLerp3f and Vec2Lerp3f - interpolate 3 2d/3d vectors from 3 weights
* AngleToLength(angle) - useful for making even width shell/walls based on the 
angles of the surrounding geometry from each point. (same method used in 2.4x 
python solidify script).

also quiet some warnings.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/intern/particle.c
    trunk/blender/source/blender/blenkernel/intern/particle_system.c
    trunk/blender/source/blender/blenlib/BLI_arithb.h
    trunk/blender/source/blender/blenlib/intern/arithb.c
    trunk/blender/source/blender/editors/sculpt_paint/paint_image.c
    trunk/blender/source/blender/makesrna/intern/rna_particle.c
    trunk/blender/source/blender/render/intern/source/convertblender.c

Modified: trunk/blender/source/blender/blenkernel/intern/particle.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/particle.c   2009-09-18 
15:52:28 UTC (rev 23337)
+++ trunk/blender/source/blender/blenkernel/intern/particle.c   2009-09-18 
16:39:45 UTC (rev 23338)
@@ -2193,7 +2193,7 @@
 static int psys_threads_init_path(ParticleThread *threads, Scene *scene, float 
cfra, int editupdate)
 {
        ParticleThreadContext *ctx= threads[0].ctx;
-       Object *ob= ctx->sim.ob;
+/*     Object *ob= ctx->sim.ob; */
        ParticleSystem *psys= ctx->sim.psys;
        ParticleSettings *part = psys->part;
        ParticleEditSettings *pset = &scene->toolsettings->particle;
@@ -3868,7 +3868,7 @@
        ParticleData *pa = NULL;
        ChildParticle *cpa = NULL;
        float cfra;
-       int totpart = psys->totpart, between = 0;
+       int totpart = psys->totpart;
 
        /* negative time means "use current time" */
        cfra = state->time > 0 ? state->time : bsystem_time(sim->scene, 0, 
(float)sim->scene->r.cfra, 0.0);

Modified: trunk/blender/source/blender/blenkernel/intern/particle_system.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/particle_system.c    
2009-09-18 15:52:28 UTC (rev 23337)
+++ trunk/blender/source/blender/blenkernel/intern/particle_system.c    
2009-09-18 16:39:45 UTC (rev 23338)
@@ -614,7 +614,7 @@
        Object *ob= ctx->sim.ob;
        DerivedMesh *dm= ctx->dm;
        ParticleData *tpa;
-       ParticleSettings *part= ctx->sim.psys->part;
+/*     ParticleSettings *part= ctx->sim.psys->part; */
        float *v1, *v2, *v3, *v4, nor[3], orco1[3], co1[3], co2[3], nor1[3], 
ornor1[3];
        float cur_d, min_d, randu, randv;
        int from= ctx->from;
@@ -2451,7 +2451,7 @@
 }
 
 /* precalcs effectors and returns 1 if there were any collision object 
-/* so collision checks can be avoided as quickly as possible */
+ * so collision checks can be avoided as quickly as possible */
 static int precalc_effectors(ParticleSimulationData *sim, float cfra)
 {
        ParticleSystem *psys = sim->psys;
@@ -3561,7 +3561,7 @@
 static void hair_step(ParticleSimulationData *sim, float cfra)
 {
        ParticleSystem *psys = sim->psys;
-       ParticleSettings *part = psys->part;
+/*     ParticleSettings *part = psys->part; */
        PARTICLE_P;
        float disp = (float)get_current_display_percentage(psys)/100.0f;
 
@@ -3649,7 +3649,7 @@
        ParticleSettings *part=psys->part;
        KDTree *tree=0;
        IpoCurve *icu_esize= NULL; //=find_ipocurve(part->ipo,PART_EMIT_SIZE); 
// XXX old animation system
-       Material *ma=give_current_material(sim->ob, part->omat);
+/*     Material *ma=give_current_material(sim->ob, part->omat); */
        BoidBrainData bbd;
        PARTICLE_P;
        float timestep;
@@ -3851,7 +3851,7 @@
        ParticleSystem *psys = sim->psys;
        ParticleSettings *part = psys->part;
        IpoCurve *icu_esize = NULL; //=find_ipocurve(part->ipo,PART_EMIT_SIZE); 
// XXX old animation system
-       Material *ma = give_current_material(sim->ob,part->omat);
+/*     Material *ma = give_current_material(sim->ob,part->omat); */
        PARTICLE_P;
        float disp, birthtime, dietime, *vg_size= NULL; // XXX ipotime=cfra
 

Modified: trunk/blender/source/blender/blenlib/BLI_arithb.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_arithb.h   2009-09-18 15:52:28 UTC 
(rev 23337)
+++ trunk/blender/source/blender/blenlib/BLI_arithb.h   2009-09-18 16:39:45 UTC 
(rev 23338)
@@ -364,7 +364,8 @@
 void VecAddf(float *v, float *v1, float *v2);
 void VecSubf(float *v, float *v1, float *v2);
 void VecMulVecf(float *v, float *v1, float *v2);
-void VecLerpf(float *target, float *a, float *b, float t);
+void VecLerpf(float *target, const float *a, const float *b, const float t);
+void VecLerp3f(float p[3], const float v1[3], const float v2[3], const float 
v3[3], const float w[3]);
 void VecMidf(float *v, float *v1, float *v2);
 
 void VecOrthoBasisf(float *v, float *v1, float *v2);
@@ -375,7 +376,8 @@
 void Vec2Addf(float *v, float *v1, float *v2);
 void Vec2Subf(float *v, float *v1, float *v2);
 void Vec2Copyf(float *v1, float *v2);
-void Vec2Lerpf(float *target, float *a, float *b, float t);
+void Vec2Lerpf(float *target, const float *a, const float *b, const float t);
+void Vec2Lerp3f(float p[2], const float v1[2], const float v2[2], const float 
v3[2], const float w[3]);
 
 void AxisAngleToQuat(float q[4], float axis[3], float angle);
 void QuatToAxisAngle(float q[4], float axis[3], float *angle);
@@ -527,6 +529,8 @@
 
 float lambda_cp_line_ex(float p[3], float l1[3], float l2[3], float cp[3]);
 
+float AngleToLength(const float angle);
+
 typedef struct DualQuat {
        float quat[4];
        float trans[4];

Modified: trunk/blender/source/blender/blenlib/intern/arithb.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/arithb.c        2009-09-18 
15:52:28 UTC (rev 23337)
+++ trunk/blender/source/blender/blenlib/intern/arithb.c        2009-09-18 
16:39:45 UTC (rev 23338)
@@ -2187,23 +2187,40 @@
        v[2] = v1[2] * v2[2];
 }
 
-void VecLerpf(float *target, float *a, float *b, float t)
+void VecLerpf(float *target, const float *a, const float *b, const float t)
 {
-       float s = 1.0f-t;
+       const float s = 1.0f-t;
 
        target[0]= s*a[0] + t*b[0];
        target[1]= s*a[1] + t*b[1];
        target[2]= s*a[2] + t*b[2];
 }
 
-void Vec2Lerpf(float *target, float *a, float *b, float t)
+void Vec2Lerpf(float *target, const float *a, const float *b, const float t)
 {
-       float s = 1.0f-t;
+       const float s = 1.0f-t;
 
        target[0]= s*a[0] + t*b[0];
        target[1]= s*a[1] + t*b[1];
 }
 
+/* weight 3 vectors, (VecWeightf in 2.4x)
+ * 'w' must be unit length but is not a vector, just 3 weights */
+void VecLerp3f(float p[3], const float v1[3], const float v2[3], const float 
v3[3], const float w[3])
+{
+       p[0] = v1[0]*w[0] + v2[0]*w[1] + v3[0]*w[2];
+       p[1] = v1[1]*w[0] + v2[1]*w[1] + v3[1]*w[2];
+       p[2] = v1[2]*w[0] + v2[2]*w[1] + v3[2]*w[2];
+}
+
+/* weight 3 2D vectors, (Vec2Weightf in 2.4x)
+ * 'w' must be unit length but is not a vector, just 3 weights */
+void Vec2Lerp3f(float p[2], const float v1[2], const float v2[2], const float 
v3[2], const float w[3])
+{
+       p[0] = v1[0]*w[0] + v2[0]*w[1] + v3[0]*w[2];
+       p[1] = v1[1]*w[0] + v2[1]*w[1] + v3[1]*w[2];
+}
+
 void VecMidf(float *v, float *v1, float *v2)
 {
        v[0]= 0.5f*(v1[0]+ v2[0]);
@@ -4823,6 +4840,15 @@
 }
 #endif
 
+/* useful to calculate an even width shell, by taking the angle between 2 
planes.
+ * The return value is a scale on the offset.
+ * no angle between planes is 1.0, as the angle between the 2 planes approches 
180d
+ * the distance gets very hight, 180d would be inf, but this case isnt valid */
+float AngleToLength(const float angle)
+{
+       return (angle < SMALL_NUMBER) ? 1.0f : fabsf(1.0f / cosf(angle * 
(M_PI/180.0f)));
+}
+
 /* Similar to LineIntersectsTriangleUV, except it operates on a quad and in 
2d, assumes point is in quad */
 void PointInQuad2DUV(float v0[2], float v1[2], float v2[2], float v3[2], float 
pt[2], float *uv)
 {

Modified: trunk/blender/source/blender/editors/sculpt_paint/paint_image.c
===================================================================
--- trunk/blender/source/blender/editors/sculpt_paint/paint_image.c     
2009-09-18 15:52:28 UTC (rev 23337)
+++ trunk/blender/source/blender/editors/sculpt_paint/paint_image.c     
2009-09-18 16:39:45 UTC (rev 23338)
@@ -625,19 +625,6 @@
        w[0] = w[1] = w[2] = 1.0f/3.0f;
 }
 
-static void VecWeightf(float p[3], const float v1[3], const float v2[3], const 
float v3[3], const float w[3])
-{
-       p[0] = v1[0]*w[0] + v2[0]*w[1] + v3[0]*w[2];
-       p[1] = v1[1]*w[0] + v2[1]*w[1] + v3[1]*w[2];
-       p[2] = v1[2]*w[0] + v2[2]*w[1] + v3[2]*w[2];
-}
-
-static void Vec2Weightf(float p[2], const float v1[2], const float v2[2], 
const float v3[2], const float w[3])
-{
-       p[0] = v1[0]*w[0] + v2[0]*w[1] + v3[0]*w[2];
-       p[1] = v1[1]*w[0] + v2[1]*w[1] + v3[1]*w[2];
-}
-
 static float VecZDepthOrtho(float pt[2], float v1[3], float v2[3], float 
v3[3], float w[3])
 {
        BarycentricWeights2f(pt, v1, v2, v3, w);
@@ -746,10 +733,10 @@
        tf = ps->dm_mtface + face_index;
        
        if (side == 0) {
-               Vec2Weightf(uv, tf->uv[0], tf->uv[1], tf->uv[2], w);
+               Vec2Lerp3f(uv, tf->uv[0], tf->uv[1], tf->uv[2], w);
        }
        else { /* QUAD */
-               Vec2Weightf(uv, tf->uv[0], tf->uv[2], tf->uv[3], w);
+               Vec2Lerp3f(uv, tf->uv[0], tf->uv[2], tf->uv[3], w);
        }
        
        ibuf = tf->tpage->ibufs.first; /* we must have got the imbuf before 
getting here */
@@ -870,8 +857,8 @@
        }
 
        /* Test if we're in the clipped area, */
-       if (side)       VecWeightf(wco, ps->dm_mvert[mf->v1].co, 
ps->dm_mvert[mf->v3].co, ps->dm_mvert[mf->v4].co, w);
-       else            VecWeightf(wco, ps->dm_mvert[mf->v1].co, 
ps->dm_mvert[mf->v2].co, ps->dm_mvert[mf->v3].co, w);
+       if (side)       VecLerp3f(wco, ps->dm_mvert[mf->v1].co, 
ps->dm_mvert[mf->v3].co, ps->dm_mvert[mf->v4].co, w);
+       else            VecLerp3f(wco, ps->dm_mvert[mf->v1].co, 
ps->dm_mvert[mf->v2].co, ps->dm_mvert[mf->v3].co, w);
        
        Mat4MulVecfl(ps->ob->obmat, wco);
        if(!view3d_test_clipping(ps->rv3d, wco)) {
@@ -1146,19 +1133,6 @@
        return 1;
 }
 
-/* TODO - move to arithb.c */
-/* Converts an angle to a length that can be used for maintaining an even 
margin around UV's */
-static float angleToLength(float angle)
-{
-       // already accounted for
-       if (angle < 0.000001f) {
-               return 1.0f;
-       }
-       else {
-               return fabsf(1.0f / cosf(angle * (M_PI/180.0f)));
-       }
-}
-
 /* Calculate outset UV's, this is not the same as simply scaling the UVs,
  * since the outset coords are a margin that keep an even distance from the 
original UV's,
  * note that the image aspect is taken into account */
@@ -1204,15 +1178,15 @@
        }
        
        if (is_quad) {
-               a1 = angleToLength(NormalizedVecAngle2_2D(dir4, dir1));
-               a2 = angleToLength(NormalizedVecAngle2_2D(dir1, dir2));
-               a3 = angleToLength(NormalizedVecAngle2_2D(dir2, dir3));
-               a4 = angleToLength(NormalizedVecAngle2_2D(dir3, dir4));
+               a1 = AngleToLength(NormalizedVecAngle2_2D(dir4, dir1));
+               a2 = AngleToLength(NormalizedVecAngle2_2D(dir1, dir2));
+               a3 = AngleToLength(NormalizedVecAngle2_2D(dir2, dir3));
+               a4 = AngleToLength(NormalizedVecAngle2_2D(dir3, dir4));
        }
        else {
-               a1 = angleToLength(NormalizedVecAngle2_2D(dir3, dir1));
-               a2 = angleToLength(NormalizedVecAngle2_2D(dir1, dir2));
-               a3 = angleToLength(NormalizedVecAngle2_2D(dir2, dir3));
+               a1 = AngleToLength(NormalizedVecAngle2_2D(dir3, dir1));
+               a2 = AngleToLength(NormalizedVecAngle2_2D(dir1, dir2));
+               a3 = AngleToLength(NormalizedVecAngle2_2D(dir2, dir3));
        }
        

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to