[Bf-blender-cvs] [a307027] strand_nodes: Add a cache structure for collision contact points.

Lukas Tönne noreply at git.blender.org
Sun Aug 7 10:39:40 CEST 2016


Commit: a3070275658e3c86062ca24d7da24dd1b81538d6
Author: Lukas Tönne
Date:   Thu Jul 28 12:57:54 2016 +0200
Branches: strand_nodes
https://developer.blender.org/rBa3070275658e3c86062ca24d7da24dd1b81538d6

Add a cache structure for collision contact points.

This should serve as a universal interface between possible collision
detection systems (BVH, Bullet) and the various collision response systems.
Using an new data structure means that the two sides of a collision
handling feature (detection and response) can be treated independently,
reducing code dependencies and complexity.

The properties of contact points are modeled after btManifoldPoint from
Bullet and may need to be adjusted in the future.

===================================================================

M	source/blender/blenkernel/BKE_collision.h
M	source/blender/blenkernel/intern/collision.c

===================================================================

diff --git a/source/blender/blenkernel/BKE_collision.h b/source/blender/blenkernel/BKE_collision.h
index d5b4a58..6fe4cd6 100644
--- a/source/blender/blenkernel/BKE_collision.h
+++ b/source/blender/blenkernel/BKE_collision.h
@@ -160,8 +160,30 @@ void free_collider_cache(struct ListBase **colliders);
 /////////////////////////////////////////////////
 
 
-
-/////////////////////////////////////////////////
+typedef struct CollisionContactPoint {
+	float point_world_a[3];
+	float point_world_b[3];
+	float normal_world_b[3];
+	float distance;
+	float friction, rolling_friction, restitution;
+	int part_id_a, part_id_b;
+	int index_a, index_b;
+	int lifetime;
+} CollisionContactPoint;
+
+typedef struct CollisionContactCache {
+	struct BLI_mempool *points;
+} CollisionContactCache;
+
+struct CollisionContactCache *BKE_collision_cache_create(void);
+void BKE_collision_cache_free(struct CollisionContactCache *cache);
+
+CollisionContactPoint *BKE_collision_cache_add(struct CollisionContactCache *cache,
+                                               int index_a, int index_b,
+                                               int part_id_a, int part_id_b);
+
+#define BKE_COLLISION_ITER_CONTACTS(point, iter, cache) \
+	for (BLI_mempool_iternew(cache->points, iter); (point = BLI_mempool_iterstep(iter)); )
 
 #endif
 
diff --git a/source/blender/blenkernel/intern/collision.c b/source/blender/blenkernel/intern/collision.c
index 8cac856..bdb69a0 100644
--- a/source/blender/blenkernel/intern/collision.c
+++ b/source/blender/blenkernel/intern/collision.c
@@ -43,6 +43,7 @@
 #include "BLI_utildefines.h"
 #include "BLI_blenlib.h"
 #include "BLI_math.h"
+#include "BLI_mempool.h"
 #include "BLI_edgehash.h"
 
 #include "BKE_cloth.h"
@@ -1433,3 +1434,33 @@ void cloth_free_contacts(ColliderContacts *collider_contacts, int totcolliders)
 		MEM_freeN(collider_contacts);
 	}
 }
+
+/////////////////////////////////////////////////
+
+
+CollisionContactCache *BKE_collision_cache_create(void)
+{
+	CollisionContactCache *cache = MEM_callocN(sizeof(CollisionContactCache), "CollisionContactCache");
+	cache->points = BLI_mempool_create(sizeof(CollisionContactPoint), 0, 512, BLI_MEMPOOL_ALLOW_ITER);
+	return cache;
+}
+
+void BKE_collision_cache_free(CollisionContactCache *cache)
+{
+	if (cache) {
+		BLI_mempool_destroy(cache->points);
+		MEM_freeN(cache);
+	}
+}
+
+CollisionContactPoint *BKE_collision_cache_add(CollisionContactCache *cache,
+                                               int index_a, int index_b,
+                                               int part_id_a, int part_id_b)
+{
+	CollisionContactPoint *pt = BLI_mempool_calloc(cache->points);
+	pt->index_a = index_a;
+	pt->index_b = index_b;
+	pt->part_id_a = part_id_a;
+	pt->part_id_b = part_id_b;
+	return pt;
+}




More information about the Bf-blender-cvs mailing list