RigsofRods
Soft-body Physics Simulation
Data Structures | Public Types | Public Member Functions | Data Fields | Static Public Attributes | Private Member Functions | Private Attributes | Static Private Attributes
RoR::Collisions Class Reference

#include <Collisions.h>

+ Collaboration diagram for RoR::Collisions:

Data Structures

struct  hash_coll_element_t
 

Public Types

enum  SurfaceType {
  FX_NONE, FX_HARD, FX_DUSTY, FX_CLUMPY,
  FX_PARTICLE
}
 
typedef std::vector< collision_box_tCollisionBoxVec
 

Public Member Functions

 Collisions (Ogre::Vector3 terrn_size)
 
 ~Collisions ()
 
Ogre::Vector3 getPosition (const Ogre::String &inst, const Ogre::String &box)
 
Ogre::Quaternion getDirection (const Ogre::String &inst, const Ogre::String &box)
 
collision_box_tgetBox (const Ogre::String &inst, const Ogre::String &box)
 
std::pair< bool, Ogre::Real > intersectsTris (Ogre::Ray ray)
 
float getSurfaceHeight (float x, float z)
 
float getSurfaceHeightBelow (float x, float z, float height)
 
bool collisionCorrect (Ogre::Vector3 *refpos, bool envokeScriptCallbacks=true)
 
bool groundCollision (node_t *node, float dt)
 
bool isInside (Ogre::Vector3 pos, const Ogre::String &inst, const Ogre::String &box, float border=0)
 
bool isInside (Ogre::Vector3 pos, collision_box_t *cbox, float border=0)
 
bool nodeCollision (node_t *node, float dt)
 
void envokeScriptCallback (collision_box_t *cbox, node_t *node=0)
 
void findPotentialEventBoxes (Actor *actor, CollisionBoxPtrVec &out_boxes)
 
void finishLoadingTerrain ()
 
int addCollisionBox (bool rotating, bool virt, Ogre::Vector3 pos, Ogre::Vector3 rot, Ogre::Vector3 l, Ogre::Vector3 h, Ogre::Vector3 sr, const Ogre::String &eventname, const Ogre::String &instancename, bool forcecam, Ogre::Vector3 campos, Ogre::Vector3 sc=Ogre::Vector3::UNIT_SCALE, Ogre::Vector3 dr=Ogre::Vector3::ZERO, CollisionEventFilter event_filter=EVENT_ALL, int scripthandler=-1)
 
void addCollisionMesh (Ogre::String const &srcname, Ogre::String const &meshname, Ogre::Vector3 const &pos, Ogre::Quaternion const &q, Ogre::Vector3 const &scale, ground_model_t *gm=0, std::vector< int > *collTris=0)
 generate collision tris from existing mesh resource More...
 
void registerCollisionMesh (Ogre::String const &srcname, Ogre::String const &meshname, Ogre::Vector3 const &pos, Ogre::AxisAlignedBox bounding_box, ground_model_t *gm, int ctri_start, int ctri_count)
 Mark already generated collision tris as belonging to (virtual) mesh. More...
 
int addCollisionTri (Ogre::Vector3 p1, Ogre::Vector3 p2, Ogre::Vector3 p3, ground_model_t *gm)
 
void createCollisionDebugVisualization (Ogre::SceneNode *root_node, Ogre::AxisAlignedBox const &area_limit, std::vector< Ogre::SceneNode * > &out_nodes)
 
void removeCollisionBox (int number)
 
void removeCollisionTri (int number)
 
void clearEventCache ()
 
Ogre::AxisAlignedBox getCollisionAAB ()
 
int loadDefaultModels ()
 
int loadGroundModelsConfigFile (Ogre::String filename)
 
std::map< Ogre::String, ground_model_t > * getGroundModels ()
 
void setupLandUse (const char *configfile)
 
ground_model_tgetGroundModelByString (const Ogre::String name)
 
