Kigs Framework  Doc version 0.8
Open source multi purpose Rapid Application Development framework
Classes | Public Member Functions | Protected Member Functions | List of all members
CollisionManager Class Reference

#include <CollisionManager.h>

Inheritance diagram for CollisionManager:
CoreModifiable GenericRefCountedBaseClass

Classes

class  MeshCollisionInfo
 

Public Member Functions

bool GetRayIntersection (Hit &hit, const Point3D &start, const Vector3D &dir, unsigned int a_itemCategory=ALL, bool ignore_is_collidable=false)
 intersect a ray with all objects in the collision manager More...
 
void GetAllRayIntersection (const Point3D &start, const Vector3D &dir, std::vector< Hit > &hits, unsigned int a_itemCategory=ALL, bool ignore_is_collidable=false)
 intersect a ray with all objects in the collision manager More...
 
void GetPlaneIntersection (const Point3D &o, const Vector3D &n, PlaneIntersectionInfoStruct &result, unsigned int a_itemCategory=ALL, const BBox *Zone=nullptr)
 intersect a plane with all (triangles) objects in the collision manager More...
 
CoreModifiableGetSphereIntersection (const Point3D &start, const Vector3D &dir, const kfloat Radius, kdouble &Distance, Vector3D &normal, Point3D &intersectP, unsigned int a_itemCategory=ALL)
 intersect a sphere with all objects in the collision manager More...
 
bool GetAltitude (kfloat x, kfloat y, kfloat z, kfloat &alt)
 return altitude for the current point More...
 
void setCollisionCategories (CoreModifiable *a_Item, unsigned int a_Category=0)
 set collision mask for a specific mItem
 
void setActiveMask (unsigned int a_mask)
 set collision mask for all the next items that will be added to the collision manager (should be reset to NONE(0) when we have finish).
 
- Public Member Functions inherited from CoreModifiable
void Init ()
 Modifiable managmenent.
 
void EmptyItemList ()
 remove all items (sons)
 
CMSP GetInstanceByPath (const std::string &path)
 return the instance corresponding to the given path in sons tree
 
std::string GetRuntimeID () const
 ID.
 
CoreModifiableAttributegetAttribute (KigsID labelid) const
 Attribute management.
 
u32 getNbArrayElements (KigsID attributeLabel) const
 return element count for an array type attribute
 
template<typename attribute_type , typename value_type >
attribute_type * AddDynamicAttribute (KigsID ID, const value_type &value)
 Dynamic attribute management.
 
const kigs::unordered_map< KigsID, ModifiableMethodStruct > * GetMethods ()
 Method management.
 
bool aggregateWith (CMSP &item, ItemPosition pos=Last)
 Aggregate management.
 
void flagAsNotificationCenterRegistered ()
 Flags.
 
void InitParametersFromList (const std::vector< CoreModifiableAttribute * > *params)
 Utility. More...
 
virtual void UninitModifiable ()
 called when InitModifiable has failled : reset read/write flag on all init params More...
 
virtual void ProtectedDestroy ()
 Destroy method decrement refcounter and delete instance if no more used. More...
 
virtual void addUser (CoreModifiable *user)
 add the given parent to list
 
virtual void removeUser (CoreModifiable *user)
 remove user (parent)
 
virtual bool addItem (const CMSP &item, ItemPosition pos=Last)
 add item at first or last position
 
virtual bool removeItem (const CMSP &item)
 remove item (son)
 

Protected Member Functions

void InitModifiable () override
 default modifiable init : set all initparams to readonly and set initflag to true More...
 
void CreateCollisionObject (CoreModifiable *item, unsigned int ColMask)
 
bool GetLocalRayIntersection (Hit &hit, const Point3D &start, const Vector3D &dir, const CollisionBaseObject *pCollisionObject)
 recursive internal method return true if itersection found More...
 
bool GetLocalSphereIntersection (Hit &hit, const Point3D &start, const Vector3D &dir, const kfloat &Radius, CollisionBaseObject *pCollisionObject)
 recursive internal method More...
 
bool RecursiveSearchRayIntersection (CoreModifiable *lastCollideNode, Node3D *lastNode, CoreModifiable *currentitem, Point3D start, Vector3D dir, Hit &hit, unsigned int lastNodeCategory, unsigned int a_itemCategory=ALL, bool ignore_is_collidable=false)
 recursive internal method More...
 
