Bullet Physics Block Toy
Game Physics with a 3D Physics Engine
Loading...
Searching...
No Matches
CObject Class Reference

The game object. More...

#include <Object.h>

Inheritance diagram for CObject:
Collaboration diagram for CObject:

Public Member Functions

 CObject (const eObject, const CInstanceDesc &)
 Constructor.
 
 ~CObject ()
 Destructor.
 
void ApplyImpulse (const Vector3 &, const Vector3 &)
 Apply impulse.
 
void AddContact (CObject *, const CContactDesc &)
 Add a contact.
 
void PlayCollisionSounds ()
 Play collision sounds.
 
const eObject GetObjectType () const
 
const Vector3 GetPosition () const
 Get object type.
 
const Quaternion GetOrientation () const
 Get orientation.
 

Private Member Functions

btConvexHullShape * ComputeConvexHull ()
 Compute convex hull.
 
const bool ContactType (CObject *, eObject, eObject) const
 Contact type test.
 
const bool ContactType (CObject *, eObject) const
 Contact type test.
 

Private Attributes

eObject m_eObjectType = eObject::Unknown
 Object type.
 
eMesh m_eMeshType = eMesh::Unknown
 Mesh type.
 
eModel m_eModelType = eModel::Unknown
 Model type.
 
float m_fScale = 1.0f
 Scale (used for models).
 
UINT m_nShapeIndex = 0
 Shape index.
 
UINT m_nEffectIndex = 0
 Effect index.
 
Quaternion m_qOrientation
 Initial orientation.
 
btRigidBody * m_pBody = nullptr
 Pointer to physics body.
 
std::map< CObject *, CContactDescm_mapContact [2]
 Contact lists.
 
UINT m_nContactIndex = 0
 Contact index.
 

Friends

class CRenderer
 

Additional Inherited Members

- Protected Attributes inherited from CCommon
const float m_fFloorHt = 1.0f
 Floor height.
 
const Vector3 m_vPlanePos
 Plane position.
 
const Vector3 m_vPlaneSize
 Plane size.
 
const bool m_bWireFrame = false
 Draw in wireframe.
 
const float m_fMoonRadius = 25.0f
 Moon radius.
 
const float m_fBallRadius = 2.0f
 Ball radius.
 
const Vector3 m_vBoxSize = Vector3(9.0f, 6.0f, 6.0f)
 Box size.

 
const float m_fTetrahedronSize = 16.0f
 Tetrahedron size.
 
const float m_fIcosahedronSize = 16.0f
 Icosahedron size.
 
const float m_fDodecahedronSize = 16.0f
 Dodecahedron size.
 
const float m_fTeapotSize = 8.0f
 Teapot size.
 
- Static Protected Attributes inherited from CCommon
static CRendererm_pRenderer = nullptr
 Pointer to the renderer.
 
static Sage::CCamera * m_pCamera = nullptr
 Pointer to the camera.
 
static CObjectManagerm_pObjectManager = nullptr
 Pointer to object manager.
 
static btDiscreteDynamicsWorld * m_pPhysicsWorld = nullptr
 Pointer to physics engine.
 
static btDefaultCollisionConfiguration * m_pConfig = nullptr
 Bullet physics configuration.
 
static btCollisionDispatcher * m_pDispatcher = nullptr
 Bullet physics dispatcher.
 
static btBroadphaseInterface * m_pBroadphase = nullptr
 Bullet physics broadphase.
 
static btSequentialImpulseConstraintSolver * m_pSolver = nullptr
 Bullet physics constraint solver.
 
static btAlignedObjectArray< btCollisionShape * > m_btCollisionShapes
 Collision shapes.
 
static bool m_bCollisionSoundsMuted = false
 Mute collision sounds.
 

Detailed Description

CObject is the abstract representation of an object.

Constructor & Destructor Documentation

◆ CObject()

CObject::CObject ( const eObject t,
const CInstanceDesc & d )

Make an instance of a geometric primitive or triangle mesh model object with a shape for collision detection and response. Add a rigid body to the physics world with user pointer pointing to this so that we can later map collisions between physics bodies to the corresponding objects.

Parameters
tObject type.
dInstance descriptor.
Here is the call graph for this function:

◆ ~CObject()

CObject::~CObject ( )

Destructor. This is mainly just cleaning up after Bullet Physics by deleting the physics body, motion state, and collision object.

Member Function Documentation

◆ AddContact()

void CObject::AddContact ( CObject * pObj,
const CContactDesc & d )

Add a contact to the current contact map. This function is called by a callback function myTickCallback(), which is called from Bullet Physics whenever a contact between two bodies is detected.

Parameters
pObjPointer to object in contact.
dContact descriptor for the contact.
Here is the caller graph for this function:

◆ ApplyImpulse()

void CObject::ApplyImpulse ( const Vector3 & force,
const Vector3 & pos )

Apply an impulse through a point.

Parameters
forceDirection and magnitude of impulse.
posPoint through which the impulse is applied.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ComputeConvexHull()

btConvexHullShape * CObject::ComputeConvexHull ( )
private

Compute the convex hull for a primitive of type m_eMeshType. A convex hull is a triangle mesh that fits closely to the original mesh but is convex. Bullet Physics has the ability to compute a convex hull from the vertices of a mesh and use it as a collision shape. Append a pointer to it to m_btCollisionShapes.

Returns
Pointer to the convex hull created.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ContactType() [1/2]

const bool CObject::ContactType ( CObject * p,
eObject t ) const
private

Determine whether this object and another object have the right types, ignoring the order of the type parameters.

Parameters
pPointer to an object.
tObject type.
Returns
true if this object or *p has types t.
Here is the call graph for this function:

◆ ContactType() [2/2]

const bool CObject::ContactType ( CObject * p,
eObject t0,
eObject t1 ) const
private

Determine whether this object and another object have the right types, ignoring the order of the type parameters.

Parameters
pPointer to an object.
t0First object type.
t1Second object type.
Returns
true if this object and *p have types t0 and t1 in any order.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetObjectType()

const eObject CObject::GetObjectType ( ) const

Reader function for the object type.

Returns
Object type.
Here is the caller graph for this function:

◆ GetOrientation()

const Quaternion CObject::GetOrientation ( ) const

Get the object orientation. If it has a physics body, then get it from the physics engine, otherwise from m_qOrientation.

Returns
The object orientation quaternion.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetPosition()

const Vector3 CObject::GetPosition ( ) const

Get position.

Get the position of the object center. If it has a physics body, then get it from the physics engine, otherwise return the zero vector.

Returns
The position of the object center.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ PlayCollisionSounds()

void CObject::PlayCollisionSounds ( )

Play collision sounds, which are managed as follows. There are two contact maps, m_mapContact[0] and m_mapContact[1], which map a pointer to the object that this object is in contact with to a contact descriptor for the contact. The current contact map is m_mapContact[m_nContactIndex], where m_nContactIndex flips from zero to one each time this function is called. The other contact map m_mapContact[m_nContactIndex^1] is the contact map from the previous frame. Entries are place in the current contact map by a callback function myTickCallback() calling function AddContact() above. This function is then called at the end of the frame to play the appropriate sound when either (1) there is an entry in the current contact map for an object that does not have an entry in the previous contact map, or, (2) the entry for an object in the current contact map has more points of contact than the one in the previous contact map.

Here is the call graph for this function: