Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
csOPCODECollider Class Reference

#include <CSopcodecollider.h>

Public Member Functions

 csOPCODECollider (const std::vector< mesh_polygon > &polygons)
 
 ~csOPCODECollider ()
 
int GetColliderType () const
 
bool rayCollide (const Opcode::Ray &boltbeam, Vector &norm, float &distance)
 
bool Collide (csOPCODECollider &pOtherCollider, const csReversibleTransform *pThisTransform=0, const csReversibleTransform *pOtherTransform=0)
 
void SetOneHitOnly (bool fh)
 
bool GetOneHitOnly () const
 
float GetRadius () const
 
Vector getVertex (unsigned int which) const
 
unsigned int getNumVertex () const
 

Static Public Member Functions

static csCollisionPairGetCollisions ()
 
static void ResetCollisionPairs ()
 
static size_t GetCollisionPairCount ()
 

Detailed Description

Definition at line 70 of file CSopcodecollider.h.

Constructor & Destructor Documentation

csOPCODECollider::csOPCODECollider ( const std::vector< mesh_polygon > &  polygons)

Definition at line 38 of file CSopcodecollider.cpp.

39 {
40  m_pCollisionModel = 0;
41  vertholder = 0;
42  pairs.IncRef();
43  TreeCollider.SetFirstContact(true);
44  TreeCollider.SetFullBoxBoxTest(false);
45  TreeCollider.SetTemporalCoherence(false);
46  opcMeshInt.SetCallback (&MeshCallback, this);
47  GeometryInitialize (polygons);
48  CollisionFace collFace;
49  rCollider.SetFirstContact(true);
50 
51 }
csOPCODECollider::~csOPCODECollider ( )

Definition at line 108 of file CSopcodecollider.cpp.

109 {
110 
111  if (m_pCollisionModel) {
112  delete m_pCollisionModel;
113  m_pCollisionModel = 0;
114  }
115  pairs.DecRef();
116  delete[] vertholder;
117 }

Member Function Documentation

bool csOPCODECollider::Collide ( csOPCODECollider pOtherCollider,
const csReversibleTransform pThisTransform = 0,
const csReversibleTransform pOtherTransform = 0 
)

Definition at line 165 of file CSopcodecollider.cpp.

References FALSE, csTransform::GetO2TTranslation(), csReversibleTransform::GetT2O(), Opcode::Matrix4x4::m, m1, csMatrix3::Row1(), csMatrix3::Row2(), csMatrix3::Row3(), csVector3::Set(), csVector3::x, csVector3::y, and csVector3::z.

Referenced by ContinuousTerrain::Collide(), and Unit::InsideCollideTree().

168 {
169  csOPCODECollider* col2 = (csOPCODECollider*) &otherCollider;
170  ColCache.Model0 = this->m_pCollisionModel;
171  ColCache.Model1 = col2->m_pCollisionModel;
172  csMatrix3 m1;
173  if (trans1) m1 = trans1->GetT2O ();
174  csMatrix3 m2;
175  if (trans2) m2 = trans2->GetT2O ();
176  csVector3 u;
177  Matrix4x4 transform1;
178  transform1.m[0][3] = 0;
179  transform1.m[1][3] = 0;
180  transform1.m[2][3] = 0;
181  transform1.m[3][3] = 1;
182  Matrix4x4 transform2;
183  transform2.m[0][3] = 0;
184  transform2.m[1][3] = 0;
185  transform2.m[2][3] = 0;
186  transform2.m[3][3] = 1;
187  u = m1.Row1 ();
188  transform1.m[0][0] = u.x;
189  transform1.m[1][0] = u.y;
190  transform1.m[2][0] = u.z;
191  u = m2.Row1 ();
192  transform2.m[0][0] = u.x;
193  transform2.m[1][0] = u.y;
194  transform2.m[2][0] = u.z;
195  u = m1.Row2 ();
196  transform1.m[0][1] = u.x;
197  transform1.m[1][1] = u.y;
198  transform1.m[2][1] = u.z;
199  u = m2.Row2 ();
200  transform2.m[0][1] = u.x;
201  transform2.m[1][1] = u.y;
202  transform2.m[2][1] = u.z;
203  u = m1.Row3 ();
204  transform1.m[0][2] = u.x;
205  transform1.m[1][2] = u.y;
206  transform1.m[2][2] = u.z;
207  u = m2.Row3();
208  transform2.m[0][2] = u.x;
209  transform2.m[1][2] = u.y;
210  transform2.m[2][2] = u.z;
211  if (trans1) u = trans1->GetO2TTranslation ();
212  else u.Set (0, 0, 0);
213  transform1.m[3][0] = u.x;
214  transform1.m[3][1] = u.y;
215  transform1.m[3][2] = u.z;
216 
217  if (trans2) u = trans2->GetO2TTranslation ();
218  else u.Set (0, 0, 0);
219  transform2.m[3][0] = u.x;
220  transform2.m[3][1] = u.y;
221  transform2.m[3][2] = u.z;
222  if (TreeCollider.Collide (ColCache, &transform1, &transform2)) {
223  bool status = (TreeCollider.GetContactStatus () != FALSE);
224  if (status) {
225  CopyCollisionPairs (this, col2);
226  }
227  return(status);
228  } else
229  return(false);
230 }
int csOPCODECollider::GetColliderType ( ) const
inline

