6 * ***** BEGIN GPL LICENSE BLOCK *****
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 * The Original Code is Copyright (C) Blender Foundation.
23 * All rights reserved.
25 * The Original Code is: all of this file.
27 * Contributor(s): Daniel Genrich
29 * ***** END GPL LICENSE BLOCK *****
31 #ifndef BKE_COLLISIONS_H
32 #define BKE_COLLISIONS_H
40 #include "BKE_collision.h"
41 #include "DNA_cloth_types.h"
43 #include "BLI_kdopbvh.h"
46 struct ClothModifierData;
47 struct CollisionModifierData;
56 ////////////////////////////////////////
57 // used for collisions in collision.c
58 ////////////////////////////////////////
63 COLLISION_IN_FUTURE = ( 1 << 1 ),
67 ////////////////////////////////////////
68 // used for collisions in collision.c
69 ////////////////////////////////////////
70 /* used for collisions in collision.c */
71 typedef struct CollPair
73 unsigned int face1; // cloth face
74 unsigned int face2; // object face
75 double distance; // magnitude of vector
77 float vector[3]; // unnormalized collision vector: p2-p1
78 float pa[3], pb[3]; // collision point p1 on face1, p2 on face2
80 float time; // collision time, from 0 up to 1
81 int ap1, ap2, ap3, bp1, bp2, bp3;
86 /* used for collisions in collision.c */
87 typedef struct EdgeCollPair
89 unsigned int p11, p12, p21, p22;
94 float pa[3], pb[3]; // collision point p1 on face1, p2 on face2
98 /* used for collisions in collision.c */
99 typedef struct FaceCollPair
101 unsigned int p11, p12, p13, p21;
106 float pa[3], pb[3]; // collision point p1 on face1, p2 on face2
109 ////////////////////////////////////////
113 /////////////////////////////////////////////////
114 // forward declarations
115 /////////////////////////////////////////////////
117 /////////////////////////////////////////////////
118 // used in modifier.c from collision.c
119 /////////////////////////////////////////////////
121 BVHTree *bvhtree_build_from_mvert ( struct MFace *mfaces, unsigned int numfaces, struct MVert *x, unsigned int numverts, float epsilon );
122 void bvhtree_update_from_mvert ( BVHTree * bvhtree, struct MFace *faces, int numfaces, struct MVert *x, struct MVert *xnew, int numverts, int moving );
124 /////////////////////////////////////////////////
126 struct LinkNode *BLI_linklist_append_fast ( struct LinkNode **listp, void *ptr );
128 // move Collision modifier object inter-frame with step = [0,1]
129 // defined in collisions.c
130 void collision_move_object ( struct CollisionModifierData *collmd, float step, float prevstep );
132 // interface for collision functions
133 void collisions_compute_barycentric ( float pv[3], float p1[3], float p2[3], float p3[3], float *w1, float *w2, float *w3 );
134 void interpolateOnTriangle ( float to[3], float v1[3], float v2[3], float v3[3], double w1, double w2, double w3 );
136 /////////////////////////////////////////////////
138 /////////////////////////////////////////////////
139 struct Object **get_collisionobjects(struct Scene *scene, struct Object *self, struct Group *group, int *numcollobj);
141 typedef struct ColliderCache {
142 struct ColliderCache *next, *prev;
144 struct CollisionModifierData *collmd;
147 struct ListBase *get_collider_cache(struct Scene *scene, struct Object *self, struct Group *group);
148 void free_collider_cache(struct ListBase **colliders);
150 /////////////////////////////////////////////////
154 /////////////////////////////////////////////////