diff options
author | Janne Karhu <jhkarh@gmail.com> | 2011-03-18 18:31:32 +0300 |
---|---|---|
committer | Janne Karhu <jhkarh@gmail.com> | 2011-03-18 18:31:32 +0300 |
commit | 60ce95f5622d3947e30fe960eda22ea305660619 (patch) | |
tree | 20a322ff834993f9794ebb5c110437da41273812 /source/blender/modifiers/intern/MOD_collision.c | |
parent | 7e53769d09863b59beae4155ea0ad13c6ab2fac2 (diff) |
New particle collisions code:
* The old collisions code detected particle collisions by calculating the
collision times analytically from the collision mesh faces. This was
pretty accurate, but didn't support rotating/deforming faces at all, as
the equations for these quickly become quite nasty.
* The new code uses a simple "distance to plane/edge/vert" function and
iterates this with the Newton-Rhapson method to find the closest particle
distance during a simulation step.
* The advantage in this is that the collision object can now move, rotate,
scale or even deform freely and collisions are still detected reliably.
* For some extreme movements the calculation errors could stack up so much
that the detection fails, but this can be easily fixed by increasing the
particle size or simulation substeps.
* As a side note the algorithm doesn't really do point particles anymore,
but uses a very small radius as the particle size when "size deflect" isn't
selected.
* I've also updated the collision response code a bit, so now the particles
shouldn't leak even from tight corners.
All in all the collisions code is now much cleaner and more robust than before!
Diffstat (limited to 'source/blender/modifiers/intern/MOD_collision.c')
-rw-r--r-- | source/blender/modifiers/intern/MOD_collision.c | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/source/blender/modifiers/intern/MOD_collision.c b/source/blender/modifiers/intern/MOD_collision.c index 2ed66f2374b..83ba8a12163 100644 --- a/source/blender/modifiers/intern/MOD_collision.c +++ b/source/blender/modifiers/intern/MOD_collision.c @@ -64,7 +64,7 @@ static void initData(ModifierData *md) collmd->current_x = NULL; collmd->current_xnew = NULL; collmd->current_v = NULL; - collmd->time = -1000; + collmd->time_x = collmd->time_xnew = -1000; collmd->numverts = 0; collmd->bvhtree = NULL; } @@ -95,7 +95,7 @@ static void freeData(ModifierData *md) collmd->current_x = NULL; collmd->current_xnew = NULL; collmd->current_v = NULL; - collmd->time = -1000; + collmd->time_x = collmd->time_xnew = -1000; collmd->numverts = 0; collmd->bvhtree = NULL; collmd->mfaces = NULL; @@ -139,11 +139,11 @@ static void deformVerts(ModifierData *md, Object *ob, current_time = BKE_curframe(md->scene); if(G.rt > 0) - printf("current_time %f, collmd->time %f\n", current_time, collmd->time); + printf("current_time %f, collmd->time_xnew %f\n", current_time, collmd->time_xnew); numverts = dm->getNumVerts ( dm ); - if((current_time > collmd->time)|| (BKE_ptcache_get_continue_physics())) + if((current_time > collmd->time_xnew)|| (BKE_ptcache_get_continue_physics())) { unsigned int i; @@ -151,7 +151,7 @@ static void deformVerts(ModifierData *md, Object *ob, if(collmd->x && (numverts != collmd->numverts)) freeData((ModifierData *)collmd); - if(collmd->time == -1000) // first time + if(collmd->time_xnew == -1000) // first time { collmd->x = dm->dupVertArray(dm); // frame start position @@ -174,7 +174,7 @@ static void deformVerts(ModifierData *md, Object *ob, // create bounding box hierarchy collmd->bvhtree = bvhtree_build_from_mvert(collmd->mfaces, collmd->numfaces, collmd->x, numverts, ob->pd->pdef_sboft); - collmd->time = current_time; + collmd->time_x = collmd->time_xnew = current_time; } else if(numverts == collmd->numverts) { @@ -182,6 +182,7 @@ static void deformVerts(ModifierData *md, Object *ob, tempVert = collmd->x; collmd->x = collmd->xnew; collmd->xnew = tempVert; + collmd->time_x = collmd->time_xnew; memcpy(collmd->xnew, dm->getVertArray(dm), numverts*sizeof(MVert)); @@ -216,7 +217,7 @@ static void deformVerts(ModifierData *md, Object *ob, bvhtree_update_from_mvert ( collmd->bvhtree, collmd->mfaces, collmd->numfaces, collmd->current_x, collmd->current_xnew, collmd->numverts, 1 ); } - collmd->time = current_time; + collmd->time_xnew = current_time; } else if(numverts != collmd->numverts) { @@ -224,7 +225,7 @@ static void deformVerts(ModifierData *md, Object *ob, } } - else if(current_time < collmd->time) + else if(current_time < collmd->time_xnew) { freeData((ModifierData *)collmd); } |