void RecursiveSearchAllRayIntersection (CoreModifiable *lastCollideNode, Node3D *lastNode, CoreModifiable *currentitem, const Point3D &start, const Vector3D &dir, std::vector< Hit > &hits, unsigned int lastNodeCategory, unsigned int a_itemCategory=ALL, bool ignore_is_collidable=false)
 
void RecursiveSearchPlaneIntersection (Node3D *lastNode, CoreModifiable *currentitem, const Point3D &o, const Vector3D &n, const BBox *Zone, PlaneIntersectionInfoStruct &result, unsigned int lastNodeCategory, unsigned int a_itemCategory=ALL)
 
bool RecursiveSearchSphereIntersection (Hit &hit, CoreModifiable *currentitem, const Point3D &start, const Vector3D &dir, const kfloat &Radius, unsigned int a_itemCategory=ALL)
 recursive internal method More...
 
CoreModifiableRecursiveSearchSphereIntersection (OctreeSubNode *currentNode, const Point3D &start, const Vector3D &dir, const kfloat &Radius, const Point3D &lstart, const Vector3D &ldir, const kfloat &lRadius, kdouble &Distance, Vector3D &normal, Point3D &intersectP, bool recurse=true, unsigned int a_itemCategory=ALL)
 recursive internal method More...
 
bool GetLocalSphereIntersectionWithRay (Hit &hit, const Point3D &start, const Vector3D &dir, const kfloat &Radius, CollisionBaseObject *pCollisionObject, unsigned int a_itemCategory=ALL)
 recursive internal method
 
- Protected Member Functions inherited from CoreModifiable
void UpdateAggregates (const Timer &timer, void *addParam)
 Internals.
 
void Export (std::vector< CoreModifiable * > &savedList, XMLNode *currentNode, bool recursive, ExportSettings *settings)
 Export. More...
 
CoreModifiableAttributeGenericCreateDynamicAttribute (CoreModifiable::ATTRIBUTE_TYPE type, KigsID ID)
 create and add dynamic attribute except arrays
 

Additional Inherited Members

- Static Public Member Functions inherited from CoreModifiable
static std::vector< CMSP > GetRootInstances (const KigsID &cid, bool exactTypeOnly=false)
 static method : return the set of all root instances of the given type
 
static void Append (std::string &XMLString, const std::list< CoreModifiable * > &toexport, bool recursive, ExportSettings *settings=nullptr)
 static method to export the several CoreModifiable to an XML file. if recursive flag is set to true, export also all sons tree More...
 
static void Export (const std::string &filename, CoreModifiable *toexport, bool recursive=false, ExportSettings *settings=nullptr)
 static method to export the given CoreModifiable to an XML file. if recursive flag is set to true, export also all sons tree More...
 
static XMLNodeExportToXMLNode (CoreModifiable *toexport, XML *owner_xml_file, bool recursive, ExportSettings *settings=nullptr)
 static method to export the given CoreModifiable to an XML Node. if recursive flag is set to true, export also all sons tree More...
 
static std::string ExportToXMLString (CoreModifiable *toexport, bool recursive, ExportSettings *settings=nullptr)
 static method to export the given CoreModifiable to an XML file. if recursive flag is set to true, export also all sons tree More...
 
static void Export (std::string &XMLString, const std::list< CoreModifiable * > &toexport, bool recursive, ExportSettings *settings=nullptr)
 static method to export the several CoreModifiable to an XML file. if recursive flag is set to true, export also all sons tree More...
 
static CMSP Import (const std::string &filename, bool noInit=false, bool keepImportFileName=false, ImportState *state=nullptr, const std::string &override_name="")
 return an new CoreModifiable instance using the description found in XML file given by name
 
static CMSP GetInstanceByGlobalPath (const std::string &path)
 static method : return the instance corresponding to the given path, and given search start
 
static void debugPrintfFullTree (int maxindent=3)
 Editor. More...
 
- Static Protected Member Functions inherited from CoreModifiable
template<typename StringType >
static CMSP Import (XMLNodeTemplate< StringType > *currentNode, CoreModifiable *currentModifiable, ImportState &importState)
 recusrive method to add sons and attributes found in the XML file
 

Detailed Description

Manager class to manage collision.

