My Project: openb3dlib.mod/openb3d/src/collision.h Source File

My Project

collision.h
Go to the documentation of this file.
1 #ifndef COLLISION_H
2 #define COLLISION_H
3
4 #include "tree.h"
5 #include "geom.h"
6
7 #include <set>
8 #include <map>
9 #include <vector>
10
11 using namespace std;
12
13 class MeshCollider;
14
15 const float COLLISION_EPSILON=.001f;
16
17 //collision methods
18 enum{
19 COLLISION_METHOD_SPHERE=1,
20 COLLISION_METHOD_POLYGON=2,
21 COLLISION_METHOD_BOX=3
22 };
23
24 //collision actions
25 enum{
26 COLLISION_RESPONSE_NONE=0,
27 COLLISION_RESPONSE_STOP=1,
28 COLLISION_RESPONSE_SLIDE=2,
29 COLLISION_RESPONSE_SLIDEXZ=3,
30 };
31
32 struct Collision{
33
34 float time;
35 Vector normal;
36 int surface;
37 int index;
38
39 Collision():time(1){
40 }
41
42 //Collision():time(1),surface(0),index(~0){}
43
44 bool update ( const Line &line,float time,const Vector &normal );
45 bool sphereCollide ( const Line &src_line,float src_radius,const Vector &dest,float dest_radius );
46 bool sphereCollide ( const Line &line ,float radius ,const Vector &dest,const Vector &radii );
47 bool triangleCollide( const Line &src_line,float src_radius,const Vector &v0,const Vector &v1,const Vector &v2 );
48 bool boxCollide ( const Line &src_line,float src_radius,const Box &box );
49 };
50
51 struct CollisionInfo{
52
53 Vector dv;
54 Vector sv;
55 Vector radii;
56
57 Vector panic;
58
59 Transform y_tform;
60
61 float radius,inv_y_scale;
62 float y_scale;
63
64 int n_hit;
65 Plane planes[2];
66
67 Line coll_line;
68 Vector dir;
69
70 float td;
71 float td_xz;
72
73 int hits;
74
75 float dst_radius;
76 float ax;
77 float ay;
78 float az;
79 float bx;
80 float by;
81 float bz;
82 };
83
84 // start of wrapper funcs
85
86 Vector* C_CreateVecObject(float x,float y,float z);
87 void C_DeleteVecObject(Vector* vec);
88 void C_UpdateVecObject(Vector* vec,float x,float y,float z);
89 float C_VecX(Vector* vec);
90 float C_VecY(Vector* vec);
91 float C_VecZ(Vector* vec);
92
93 Line* C_CreateLineObject(float ox,float oy,float oz,float dx,float dy,float dz);
94 void C_UpdateLineObject(Line* line,float ox,float oy,float oz,float dx,float dy,float dz);
95 void C_DeleteLineObject(Line* line);
96
97 MMatrix* C_CreateMatrixObject(Vector* vec_i,Vector* vec_j,Vector* vec_k);
98 void C_UpdateMatrixObject(MMatrix* mat,Vector* vec_i,Vector* vec_j,Vector* vec_k);
99 void C_DeleteMatrixObject(MMatrix* mat);
100
101 Transform* C_CreateTFormObject(MMatrix* mat,Vector* vec);
102 void C_UpdateTFormObject(Transform* tform,MMatrix* mat,Vector* vec);
103 void C_DeleteTFormObject(Transform* tform);
104
105 CollisionInfo* C_CreateCollisionInfoObject(Vector* dv,Vector* sv,Vector* radii);
106 void C_UpdateCollisionInfoObject2(CollisionInfo* ci,Vector* dv,Vector* sv,Vector* radii);
107 void C_UpdateCollisionInfoObject(CollisionInfo* ci,float dst_radius,float ax,float ay,float az,float bx,float by,float bz);
108 void C_DeleteCollisionInfoObject(CollisionInfo* ci);
109
110 Collision* C_CreateCollisionObject();
111 void C_DeleteCollisionObject(Collision* col);
112
113 int C_CollisionDetect(CollisionInfo* ci,Collision* coll,Transform* dst_tform,MeshCollider* mesh_col,int method);
114 int C_CollisionResponse(CollisionInfo* ci,Collision* coll,int response);
115 int C_CollisionFinal(CollisionInfo* ci);
116
117 int C_Pick(CollisionInfo* ci,const Line* line,float radius,Collision* coll,Transform* dst_tform,MeshCollider* mesh_col,int pick_geom);
118
119 float C_CollisionPosX();
120 float C_CollisionPosY();
121 float C_CollisionPosZ();
122 float C_CollisionX();
123 float C_CollisionY();
124 float C_CollisionZ();
125 float C_CollisionNX();
126 float C_CollisionNY();
127 float C_CollisionNZ();
128 float C_CollisionTime();
129 int C_CollisionSurface();
130 int C_CollisionTriangle();
131
132 #endif
C_CollisionZ
float C_CollisionZ()
Definition: collision.cpp:481
C_CollisionY
float C_CollisionY()
Definition: collision.cpp:476
C_CollisionTriangle
int C_CollisionTriangle()
Definition: collision.cpp:511
geom.h
COLLISION_RESPONSE_NONE
Definition: collision.h:26
C_UpdateCollisionInfoObject2
void C_UpdateCollisionInfoObject2(CollisionInfo *ci, Vector *dv, Vector *sv, Vector *radii)
Definition: collision.cpp:234
C_CollisionPosZ
float C_CollisionPosZ()
Definition: collision.cpp:466
C_CreateCollisionObject
Collision * C_CreateCollisionObject()
Definition: collision.cpp:174
CollisionInfo::y_scale
float y_scale
Definition: collision.h:62
CollisionInfo::panic
Vector panic
Definition: collision.h:57
Collision::time
float time
Definition: collision.h:34
COLLISION_METHOD_SPHERE
Definition: collision.h:19
C_CollisionPosX
float C_CollisionPosX()
Definition: collision.cpp:456
std
tree.h
CollisionInfo::az
float az
Definition: collision.h:78
C_CollisionSurface
int C_CollisionSurface()
Definition: collision.cpp:506
COLLISION_RESPONSE_STOP
Definition: collision.h:27
CollisionInfo::n_hit
int n_hit
Definition: collision.h:64
C_CollisionNX
float C_CollisionNX()
Definition: collision.cpp:486
C_UpdateTFormObject
void C_UpdateTFormObject(Transform *tform, MMatrix *mat, Vector *vec)
Definition: collision.cpp:601
C_CollisionTime
float C_CollisionTime()
Definition: collision.cpp:501
C_CollisionX
float C_CollisionX()
Definition: collision.cpp:471
Collision::Collision
Collision()
Definition: collision.h:39
Transform
Definition: geom.h:394
C_CreateLineObject
Line * C_CreateLineObject(float ox, float oy, float oz, float dx, float dy, float dz)
Definition: collision.cpp:550
MeshCollider
Definition: tree.h:14
C_DeleteMatrixObject
void C_DeleteMatrixObject(MMatrix *mat)
Definition: collision.cpp:589
C_CreateMatrixObject
MMatrix * C_CreateMatrixObject(Vector *vec_i, Vector *vec_j, Vector *vec_k)
Definition: collision.cpp:575
C_CreateCollisionInfoObject
CollisionInfo * C_CreateCollisionInfoObject(Vector *dv, Vector *sv, Vector *radii)
Definition: collision.cpp:186
Collision::surface
int surface
Definition: collision.h:36
C_UpdateMatrixObject
void C_UpdateMatrixObject(MMatrix *mat, Vector *vec_i, Vector *vec_j, Vector *vec_k)
Definition: collision.cpp:582
C_CreateTFormObject
Transform * C_CreateTFormObject(MMatrix *mat, Vector *vec)
Definition: collision.cpp:594
C_CreateVecObject
Vector * C_CreateVecObject(float x, float y, float z)
Definition: collision.cpp:516
C_UpdateLineObject
void C_UpdateLineObject(Line *line, float ox, float oy, float oz, float dx, float dy, float dz)
Definition: collision.cpp:565
CollisionInfo::sv
Vector sv
Definition: collision.h:54
C_DeleteLineObject
void C_DeleteLineObject(Line *line)
Definition: collision.cpp:560
C_CollisionNY
float C_CollisionNY()
Definition: collision.cpp:491
C_VecZ
float C_VecZ(Vector *vec)
Definition: collision.cpp:545
C_CollisionPosY
float C_CollisionPosY()
Definition: collision.cpp:461
C_VecX
float C_VecX(Vector *vec)
Definition: collision.cpp:535
CollisionInfo::hits
int hits
Definition: collision.h:73
Line
Definition: geom.h:118
C_CollisionResponse
int C_CollisionResponse(CollisionInfo *ci, Collision *coll, int response)
Definition: collision.cpp:349
CollisionInfo::dir
Vector dir
Definition: collision.h:68
C_UpdateCollisionInfoObject
void C_UpdateCollisionInfoObject(CollisionInfo *ci, float dst_radius, float ax, float ay, float az, float bx, float by, float bz)
Definition: collision.cpp:282
CollisionInfo::ax
float ax
Definition: collision.h:76
CollisionInfo::y_tform
Transform y_tform
Definition: collision.h:59
CollisionInfo::dv
Vector dv
Definition: collision.h:53
C_CollisionNZ
float C_CollisionNZ()
Definition: collision.cpp:496
CollisionInfo::bx
float bx
Definition: collision.h:79
Plane
Definition: geom.h:139
CollisionInfo::dst_radius
float dst_radius
Definition: collision.h:75
COLLISION_RESPONSE_SLIDEXZ
Definition: collision.h:29
Collision
Definition: collision.h:32
C_Pick
int C_Pick(CollisionInfo *ci, const Line *line, float radius, Collision *coll, Transform *dst_tform, MeshCollider *mesh_col, int pick_geom)
Definition: collision.cpp:433
COLLISION_EPSILON
const float COLLISION_EPSILON
Definition: collision.h:15
CollisionInfo::coll_line
Line coll_line
Definition: collision.h:67
C_UpdateVecObject
void C_UpdateVecObject(Vector *vec, float x, float y, float z)
Definition: collision.cpp:528
CollisionInfo::ay
float ay
Definition: collision.h:77
C_DeleteCollisionObject
void C_DeleteCollisionObject(Collision *col)
Definition: collision.cpp:181
Collision::index
int index
Definition: collision.h:37
Collision::normal
Vector normal
Definition: collision.h:35
C_DeleteCollisionInfoObject
void C_DeleteCollisionInfoObject(CollisionInfo *ci)
Definition: collision.cpp:293
C_DeleteTFormObject
void C_DeleteTFormObject(Transform *tform)
Definition: collision.cpp:607
C_VecY
float C_VecY(Vector *vec)
Definition: collision.cpp:540
Vector
Definition: geom.h:19
COLLISION_METHOD_BOX
Definition: collision.h:21
Box
Definition: geom.h:338
CollisionInfo
Definition: collision.h:51
COLLISION_METHOD_POLYGON
Definition: collision.h:20
CollisionInfo::radii
Vector radii
Definition: collision.h:55
CollisionInfo::by
float by
Definition: collision.h:80
C_DeleteVecObject
void C_DeleteVecObject(Vector *vec)
Definition: collision.cpp:523
CollisionInfo::radius
float radius
Definition: collision.h:61
MMatrix
Definition: geom.h:252
CollisionInfo::td_xz
float td_xz
Definition: collision.h:71
COLLISION_RESPONSE_SLIDE
Definition: collision.h:28
C_CollisionDetect
int C_CollisionDetect(CollisionInfo *ci, Collision *coll, Transform *dst_tform, MeshCollider *mesh_col, int method)
Definition: collision.cpp:324
CollisionInfo::td
float td
Definition: collision.h:70
CollisionInfo::bz
float bz
Definition: collision.h:81
C_CollisionFinal
int C_CollisionFinal(CollisionInfo *ci)
Definition: collision.cpp:419