Blender  V3.3
BKE_collision.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright Blender Foundation. All rights reserved. */
3 #pragma once
4 
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12 
13 struct BVHTree;
14 struct Collection;
16 struct Depsgraph;
17 struct MVert;
18 struct MVertTri;
19 struct Object;
20 
22 // used for collisions in collision.c
24 
25 /* COLLISION FLAGS */
26 typedef enum {
27  COLLISION_IN_FUTURE = (1 << 1),
28 #ifdef WITH_ELTOPO
29  COLLISION_USE_COLLFACE = (1 << 2),
30  COLLISION_IS_EDGES = (1 << 3),
31 #endif
32  COLLISION_INACTIVE = (1 << 4),
34 
36 // used for collisions in collision.c
38 /* used for collisions in collision.c */
39 typedef struct CollPair {
40  unsigned int face1; /* cloth face */
41  unsigned int face2; /* object face */
42  float distance;
43  float normal[3];
44  float vector[3]; /* unnormalized collision vector: p2-p1 */
45  float pa[3], pb[3]; /* collision point p1 on face1, p2 on face2 */
46  int flag;
47  float time; /* collision time, from 0 up to 1 */
48 
49  /* mesh-mesh collision */
50 #ifdef WITH_ELTOPO /* Either ap* or bp* can be set, but not both. */
51  float bary[3];
52  int ap1, ap2, ap3, collp, bp1, bp2, bp3;
53  int collface;
54 #else
55  int ap1, ap2, ap3, bp1, bp2, bp3;
56 #endif
57  int pointsb[4];
59 
60 /* used for collisions in collision.c */
61 typedef struct EdgeCollPair {
62  unsigned int p11, p12, p21, p22;
63  float normal[3];
64  float vector[3];
65  float time;
66  int lastsign;
67  float pa[3], pb[3]; /* collision point p1 on face1, p2 on face2 */
69 
70 /* used for collisions in collision.c */
71 typedef struct FaceCollPair {
72  unsigned int p11, p12, p13, p21;
73  float normal[3];
74  float vector[3];
75  float time;
76  int lastsign;
77  float pa[3], pb[3]; /* collision point p1 on face1, p2 on face2 */
79 
81 
83 // forward declarations
85 
87 // used in modifier.c from collision.c
89 
90 struct BVHTree *bvhtree_build_from_mvert(const struct MVert *mvert,
91  const struct MVertTri *tri,
92  int tri_num,
93  float epsilon);
94 void bvhtree_update_from_mvert(struct BVHTree *bvhtree,
95  const struct MVert *mvert,
96  const struct MVert *mvert_moving,
97  const struct MVertTri *tri,
98  int tri_num,
99  bool moving);
100 
102 
108 void collision_move_object(struct CollisionModifierData *collmd,
109  float step,
110  float prevstep,
111  bool moving_bvh);
112 
113 void collision_get_collider_velocity(float vel_old[3],
114  float vel_new[3],
115  struct CollisionModifierData *collmd,
116  struct CollPair *collpair);
117 
118 /* Collision relations for dependency graph build. */
119 
120 typedef struct CollisionRelation {
122  struct Object *ob;
124 
131  struct Collection *collection,
132  unsigned int modifier_type);
133 void BKE_collision_relations_free(struct ListBase *relations);
134 
135 /* Collision object lists for physics simulation evaluation. */
136 
142  struct Object *self,
143  struct Collection *collection,
144  unsigned int *numcollobj,
145  unsigned int modifier_type);
146 void BKE_collision_objects_free(struct Object **objects);
147 
148 typedef struct ColliderCache {
150  struct Object *ob;
153 
159  struct Object *self,
160  struct Collection *collection);
161 void BKE_collider_cache_free(struct ListBase **colliders);
162 
164 
166 
167 #ifdef __cplusplus
168 }
169 #endif
COLLISION_FLAGS
Definition: BKE_collision.h:26
@ COLLISION_INACTIVE
Definition: BKE_collision.h:32
@ COLLISION_IN_FUTURE
Definition: BKE_collision.h:27
struct ListBase * BKE_collision_relations_create(struct Depsgraph *depsgraph, struct Collection *collection, unsigned int modifier_type)
Definition: collision.c:1247
struct EdgeCollPair EdgeCollPair
void BKE_collider_cache_free(struct ListBase **colliders)
Definition: collision.c:1359
struct Object ** BKE_collision_objects_create(struct Depsgraph *depsgraph, struct Object *self, struct Collection *collection, unsigned int *numcollobj, unsigned int modifier_type)
Definition: collision.c:1275
struct BVHTree * bvhtree_build_from_mvert(const struct MVert *mvert, const struct MVertTri *tri, int tri_num, float epsilon)
void BKE_collision_relations_free(struct ListBase *relations)
Definition: collision.c:1267
void bvhtree_update_from_mvert(struct BVHTree *bvhtree, const struct MVert *mvert, const struct MVert *mvert_moving, const struct MVertTri *tri, int tri_num, bool moving)
struct CollisionRelation CollisionRelation
void collision_get_collider_velocity(float vel_old[3], float vel_new[3], struct CollisionModifierData *collmd, struct CollPair *collpair)
Definition: collision.c:1716
void BKE_collision_objects_free(struct Object **objects)
Definition: collision.c:1315
struct ListBase * BKE_collider_cache_create(struct Depsgraph *depsgraph, struct Object *self, struct Collection *collection)
Definition: collision.c:1322
void collision_move_object(struct CollisionModifierData *collmd, float step, float prevstep, bool moving_bvh)
Definition: collision.c:65
struct CollPair CollPair
struct ColliderCache ColliderCache
struct FaceCollPair FaceCollPair
struct Depsgraph Depsgraph
Definition: DEG_depsgraph.h:35
const Depsgraph * depsgraph
static double epsilon
float distance
Definition: BKE_collision.h:42
float pa[3]
Definition: BKE_collision.h:45
unsigned int face1
Definition: BKE_collision.h:40
float pb[3]
Definition: BKE_collision.h:45
float time
Definition: BKE_collision.h:47
float normal[3]
Definition: BKE_collision.h:43
unsigned int face2
Definition: BKE_collision.h:41
int pointsb[4]
Definition: BKE_collision.h:57
struct ColliderCache * prev
struct Object * ob
struct CollisionModifierData * collmd
struct ColliderCache * next
struct CollisionRelation * next
struct CollisionRelation * prev
struct Object * ob
float pb[3]
Definition: BKE_collision.h:67
float pa[3]
Definition: BKE_collision.h:67
unsigned int p22
Definition: BKE_collision.h:62
unsigned int p11
Definition: BKE_collision.h:62
unsigned int p12
Definition: BKE_collision.h:62
float normal[3]
Definition: BKE_collision.h:63
unsigned int p21
Definition: BKE_collision.h:62
float normal[3]
Definition: BKE_collision.h:73
float pa[3]
Definition: BKE_collision.h:77
unsigned int p13
Definition: BKE_collision.h:72
float pb[3]
Definition: BKE_collision.h:77
unsigned int p12
Definition: BKE_collision.h:72
unsigned int p21
Definition: BKE_collision.h:72
unsigned int p11
Definition: BKE_collision.h:72