void getMeshInformation (Ogre::Mesh *mesh, size_t &vertex_count, Ogre::Vector3 *&vertices, size_t &index_count, unsigned *&indices, const Ogre::Vector3 &position=Ogre::Vector3::ZERO, const Ogre::Quaternion &orient=Ogre::Quaternion::IDENTITY, const Ogre::Vector3 &scale=Ogre::Vector3::UNIT_SCALE)
 
eventsource_tgetEventSource (int pos)
 
CollisionBoxVec const & getCollisionBoxes () const
 
CollisionMeshVec const & getCollisionMeshes () const
 
CollisionTriVec const & getCollisionTriangles () const
 

Data Fields

bool forcecam
 
Ogre::Vector3 forcecampos
 
ground_model_tdefaultgm
 
ground_model_tdefaultgroundgm
 

Static Public Attributes

static const int CELL_BLOCKSIZE = 126
 

Private Member Functions

bool permitEvent (Actor *actor, CollisionEventFilter filter)
 
void hash_add (int cell_x, int cell_z, int value, float h)
 
int hash_find (int cell_x, int cell_z)
 
unsigned int hashfunc (unsigned int cellid)
 Returns index to 'hashtable'. More...
 
void parseGroundConfig (Ogre::ConfigFile *cfg, Ogre::String groundModel="")
 
Ogre::Vector3 calcCollidedSide (const Ogre::Vector3 &pos, const Ogre::Vector3 &lo, const Ogre::Vector3 &hi)
 

Private Attributes

CollisionBoxVec m_collision_boxes
 
std::vector< collision_box_t * > m_last_called_cboxes
 
CollisionTriVec m_collision_tris
 
CollisionMeshVec m_collision_meshes
 
Ogre::AxisAlignedBox m_collision_aab
 
std::array< float, HASH_SIZEhashtable_height
 
std::vector< hash_coll_element_thashtable [HASH_SIZE]
 
std::map< Ogre::String, ground_model_tground_models
 
eventsource_t eventsources [MAX_EVENT_SOURCE]
 
int free_eventsource
 
Landusemaplanduse
 
int collision_version
 
unsigned int hashmask
 
const Ogre::Vector3 m_terrain_size
 

Static Private Attributes

static const int LATEST_GROUND_MODEL_VERSION = 3
 
static const int MAX_EVENT_SOURCE = 500
 
static const int HASH_POWER = 20
 
static const int HASH_SIZE = 1 << HASH_POWER
 
static const int CELL_SIZE = 2.0
 
static const int MAXIMUM_CELL = 0x7FFF
 

Detailed Description

Definition at line 80 of file Collisions.h.

Member Typedef Documentation

◆ CollisionBoxVec

Definition at line 84 of file Collisions.h.

Member Enumeration Documentation

◆ SurfaceType

Enumerator
FX_NONE 
FX_HARD 
FX_DUSTY 
FX_CLUMPY 
FX_PARTICLE 

Definition at line 86 of file Collisions.h.

Constructor & Destructor Documentation

◆ Collisions()

Collisions::Collisions ( Ogre::Vector3  terrn_size)

Definition at line 118 of file Collisions.cpp.

+ Here is the call graph for this function:

◆ ~Collisions()

Collisions::~Collisions ( )

Definition at line 140 of file Collisions.cpp.

Member Function Documentation

◆ addCollisionBox()

int Collisions::addCollisionBox ( bool  rotating,
bool  virt,
Ogre::Vector3  pos,
Ogre::Vector3  rot,
Ogre::Vector3  l,
Ogre::Vector3  h,
Ogre::Vector3  sr,
const Ogre::String &  eventname,
const Ogre::String &  instancename,
bool  forcecam,
Ogre::Vector3  campos,
Ogre::Vector3  sc = Ogre::Vector3::UNIT_SCALE,
Ogre::Vector3  dr = Ogre::Vector3::ZERO,
CollisionEventFilter  event_filter = EVENT_ALL,
int  scripthandler = -1 
)

Definition at line 401 of file Collisions.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addCollisionMesh()