Attributes

Key : Scene

Methods

Key : DeserializeAABBTree

Key : GetAllRayIntersection

intersect a ray with all objects in the collision manager search an intersection between a Ray (point and direction), and all the objects in the manager call the recursive method : RecursiveSearchRayIntersection

Key : GetAltitude

return altitude for the current point compute "altitude" = vertical distance from the given point to any object in the collision manager

Key : GetIntersection

Key : OnAddItemCallback

Key : OnDeleteCallBack

Key : OnRemoveItemCallback

Key : SerializeAABBTree

Key : SetAABBTreeFromFile

Member Function Documentation

◆ CreateCollisionObject()

void CollisionManager::CreateCollisionObject ( CoreModifiable item,
unsigned int  ColMask 
)
protected

for each mItem in the list search if this mItem is already managed by the collision manager

else, construct its AABBTree if it is a mesh and add it to the collision map

◆ GetAllRayIntersection()

void CollisionManager::GetAllRayIntersection ( const Point3D &  start,
const Vector3D &  dir,
std::vector< Hit > &  hits,
unsigned int  a_itemCategory = ALL,
bool  ignore_is_collidable = false 
)

intersect a ray with all objects in the collision manager

search an intersection between a Ray (point and direction), and all the objects in the manager call the recursive method : RecursiveSearchRayIntersection

◆ GetAltitude()

bool CollisionManager::GetAltitude ( kfloat  x,
kfloat  y,
kfloat  z,
kfloat &  alt 
)

return altitude for the current point

compute "altitude" = vertical distance from the given point to any object in the collision manager

◆ GetLocalRayIntersection()

bool CollisionManager::GetLocalRayIntersection ( Hit &  hit,
const Point3D &  start,
const Vector3D &  dir,
const CollisionBaseObject pCollisionObject 
)
protected

recursive internal method return true if itersection found

compute intersection between a ray and a mesh in the local mesh coordinate system

◆ GetLocalSphereIntersection()

bool CollisionManager::GetLocalSphereIntersection ( Hit &  hit,
const Point3D &  start,
const Vector3D &  dir,
const kfloat &  Radius,
CollisionBaseObject pCollisionObject 
)
protected

recursive internal method

Utility method used by recursive intersection search

◆ GetPlaneIntersection()

void CollisionManager::GetPlaneIntersection ( const Point3D &  o,
const Vector3D &  n,
PlaneIntersectionInfoStruct &  result,
unsigned int  a_itemCategory = ALL,
const BBox *  Zone = nullptr 
)

intersect a plane with all (triangles) objects in the collision manager

intersect a plane with all (triangles) objects in the collision manager

◆ GetRayIntersection()

bool CollisionManager::GetRayIntersection ( Hit &  hit,
const Point3D &  start,
const Vector3D &  dir,
unsigned int  a_itemCategory = ALL,
bool  ignore_is_collidable = false 
)

intersect a ray with all objects in the collision manager

search an intersection between a Ray (point and direction), and all the objects in the manager call the recursive method : RecursiveSearchRayIntersection

◆ GetSphereIntersection()

CoreModifiable * CollisionManager::GetSphereIntersection ( const Point3D &  start,
const Vector3D &  dir,
const kfloat  Radius,
kdouble &  Distance,
Vector3D &  normal,
Point3D &  intersectP,
unsigned int  a_itemCategory = ALL 
)

intersect a sphere with all objects in the collision manager

compute intersection between a moving sphere and all the objects in the collision manager return the nearest intersection if at least one is found

first compute moving sphere BBox in local space

ensure the node is up to date (matrix, bbox...)

◆ InitModifiable()

void CollisionManager::InitModifiable ( )
overrideprotectedvirtual

default modifiable init : set all initparams to readonly and set initflag to true

already done ? then return

Reimplemented from CoreModifiable.

◆ RecursiveSearchAllRayIntersection()

void CollisionManager::RecursiveSearchAllRayIntersection ( CoreModifiable lastCollideNode,
Node3D lastNode,
CoreModifiable item,
const Point3D &  start,
const Vector3D &  dir,
std::vector< Hit > &  hits,
unsigned int  lastNodeCategory,
unsigned int  a_itemCategory = ALL,
bool  ignore_is_collidable = false 
)
protected

