cd_vcollide.cpp
Go to the documentation of this file.
1 
10 #if _HAVE_VCOLLIDE
11 
12 #include "cd_vcollide.h"
13 
14 #include <VCollide.H>
15 
16 extern "C" {
17  #include "error.h"
18 }
19 
20 
22 {
23  VCollide *vc;
24 
25  vc=new(VCollide);
26 
27  return((Tvcollide *)vc);
28 }
29 
30 unsigned int AddPolyhedron2Vcollide(double **v,unsigned int nf,unsigned int *nvf,unsigned int **fv,Tvcollide *vc)
31 {
32  int id;
33  VCollide *vco;
34  unsigned int i,j,k;
35 
36  vco=(VCollide *)vc;
37 
38  vco->NewObject(&id);
39 
40  k=0;
41  for(i=0;i<nf;i++)
42  {
43  /* If the face has more then 3 vertexes, we trivially triangulate it.
44  In this triangulation we assume the face to be convex. */
45  if (nvf[i]<3)
46  Error("Detected a face with less than 3 vertexes in AddPolyhedron2Vcollide");
47 
48  for(j=2;j<nvf[i];j++)
49  {
50  vco->AddTri(v[fv[i][0]],v[fv[i][j-1]],v[fv[i][j]],k);
51  k++;
52  }
53  }
54 
55  vco->EndObject();
56 
57  return((unsigned int)id);
58 }
59 
60 void ActivateCollisionsVcollide(unsigned int o1,unsigned int o2,Tvcollide *vc)
61 {
62  VCollide *vco;
63 
64  vco=(VCollide *)vc;
65 
66  vco->ActivatePair((int)o1,(int)o2);
67 }
68 
69 void DeactivateCollisionsVcollide(unsigned int o1,unsigned int o2,Tvcollide *vc)
70 {
71  VCollide *vco;
72 
73  vco=(VCollide *)vc;
74 
75  vco->DeactivatePair((int)o1,(int)o2);
76 }
77 
78 void MoveVcollideObject(unsigned int o,THTransform *t,Tvcollide *vc)
79 {
80  VCollide *vco;
81 
82  vco=(VCollide *)vc;
83 
84  vco->UpdateTrans((int)o,*t);
85 }
86 
87 boolean VcollideTest(Tvcollide *vc)
88 {
89  VCollide *vco;
90  VCReport report;
91 
92  vco=(VCollide *)vc;
93 
94  vco->Collide(&report,VC_FIRST_CONTACT);
95 
96  if (report.numObjPairs()>0)
97  return(TRUE);
98  else
99  return(FALSE);
100 }
101 
102 void DeleteVcollideObject(unsigned int o,Tvcollide *vc)
103 {
104  VCollide *vco;
105 
106  vco=(VCollide *)vc;
107 
108  vco->DeleteObject((int)o);
109 }
110 
112 {
113  VCollide *vco;
114 
115  vco=(VCollide *)vc;
116 
117  delete vco;
118 }
119 
120 #endif
#define FALSE
FALSE.
Definition: boolean.h:30
unsigned int AddPolyhedron2Vcollide(double **v, unsigned int nf, unsigned int *nvf, unsigned int **fv, Tvcollide *vc)
Adds a polyhedron to the vcollide object.
Definition: cd_vcollide.cpp:30
A homgeneous transform in R^3.
Tvcollide * InitVcollide()
Initializes a Vcollide object.
Definition: cd_vcollide.cpp:21
void Tvcollide
The Vcollide object.
Definition: cd_vcollide.h:33
#define TRUE
TRUE.
Definition: boolean.h:21
void Error(const char *s)
General error function.
Definition: error.c:80
Error and warning functions.
Headers of the C interface for the vcollide collision detection engine.
boolean VcollideTest(Tvcollide *vc)
Test for collision.
Definition: cd_vcollide.cpp:87
void DeleteVcollideObject(unsigned int o, Tvcollide *vc)
Deletes a given vcollide object.
void DeleteVcollide(Tvcollide *vc)
Deletes a vcollide object.
void MoveVcollideObject(unsigned int o, THTransform *t, Tvcollide *vc)
Moves a given v-collide object.
Definition: cd_vcollide.cpp:78
void ActivateCollisionsVcollide(unsigned int o1, unsigned int o2, Tvcollide *vc)
Activates the collision between a pair of objects.
Definition: cd_vcollide.cpp:60
void DeactivateCollisionsVcollide(unsigned int o1, unsigned int o2, Tvcollide *vc)
Deactivates the collisions between a pair of object.
Definition: cd_vcollide.cpp:69