World of Rigid Bodies (WoRB)
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
WoRB::Geometry Class Reference

Represents a geometry used to detect collisions against. More...

#include <Geometry.h>

Inheritance diagram for WoRB::Geometry:
Collaboration diagram for WoRB::Geometry:

Public Member Functions

bool IsCuboid () const
bool IsSphere () const
bool IsHalfSpace () const
bool IsTruePlane () const
const char * GetName () const
 Returns class of the geometry as a string.
Quaternion Position () const
 Gets the position vector of the geometry.
Quaternion Axis (unsigned index) const
 Gets the unit base vector (axes) of the geometry, given by the index.
void Detect (CollisionResolver &owner, const Geometry *B) const
 Detects and registers a collision between this and the other geometry.

Data Fields

RigidBodyBody
 The rigid body that is represented by this geometry.

Protected Types

enum  GeometryClass { _Sphere, _Cuboid, _HalfSpace, _TruePlane }

Protected Member Functions

 Geometry (GeometryClass type, RigidBody *body=0)
 Protected constructor; disallows explicit instantiation of the class.

Protected Attributes

GeometryClass Class
 Holds the geometry class of the object.

Detailed Description

Represents a geometry used to detect collisions against.

Cannot be explicitly instantiated.

Definition at line 27 of file Geometry.h.


Member Enumeration Documentation

Enumerator:
_Sphere 
_Cuboid 
_HalfSpace 
_TruePlane 

Definition at line 31 of file Geometry.h.


Constructor & Destructor Documentation

WoRB::Geometry::Geometry ( GeometryClass  type,
RigidBody body = 0 
) [inline, protected]

Protected constructor; disallows explicit instantiation of the class.

Definition at line 45 of file Geometry.h.

            : Class( type )
            , Body( body )
        {
        }

Member Function Documentation

Quaternion WoRB::Geometry::Axis ( unsigned  index) const [inline]

Gets the unit base vector (axes) of the geometry, given by the index.

Definition at line 88 of file Geometry.h.

References Body, WoRB::QTensor::Column(), and WoRB::RigidBody::ToWorld.

Referenced by WoRB::Cuboid::Check(), WoRB::Cuboid::Intersects(), WoRB::Cuboid::ProjectOn(), and WoRB::Cuboid::RegisterContactOnAxis().

        {
            // Axes are columns of the q-tensor with indices 0-2
            //
            return Body ? Body->ToWorld.Column( index ) : 0.0;
        }
void Geometry::Detect ( CollisionResolver owner,
const Geometry B 
) const

Detects and registers a collision between this and the other geometry.

Definition at line 18 of file CollisionDetection.cpp.

References _Cuboid, _HalfSpace, _Sphere, _TruePlane, Class, and WoRB::CollisionResolver::HasSpaceForMoreContacts().

Referenced by WoRB::WorldOfRigidBodies< 256, 1024 >::SolveODE().

{
    if ( ! owner.HasSpaceForMoreContacts () ) {
        return;
    }

    typedef const Cuboid*     Cuboid_    ;
    typedef const Sphere*     Sphere_    ;
    typedef const HalfSpace*  HalfSpace_ ;
    typedef const TruePlane*  TruePlane_ ;

    switch( Class )
    {
        case _Sphere: switch( B->Class )
        {
            case _Sphere:    Sphere_(this)->Check( owner, *Sphere_(B)    ); break;
            case _Cuboid:    Cuboid_(B)   ->Check( owner, *Sphere_(this) ); break;
            case _HalfSpace: Sphere_(this)->Check( owner, *HalfSpace_(B) ); break;
            case _TruePlane: Sphere_(this)->Check( owner, *TruePlane_(B) ); break;
        }
        break;

        case _Cuboid: switch( B->Class )
        {
            case _Sphere:    Cuboid_(this)->Check( owner, *Sphere_(B)    ); break;
            case _Cuboid:    Cuboid_(this)->Check( owner, *Cuboid_(B)    ); break;
            case _HalfSpace: Cuboid_(this)->Check( owner, *HalfSpace_(B) ); break;
            case _TruePlane: /* not implemented */                        ; break;
        }
        break;

        case _HalfSpace: switch( B->Class )
        {
            case _Sphere:    Sphere_(B)->Check( owner, *HalfSpace_(this) ); break;
            case _Cuboid:    Cuboid_(B)->Check( owner, *HalfSpace_(this) ); break;
            case _HalfSpace: /* not implemented */                        ; break;
            case _TruePlane: /* not implemented */                        ; break;
        }
        break;

        case _TruePlane: switch( B->Class )
        {
            case _Sphere:    Sphere_(B)->Check( owner, *TruePlane_(this) ); break;
            case _Cuboid:    /* not implemented */                        ; break;
            case _HalfSpace: /* not implemented */                        ; break;
            case _TruePlane: /* not implemented */                        ; break;
        }
        break;
    }
}
const char* WoRB::Geometry::GetName ( ) const [inline]

Returns class of the geometry as a string.

Definition at line 60 of file Geometry.h.

References _Cuboid, _HalfSpace, _Sphere, _TruePlane, and Class.

Referenced by WoRB_TestBed::Dump().

        {
            switch( Class )
            {
                case _Sphere:    return "Sphere";
                case _Cuboid:    return "Cuboid";
                case _HalfSpace: return "HalfSpace";
                case _TruePlane: return "TruePlane";
            }
            return "(unknown)";
        }
bool WoRB::Geometry::IsCuboid ( ) const [inline]

Definition at line 53 of file Geometry.h.

References _Cuboid, and Class.

Referenced by WoRB_TestBed::Dump().

{ return Class == _Cuboid;    }
bool WoRB::Geometry::IsHalfSpace ( ) const [inline]

Definition at line 55 of file Geometry.h.

References _HalfSpace, and Class.

{ return Class == _HalfSpace; }
bool WoRB::Geometry::IsSphere ( ) const [inline]

Definition at line 54 of file Geometry.h.

References _Sphere, and Class.

Referenced by WoRB_TestBed::Dump().

{ return Class == _Sphere;    }
bool WoRB::Geometry::IsTruePlane ( ) const [inline]

Definition at line 56 of file Geometry.h.

References _TruePlane, and Class.

{ return Class == _TruePlane; }

Gets the position vector of the geometry.

Definition at line 79 of file Geometry.h.

References Body, WoRB::QTensor::Column(), and WoRB::RigidBody::ToWorld.

Referenced by WoRB::Sphere::Check(), WoRB::Cuboid::Check(), WoRB::Sphere::Intersects(), and WoRB::Cuboid::Intersects().

        {
            // Column with index 3 holds the position
            //
            return Body ? Body->ToWorld.Column(3) : 0.0; 
        }

Field Documentation

Holds the geometry class of the object.

Definition at line 41 of file Geometry.h.

Referenced by Detect(), GetName(), IsCuboid(), IsHalfSpace(), IsSphere(), and IsTruePlane().


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