void Collisions::addCollisionMesh ( Ogre::String const &  srcname,
Ogre::String const &  meshname,
Ogre::Vector3 const &  pos,
Ogre::Quaternion const &  q,
Ogre::Vector3 const &  scale,
ground_model_t gm = 0,
std::vector< int > *  collTris = 0 
)

generate collision tris from existing mesh resource

Definition at line 1408 of file Collisions.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addCollisionTri()

int Collisions::addCollisionTri ( Ogre::Vector3  p1,
Ogre::Vector3  p2,
Ogre::Vector3  p3,
ground_model_t gm 
)

Definition at line 551 of file Collisions.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ calcCollidedSide()

Ogre::Vector3 Collisions::calcCollidedSide ( const Ogre::Vector3 &  pos,
const Ogre::Vector3 &  lo,
const Ogre::Vector3 &  hi 
)
private

Definition at line 295 of file Collisions.cpp.

+ Here is the caller graph for this function:

◆ clearEventCache()

void RoR::Collisions::clearEventCache ( )
inline

Definition at line 201 of file Collisions.h.

+ Here is the caller graph for this function:

◆ collisionCorrect()

bool Collisions::collisionCorrect ( Ogre::Vector3 *  refpos,
bool  envokeScriptCallbacks = true 
)

Definition at line 766 of file Collisions.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createCollisionDebugVisualization()

void Collisions::createCollisionDebugVisualization ( Ogre::SceneNode *  root_node,
Ogre::AxisAlignedBox const &  area_limit,
std::vector< Ogre::SceneNode * > &  out_nodes 
)

Definition at line 1314 of file Collisions.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ envokeScriptCallback()

void Collisions::envokeScriptCallback ( collision_box_t cbox,
node_t node = 0 
)

Definition at line 602 of file Collisions.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ findPotentialEventBoxes()

void Collisions::findPotentialEventBoxes ( Actor actor,
CollisionBoxPtrVec out_boxes 
)

Definition at line 1088 of file Collisions.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ finishLoadingTerrain()

void Collisions::finishLoadingTerrain ( )

Definition at line 1585 of file Collisions.cpp.

◆ getBox()

collision_box_t * Collisions::getBox ( const Ogre::String &  inst,
const Ogre::String &  box 
)

Definition at line 1157 of file Collisions.cpp.

+ Here is the caller graph for this function:

◆ getCollisionAAB()

Ogre::AxisAlignedBox RoR::Collisions::getCollisionAAB ( )
inline

Definition at line 203 of file Collisions.h.

◆ getCollisionBoxes()

CollisionBoxVec const& RoR::Collisions::getCollisionBoxes ( ) const
inline

Definition at line 218 of file Collisions.h.

◆ getCollisionMeshes()

CollisionMeshVec const& RoR::Collisions::getCollisionMeshes ( ) const
inline

Definition at line 219 of file Collisions.h.

◆ getCollisionTriangles()

CollisionTriVec const& RoR::Collisions::getCollisionTriangles ( ) const
inline

Definition at line 220 of file Collisions.h.

+ Here is the caller graph for this function:

◆ getDirection()

Quaternion Collisions::getDirection ( const Ogre::String &  inst,
const Ogre::String &  box 
)

Definition at line 1145 of file Collisions.cpp.

+ Here is the caller graph for this function:

◆ getEventSource()

eventsource_t& RoR::Collisions::getEventSource ( int  pos)
inline

Definition at line 217 of file Collisions.h.

+ Here is the caller graph for this function:

◆ getGroundModelByString()

ground_model_t * Collisions::getGroundModelByString ( const Ogre::String  name)

Definition at line 365 of file Collisions.cpp.

+ Here is the caller graph for this function:

◆ getGroundModels()

std::map<Ogre::String, ground_model_t>* RoR::Collisions::getGroundModels ( )
inline

Definition at line 208 of file Collisions.h.

+ Here is the caller graph for this function:

◆ getMeshInformation()