search an intersection between a Ray (point and direction), and the current CoreModifiable this method is recursive

on Node3D, mark as last seen node au recurse to sons

transform Ray in local mesh coordinate system if needed

for each son of the current mItem, if the son is a Mesh

if intersection found, go back to global coordinates and test if this intersection is the best one (nearest)

if intersection found, go back to global coordinates and test if this intersection is the best one (nearest)

if intersection found, go back to global coordinates and test if this intersection is the best one (nearest)

if intersection found, go back to global coordinates and test if this intersection is the best one (nearest)

◆ RecursiveSearchPlaneIntersection()

void CollisionManager::RecursiveSearchPlaneIntersection ( Node3D lastNode,
CoreModifiable currentitem,
const Point3D &  o,
const Vector3D &  n,
const BBox *  Zone,
PlaneIntersectionInfoStruct &  result,
unsigned int  lastNodeCategory,
unsigned int  a_itemCategory = ALL 
)
protected

on Node3D, mark as last seen node au recurse to sons

transform Ray in local mesh coordinate system if needed

for each son of the current mItem, if the son is a Mesh

◆ RecursiveSearchRayIntersection()

bool CollisionManager::RecursiveSearchRayIntersection ( CoreModifiable lastCollideNode,
Node3D lastNode,
CoreModifiable item,
Point3D  start,
Vector3D  dir,
Hit &  hit,
unsigned int  lastNodeCategory,
unsigned int  a_itemCategory = ALL,
bool  ignore_is_collidable = false 
)
protected

recursive internal method

recursive internal method

recurse in the Node3D hierarchy to find meshes and BSpheres. this method is recursive

void CollisionManager::RescursiveSearchMesh(CoreModifiable currentitem, std::vector<CoreModifiable>& list) { if ((currentitem->isSubType(Mesh::mClassID)) || (currentitem->isSubType(ModernMeshItemGroup::mClassID)) || (currentitem->isSubType(DrawVertice::mClassID)) || (currentitem->isSubType(Plane::mClassID)) || (currentitem->isSubType(BSphere::mClassID))) { list.push_back(currentitem); } else if (currentitem->isUserFlagSet(UserFlagNode3D) || currentitem->isSubType(ModernMesh::mClassID)) { bool needCollision = true;

! recurse only if NeedCollision flag is true CoreModifiableAttribute *pNeedCollisionAttribute = getAttribute("NeedCollision"); if (pNeedCollisionAttribute) pNeedCollisionAttribute->getValue(needCollision); if (needCollision) { std::vector<ModifiableItemStruct>::const_iterator it; for (it = currentitem->getItems().begin(); it != currentitem->getItems().end(); ++it) { RescursiveSearchMesh((*it).mItem, list); } } } }

search an intersection between a Ray (point and direction), and the current CoreModifiable this method is recursive

on Node3D, mark as last seen node au recurse to sons

transform Ray in local mesh coordinate system if needed

for each son of the current mItem, if the son is a Mesh

then check intersection between ray (local) and mesh

if intersection found, go back to global coordinates and test if this intersection is the best one (nearest)

if intersection found, go back to global coordinates and test if this intersection is the best one (nearest)

if intersection found, go back to global coordinates and test if this intersection is the best one (nearest)

if intersection found, go back to global coordinates and test if this intersection is the best one (nearest)

◆ RecursiveSearchSphereIntersection() [1/2]

bool CollisionManager::RecursiveSearchSphereIntersection ( Hit &  hit,
CoreModifiable currentitem,
const Point3D &  start,
const Vector3D &  dir,
const kfloat &  Radius,
unsigned int  a_itemCategory = ALL 
)
protected

recursive internal method

Recursive method to search for intersection of a moving sphere in an Node3D

◆ RecursiveSearchSphereIntersection() [2/2]

CoreModifiable * CollisionManager::RecursiveSearchSphereIntersection ( OctreeSubNode currentNode,
const Point3D &  start,
const Vector3D &  dir,
const kfloat &  Radius,
const Point3D &  lstart,
const Vector3D &  ldir,
const kfloat &  lRadius,
kdouble &  Distance,
Vector3D &  normal,
Point3D &  intersectP,
bool  recurse = true,
unsigned int  a_itemCategory = ALL 
)
protected

recursive internal method

Recursive method to search for intersection of a moving sphere in an octree


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