Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/nico/src/collision.h @ 3542

Last change on this file since 3542 was 3238, checked in by bensch, 20 years ago

orxonox/branches: updated branches: buerli, nico, sound. And moved bezierTrack to old.bezierTrack. Conflicts resolved in a usefull order.
Conflics mostly resolved in favor of trunk
merge.

File size: 2.6 KB
RevLine 
[2014]1/*!
2    \file collision.h
3    \brief Basic collision detection
4*/ 
[1966]5
[3238]6#ifndef _COLLISION_H
7#define _COLLISION_H
[1966]8
[1975]9#include "vector.h"
10#include "coordinates.h"
11#include <stdlib.h>
12#include <stdio.h>
[2166]13#include <string.h>
[1966]14
[2014]15//! Tree structure used by the CollisionCluster
[3238]16typedef struct CCTree
[1966]17{
18  unsigned long n;
19  union
20  {
[3238]21  struct CCTree** b;
[1966]22  unsigned long ID;
23  } data;
24  float r;
25  Vector m;
[3238]26} CCTree;
[1966]27
[2012]28//! Basic collision detection class
[2010]29/**
30  This class implements a more or less efficient collision system based on nested hitzones.
31  Instead of using a brute force approach (try if any hitzone intersects with any other hitzone)
32  this features a tree of spheric hitzones. Only some of them are actually the solid groundstones
33  the collision model bases on, the others serve to group them into sets of spheres that are only
34  checked for collision when the assigned top level sphere has registered a collision, preventing
35  unnessessary checks (like between every sphere of two collision clusters at the other end of the world)
36  from being performed.
37  The CollisionCluster features collision detection between multiple CollisionClusters as well as
38  traceing a collision between a line of defined length and a cluster. In both cases the base spheres
39  that have intersected are marked with a flag in an unsigned long for hitlocation queries. In the case
40  of a trace, the exact point of interception is returned as well.
41*/
[1966]42class CollisionCluster {
43 
[3238]44  CCTree* root;
[1966]45 
46 
47 public:
48  CollisionCluster (float r, Vector m); // simple cluster
49  CollisionCluster (char* filename); // get cluster from file
50  ~CollisionCluster ();
51 
52  int store (char* filename);
53 
[3238]54  friend bool ccTreeTrace( const Placement* p, CCTree* t, unsigned long* hitflags, const Line* trace, Vector* impactpoint);
55  friend bool ccTreeIterate(const Placement* pa, CCTree* ta, unsigned long* ahitflags, const Placement* pb, CCTree* tb, unsigned long* bhitflags);
56  friend bool checkTrace (const Placement* pa, const CollisionCluster* a, unsigned long* ahitflags, const Line* trace, Vector* impactpoint);
57  friend bool checkCollision (const Placement* pa, const CollisionCluster* a, unsigned long* ahitflags, const Placement* pb, const CollisionCluster* b, unsigned long* bhitflags);
[1966]58};
59
[3238]60bool sphereSphereCollision( Vector m1, float r1, Vector m2, float r2);
61bool traceSphereCollision( Vector m, float r, const Line* l, Vector* impactpoint);
[1966]62
63void setflag( unsigned long* flags, unsigned long ID);
64
[3238]65void freeCCTree( CCTree* tree);
66CCTree* loadCCTree (FILE* stream);
67int saveCCTree (CCTree* tree, FILE* stream);
[1966]68
[3238]69#endif /* _COLLISION_H */
Note: See TracBrowser for help on using the repository browser.