void Collisions::getMeshInformation ( Ogre::Mesh *  mesh,
size_t &  vertex_count,
Ogre::Vector3 *&  vertices,
size_t &  index_count,
unsigned *&  indices,
const Ogre::Vector3 &  position = Ogre::Vector3::ZERO,
const Ogre::Quaternion &  orient = Ogre::Quaternion::IDENTITY,
const Ogre::Vector3 &  scale = Ogre::Vector3::UNIT_SCALE 
)

Definition at line 1469 of file Collisions.cpp.

+ Here is the caller graph for this function:

◆ getPosition()

Vector3 Collisions::getPosition ( const Ogre::String &  inst,
const Ogre::String &  box 
)

Definition at line 1133 of file Collisions.cpp.

+ Here is the caller graph for this function:

◆ getSurfaceHeight()

float Collisions::getSurfaceHeight ( float  x,
float  z 
)

Definition at line 671 of file Collisions.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getSurfaceHeightBelow()

float Collisions::getSurfaceHeightBelow ( float  x,
float  z,
float  height 
)

Definition at line 676 of file Collisions.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ groundCollision()

bool Collisions::groundCollision ( node_t node,
float  dt 
)

Definition at line 1212 of file Collisions.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ hash_add()

void Collisions::hash_add ( int  cell_x,
int  cell_z,
int  value,
float  h 
)
private

Definition at line 384 of file Collisions.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ hash_find()

int Collisions::hash_find ( int  cell_x,
int  cell_z 
)
private

Definition at line 393 of file Collisions.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ hashfunc()

unsigned int Collisions::hashfunc ( unsigned int  cellid)
private

Returns index to 'hashtable'.

Definition at line 373 of file Collisions.cpp.

+ Here is the caller graph for this function:

◆ intersectsTris()

std::pair< bool, Ogre::Real > Collisions::intersectsTris ( Ogre::Ray  ray)

Definition at line 628 of file Collisions.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isInside() [1/2]

bool Collisions::isInside ( Ogre::Vector3  pos,
collision_box_t cbox,
float  border = 0 
)

Definition at line 1176 of file Collisions.cpp.

◆ isInside() [2/2]

bool Collisions::isInside ( Ogre::Vector3  pos,
const Ogre::String &  inst,
const Ogre::String &  box,
float  border = 0 
)

Definition at line 1169 of file Collisions.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ loadDefaultModels()

int Collisions::loadDefaultModels ( )

Definition at line 145 of file Collisions.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ loadGroundModelsConfigFile()

int Collisions::loadGroundModelsConfigFile ( Ogre::String  filename)

Definition at line 150 of file Collisions.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nodeCollision()

bool Collisions::nodeCollision ( node_t node,
float  dt 
)

Definition at line 926 of file Collisions.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parseGroundConfig()

void Collisions::parseGroundConfig ( Ogre::ConfigFile *  cfg,
Ogre::String  groundModel = "" 
)
private

Definition at line 206 of file Collisions.cpp.

+ Here is the caller graph for this function:

◆ permitEvent()

bool Collisions::permitEvent ( Actor actor,
CollisionEventFilter  filter 
)
private

Definition at line 906 of file Collisions.cpp.

+ Here is the caller graph for this function:

◆ registerCollisionMesh()

void Collisions::registerCollisionMesh ( Ogre::String const &  srcname,
Ogre::String const &  meshname,
Ogre::Vector3 const &  pos,
Ogre::AxisAlignedBox  bounding_box,
ground_model_t gm,
int  ctri_start,
int  ctri_count 
)

Mark already generated collision tris as belonging to (virtual) mesh.

Definition at line 1455 of file Collisions.cpp.

+ Here is the caller graph for this function:

◆ removeCollisionBox()

void Collisions::removeCollisionBox ( int  number)

Definition at line 343 of file Collisions.cpp.

+ Here is the caller graph for this function:

◆ removeCollisionTri()

void Collisions::removeCollisionTri ( int  number)

