![]() |
Bullet Physics 3D Block Toy
|
The game object. More...
#include <Object.h>
Public Member Functions | |
CObject (const eObject, const CInstanceDesc &) | |
Constructor. More... | |
~CObject () | |
Destructor. More... | |
void | ApplyImpulse (const Vector3 &, const Vector3 &) |
Apply impulse. More... | |
void | AddContact (CObject *, const CContactDesc &) |
Add a contact. More... | |
void | PlayCollisionSounds () |
Play collision sounds. More... | |
void | kill () |
Kill me. More... | |
const bool | IsDead () const |
Query whether dead. More... | |
const eObject | GetObjectType () const |
Reader function for the object type. | |
const Vector3 | GetPosition () const |
Get object type. More... | |
const Quaternion | GetOrientation () const |
Get orientation. More... | |
Private Member Functions | |
btConvexHullShape * | ComputeConvexHull () |
Compute convex hull. More... | |
const bool | ContactType (CObject *, eObject, eObject) const |
Contact type test. More... | |
const bool | ContactType (CObject *, eObject) const |
Contact type test. More... | |
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. | |
bool | m_bDead = false |
Is dead or not. | |
btRigidBody * | m_pBody = nullptr |
Pointer to physics body. | |
std::map< CObject *, CContactDesc > | m_mapContact [2] |
Contact lists. | |
UINT | m_nContactIndex = 0 |
Contact index. | |
Friends | |
class | CRenderer |
Additional Inherited Members | |
![]() | |
const float | m_fFloorHt = 0.5f |
Floor height. | |
const Vector3 | m_vPlanePos = Vector3(0.0f, 0.0f, 100.0f) |
Plane position. | |
const Vector3 | m_vPlaneSize = Vector3(600.0f, 2.0f*m_fFloorHt, 600.0f) |
Plane size. | |
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 CRenderer * | m_pRenderer = nullptr |
Pointer to the renderer. | |
static LBaseCamera * | m_pCamera = nullptr |
Pointer to the camera. | |
static CObjectManager * | m_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. | |
CObject is the abstract representation of an object.
CObject::CObject | ( | const eObject | t, |
const CInstanceDesc & | d | ||
) |
Constructor. Make an instance of a geometric primitive 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.
t | Object type. |
d | Instance descriptor. |
CObject::~CObject | ( | ) |
Destructor. This is mainly just cleaning up after Bullet Physics by deleting the physics body, motion state, and collision object.
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.
pObj | Pointer to object in contact. |
d | Contact descriptor for the contact. |
void CObject::ApplyImpulse | ( | const Vector3 & | force, |
const Vector3 & | pos | ||
) |
Apply an impulse through a point.
force | Direction and magnitude of impulse. |
pos | Point through which the impulse is applied. |
|
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.
Determine whether this object and another object have the right types, ignoring the order of the type parameters.
p | Pointer to an object. |
t | Object type. |
Determine whether this object and another object have the right types, ignoring the order of the type parameters.
p | Pointer to an object. |
t0 | First object type. |
t1 | Second object type. |
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.
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.
const bool CObject::IsDead | ( | ) | const |
Reader function for the "is dead" flag.
void CObject::kill | ( | ) |
Kill an object by marking its "is dead" flag. The object will get deleted later at the appropriate time.
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.