Blender  V2.59
BKE_collision.h
Go to the documentation of this file.
00001 /*
00002  * $Id: BKE_collision.h 36423 2011-05-02 03:44:02Z campbellbarton $
00003  *
00004  * ***** BEGIN GPL LICENSE BLOCK *****
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software Foundation,
00018  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019  *
00020  * The Original Code is Copyright (C) Blender Foundation.
00021  * All rights reserved.
00022  *
00023  * The Original Code is: all of this file.
00024  *
00025  * Contributor(s): Daniel Genrich
00026  *
00027  * ***** END GPL LICENSE BLOCK *****
00028  */
00029 #ifndef BKE_COLLISIONS_H
00030 #define BKE_COLLISIONS_H
00031 
00037 #include <math.h>
00038 #include <float.h>
00039 #include <stdlib.h>
00040 #include <string.h>
00041 
00042 /* types */
00043 #include "BKE_collision.h"
00044 #include "DNA_cloth_types.h"
00045 
00046 #include "BLI_kdopbvh.h"
00047 
00048 struct Cloth;
00049 struct ClothModifierData;
00050 struct CollisionModifierData;
00051 struct DerivedMesh;
00052 struct Group;
00053 struct MFace;
00054 struct MVert;
00055 struct Object;
00056 struct Scene;
00057 struct LinkNode;
00058 
00060 // used for collisions in collision.c
00062 
00063 /* COLLISION FLAGS */
00064 typedef enum
00065 {
00066         COLLISION_IN_FUTURE =           (1 << 1),
00067 #ifdef WITH_ELTOPO
00068         COLLISION_USE_COLLFACE =        (1 << 2),
00069         COLLISION_IS_EDGES =            (1 << 3),
00070 #endif
00071 } COLLISION_FLAGS;
00072 
00073 
00075 // used for collisions in collision.c
00077 /* used for collisions in collision.c */
00078 typedef struct CollPair
00079 {
00080         unsigned int face1; // cloth face
00081         unsigned int face2; // object face
00082         double distance; // magnitude of vector
00083         float normal[3];
00084         float vector[3]; // unnormalized collision vector: p2-p1
00085         float pa[3], pb[3]; // collision point p1 on face1, p2 on face2
00086         int flag;
00087         float time; // collision time, from 0 up to 1
00088 #ifdef WITH_ELTOPO /*either ap* or bp* can be set, but not both*/
00089         float bary[3];
00090         int ap1, ap2, ap3, collp, bp1, bp2, bp3;
00091         int collface;
00092 #else
00093         int ap1, ap2, ap3, bp1, bp2, bp3;
00094 #endif
00095         int pointsb[4];
00096 }
00097 CollPair;
00098 
00099 /* used for collisions in collision.c */
00100 typedef struct EdgeCollPair
00101 {
00102         unsigned int p11, p12, p21, p22;
00103         float normal[3];
00104         float vector[3];
00105         float time;
00106         int lastsign;
00107         float pa[3], pb[3]; // collision point p1 on face1, p2 on face2
00108 }
00109 EdgeCollPair;
00110 
00111 /* used for collisions in collision.c */
00112 typedef struct FaceCollPair
00113 {
00114         unsigned int p11, p12, p13, p21;
00115         float normal[3];
00116         float vector[3];
00117         float time;
00118         int lastsign;
00119         float pa[3], pb[3]; // collision point p1 on face1, p2 on face2
00120 }
00121 FaceCollPair;
00122 
00124 
00125 
00126 
00128 // forward declarations
00130 
00132 // used in modifier.c from collision.c
00134 
00135 BVHTree *bvhtree_build_from_mvert ( struct MFace *mfaces, unsigned int numfaces, struct MVert *x, unsigned int numverts, float epsilon );
00136 void bvhtree_update_from_mvert ( BVHTree * bvhtree, struct MFace *faces, int numfaces, struct MVert *x, struct MVert *xnew, int numverts, int moving );
00137 
00139 
00140 struct LinkNode *BLI_linklist_append_fast ( struct LinkNode **listp, void *ptr );
00141 
00142 // move Collision modifier object inter-frame with step = [0,1]
00143 // defined in collisions.c
00144 void collision_move_object ( struct CollisionModifierData *collmd, float step, float prevstep );
00145 
00146 // interface for collision functions
00147 void collisions_compute_barycentric ( float pv[3], float p1[3], float p2[3], float p3[3], float *w1, float *w2, float *w3 );
00148 void interpolateOnTriangle ( float to[3], float v1[3], float v2[3], float v3[3], double w1, double w2, double w3 );
00149 
00151 // used in effect.c
00153 struct Object **get_collisionobjects(struct Scene *scene, struct Object *self, struct Group *group, unsigned int *numcollobj);
00154 
00155 typedef struct ColliderCache {
00156         struct ColliderCache *next, *prev;
00157         struct Object *ob;
00158         struct CollisionModifierData *collmd;
00159 } ColliderCache;
00160 
00161 struct ListBase *get_collider_cache(struct Scene *scene, struct Object *self, struct Group *group);
00162 void free_collider_cache(struct ListBase **colliders);
00163 
00165 
00166 
00167 
00169 
00170 #endif
00171