Definition at line 356 of file Collisions.cpp.

+ Here is the caller graph for this function:

◆ setupLandUse()

void Collisions::setupLandUse ( const char *  configfile)

Definition at line 333 of file Collisions.cpp.

Field Documentation

◆ CELL_BLOCKSIZE

const int RoR::Collisions::CELL_BLOCKSIZE = 126
static

Definition at line 170 of file Collisions.h.

◆ CELL_SIZE

const int RoR::Collisions::CELL_SIZE = 2.0
staticprivate

Definition at line 128 of file Collisions.h.

◆ collision_version

int RoR::Collisions::collision_version
private

Definition at line 155 of file Collisions.h.

◆ defaultgm

ground_model_t* RoR::Collisions::defaultgm

Definition at line 174 of file Collisions.h.

◆ defaultgroundgm

ground_model_t * RoR::Collisions::defaultgroundgm

Definition at line 174 of file Collisions.h.

◆ eventsources

eventsource_t RoR::Collisions::eventsources[MAX_EVENT_SOURCE]
private

Definition at line 149 of file Collisions.h.

◆ forcecam

bool RoR::Collisions::forcecam

Definition at line 172 of file Collisions.h.

◆ forcecampos

Ogre::Vector3 RoR::Collisions::forcecampos

Definition at line 173 of file Collisions.h.

◆ free_eventsource

int RoR::Collisions::free_eventsource
private

Definition at line 150 of file Collisions.h.

◆ ground_models

std::map<Ogre::String, ground_model_t> RoR::Collisions::ground_models
private

Definition at line 146 of file Collisions.h.

◆ HASH_POWER

const int RoR::Collisions::HASH_POWER = 20
staticprivate

Definition at line 124 of file Collisions.h.

◆ HASH_SIZE

const int RoR::Collisions::HASH_SIZE = 1 << HASH_POWER
staticprivate

Definition at line 125 of file Collisions.h.

◆ hashmask

unsigned int RoR::Collisions::hashmask
private

Definition at line 156 of file Collisions.h.

◆ hashtable

std::vector<hash_coll_element_t> RoR::Collisions::hashtable[HASH_SIZE]
private

Definition at line 143 of file Collisions.h.

◆ hashtable_height

std::array<float, HASH_SIZE> RoR::Collisions::hashtable_height
private

Definition at line 142 of file Collisions.h.

◆ landuse

Landusemap* RoR::Collisions::landuse
private

Definition at line 154 of file Collisions.h.

◆ LATEST_GROUND_MODEL_VERSION

const int RoR::Collisions::LATEST_GROUND_MODEL_VERSION = 3
staticprivate

Definition at line 120 of file Collisions.h.

◆ m_collision_aab

Ogre::AxisAlignedBox RoR::Collisions::m_collision_aab
private

Definition at line 139 of file Collisions.h.

◆ m_collision_boxes

CollisionBoxVec RoR::Collisions::m_collision_boxes
private

Definition at line 132 of file Collisions.h.

◆ m_collision_meshes

CollisionMeshVec RoR::Collisions::m_collision_meshes
private

Definition at line 137 of file Collisions.h.

◆ m_collision_tris

CollisionTriVec RoR::Collisions::m_collision_tris
private

Definition at line 136 of file Collisions.h.

◆ m_last_called_cboxes

std::vector<collision_box_t*> RoR::Collisions::m_last_called_cboxes
private

Definition at line 133 of file Collisions.h.

◆ m_terrain_size

const Ogre::Vector3 RoR::Collisions::m_terrain_size
private

Definition at line 158 of file Collisions.h.

◆ MAX_EVENT_SOURCE

const int RoR::Collisions::MAX_EVENT_SOURCE = 500
staticprivate

Definition at line 121 of file Collisions.h.

◆ MAXIMUM_CELL

const int RoR::Collisions::MAXIMUM_CELL = 0x7FFF
staticprivate

Definition at line 129 of file Collisions.h.


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