Definition at line 112 of file CSopcodecollider.h.

References CS_MESH_COLLIDER.

112 {return CS_MESH_COLLIDER;}
size_t csOPCODECollider::GetCollisionPairCount ( )
static

Definition at line 243 of file CSopcodecollider.cpp.

Referenced by ContinuousTerrain::Collide(), and Unit::InsideCollideTree().

244 {
245  return(pairs.Length());
246 }
csCollisionPair * csOPCODECollider::GetCollisions ( )
static

Definition at line 238 of file CSopcodecollider.cpp.

Referenced by ContinuousTerrain::Collide(), and Unit::InsideCollideTree().

239 {
240  return(pairs.GetArray());
241 }
unsigned int csOPCODECollider::getNumVertex ( ) const
inline

Definition at line 153 of file CSopcodecollider.h.

References Opcode::BaseModel::GetMeshInterface(), and Opcode::MeshInterface::GetNbVertices().

Referenced by LaunchOneParticle().

153 { return(m_pCollisionModel->GetMeshInterface()->GetNbVertices());}
bool csOPCODECollider::GetOneHitOnly ( ) const
inline

Definition at line 142 of file CSopcodecollider.h.

References Opcode::Collider::FirstContactEnabled().

142 { return(TreeCollider.FirstContactEnabled());}
float csOPCODECollider::GetRadius ( ) const
inline

Definition at line 146 of file CSopcodecollider.h.

146 {return radius;};
Vector csOPCODECollider::getVertex ( unsigned int  which) const

Definition at line 256 of file CSopcodecollider.cpp.

References Vector, x, y, and z.

Referenced by LaunchOneParticle().

257 {
258  // This function is used to position the damage particles
259  if(!vertholder)
260  return(Vector(0,0,0));
261  return(Vector(vertholder[which].x,vertholder[which].y,vertholder[which].z));
262 }
bool csOPCODECollider::rayCollide ( const Opcode::Ray boltbeam,
Vector norm,
float distance 
)

Definition at line 132 of file CSopcodecollider.cpp.

Referenced by Unit::rayCollide().

133 {
134  rCollider.SetHitCallback(&csOPCODECollider::RayCallback);
135  rCollider.SetUserData(this);
136  rCollider.SetFirstContact(false);
137  //rCollider.SetClosestHit(true);
138  collFace.mDistance=FLT_MAX;
139  bool retval=rCollider.Collide(boltbeam,*m_pCollisionModel);
140  rCollider.SetUserData(NULL);
141  if (retval) {
142  retval=collFace.mDistance!=FLT_MAX;
143  if (retval) {
144  distance=collFace.mDistance;
145 #ifdef VS_DEBUG
146  printf("Opcode actually reported a hit at %f meters!\n",distance);
147 #endif
148  } else {
149  return true;//FIXME: buggy! this should return FALSE but the math is obviously broken with opcode, so opcode is rarely telling us about intersections
150  }
151  //FIXME set normal
152  }
153  return retval;
154 }
void csOPCODECollider::ResetCollisionPairs ( )
static

Definition at line 233 of file CSopcodecollider.cpp.

Referenced by Unit::InsideCollideTree().

234 {
235  pairs.SetLength(0);
236 }
void csOPCODECollider::SetOneHitOnly ( bool  fh)

Definition at line 249 of file CSopcodecollider.cpp.

250 {
251  TreeCollider.SetFirstContact(on);
252  rCollider.SetFirstContact(on);
253 }

The documentation for this class was generated from the following files: