Leviathan  0.8.0.0
Leviathan game engine
Leviathan::PhysicsShape Class Reference

A physical shape that can be used to create PhysicsBody objects. More...

#include <PhysicsShape.h>

+ Inheritance diagram for Leviathan::PhysicsShape:

Public Member Functions

DLLEXPORT btCollisionShape * GetShape ()
 
 REFERENCE_COUNTED_PTR_TYPE (PhysicsShape)
 
DLLEXPORT bool AddChildShape (const PhysicsShape::pointer &child, const Float3 &offset=Float3(0, 0, 0), const Float4 &orientation=Float4::IdentityQuaternion())
 
DLLEXPORT bool RemoveChildShape (PhysicsShape *child)
 
DLLEXPORT PhysicsShape::pointer GetChildByIndex (size_t index)
 
DLLEXPORT int GetChildCustomTag (size_t index) const
 Calls GetCustomTag on the child at index. If invalid index returns -1. More...
 
DLLEXPORT int FindChildShapeIndex (PhysicsShape *child)
 Finds the index that the child shape occupies. More...
 
DLLEXPORT int GetCustomTag () const
 Custom tags allow storing one int of application specific info in this class. More...
 
DLLEXPORT void SetCustomTag (int value)
 
DLLEXPORT bool AddChildShapeWrapper (PhysicsShape *child, const Float3 &offset=Float3(0, 0, 0), const Float4 &orientation=Float4::IdentityQuaternion())
 
DLLEXPORT int FindChildShapeIndexWrapper (PhysicsShape *child)
 
- Public Member Functions inherited from Leviathan::ReferenceCounted
 ReferenceCounted (const ReferenceCounted &other)=delete
 
ReferenceCountedoperator= (const ReferenceCounted &other)=delete
 
FORCE_INLINE void AddRef () const
 
FORCE_INLINE void Release () const
 removes a reference and deletes the object if reference count reaches zero More...
 
FORCE_INLINE void AddRef ()
 
FORCE_INLINE void Release ()
 
int32_t GetRefCount () const
 Returns the reference count. More...
 

Protected Member Functions

DLLEXPORT PhysicsShape (std::unique_ptr< btCollisionShape > &&shape)
 
DLLEXPORT PhysicsShape (std::unique_ptr< btCompoundShape > &&shape)
 
- Protected Member Functions inherited from Leviathan::ReferenceCounted
DLLEXPORT ReferenceCounted ()
 
virtual DLLEXPORT ~ReferenceCounted ()
 

Protected Attributes

friend ReferenceCounted
 

Friends

class PhysicalWorld
 

Additional Inherited Members

- Public Types inherited from Leviathan::ReferenceCounted
using basepointer = boost::intrusive_ptr< ReferenceCounted >
 
using refcountedpointer = boost::intrusive_ptr< ReferenceCounted >
 
- Static Public Member Functions inherited from Leviathan::ReferenceCounted
template<class ActualType >
static boost::intrusive_ptr< ActualType > WrapPtr (ActualType *ptr)
 Creates an intrusive_ptr from raw pointer. More...
 
template<class ActualType , class... Args>
static boost::intrusive_ptr< ActualType > MakeShared (Args &&... args)
 Constructs a new instance and wraps it. More...
 

Detailed Description

A physical shape that can be used to create PhysicsBody objects.

Definition at line 17 of file PhysicsShape.h.

Constructor & Destructor Documentation

◆ PhysicsShape() [1/2]

DLLEXPORT PhysicsShape::PhysicsShape ( std::unique_ptr< btCollisionShape > &&  shape)
protected

Definition at line 9 of file PhysicsShape.cpp.

9  :
10  Shape1(std::move(shape))
11 {}

◆ PhysicsShape() [2/2]

DLLEXPORT PhysicsShape::PhysicsShape ( std::unique_ptr< btCompoundShape > &&  shape)
protected

Definition at line 13 of file PhysicsShape.cpp.

13  :
14  Shape1(std::move(shape)), Compound(true)
15 {}

Member Function Documentation

◆ AddChildShape()

DLLEXPORT bool PhysicsShape::AddChildShape ( const PhysicsShape::pointer &  child,
const Float3 offset = Float3(0, 0, 0),
const Float4 orientation = Float4::IdentityQuaternion() 
)

Definition at line 17 of file PhysicsShape.cpp.

20 {
21  if(!Compound || !child)
22  return false;
23 
24  // Let's stop some silliness
25  if(child.get() == this) {
26  LOG_ERROR("PhysicsShape: AddChildShape: can't add 'this' as child");
27  return false;
28  }
29 
30  btTransform transform;
31  transform.setIdentity();
32 
33  transform.setRotation(orientation);
34  transform.setOrigin(offset);
35 
36  static_cast<btCompoundShape*>(Shape1.get())->addChildShape(transform, child->GetShape());
37 
38  ChildShapes.emplace_back(child);
39  return true;
40 }
#define LOG_ERROR(x)
Definition: Define.h:94

◆ AddChildShapeWrapper()

DLLEXPORT bool Leviathan::PhysicsShape::AddChildShapeWrapper ( PhysicsShape child,
const Float3 offset = Float3(0, 0, 0),
const Float4 orientation = Float4::IdentityQuaternion() 
)
inline

Definition at line 68 of file PhysicsShape.h.

71  {
72  return AddChildShape(ReferenceCounted::WrapPtr(child), offset, orientation);
73  }
DLLEXPORT bool AddChildShape(const PhysicsShape::pointer &child, const Float3 &offset=Float3(0, 0, 0), const Float4 &orientation=Float4::IdentityQuaternion())
static boost::intrusive_ptr< ActualType > WrapPtr(ActualType *ptr)
Creates an intrusive_ptr from raw pointer.

◆ FindChildShapeIndex()

DLLEXPORT int PhysicsShape::FindChildShapeIndex ( PhysicsShape child)

Finds the index that the child shape occupies.

This is useful for compound shape contact callbacks to determine which child shape collided

Returns
-1 if not found

Definition at line 67 of file PhysicsShape.cpp.

68 {
69  if(!Compound || !child)
70  return -1;
71 
72  const btCollisionShape* childPtr = child->GetShape();
73 
74  auto* casted = static_cast<btCompoundShape*>(Shape1.get());
75 
76  auto children = casted->getChildList();
77 
78  const auto count = casted->getNumChildShapes();
79 
80  for(int i = 0; i < count; ++i) {
81 
82  if(children[i].m_childShape == childPtr) {
83  return i;
84  }
85  }
86 
87  return -1;
88 }
DLLEXPORT btCollisionShape * GetShape()
Definition: PhysicsShape.h:26

◆ FindChildShapeIndexWrapper()

DLLEXPORT int Leviathan::PhysicsShape::FindChildShapeIndexWrapper ( PhysicsShape child)
inline

Definition at line 75 of file PhysicsShape.h.

76  {
77  const auto result = FindChildShapeIndex(child);
78 
79  if(child)
80  child->Release();
81 
82  return result;
83  }
DLLEXPORT int FindChildShapeIndex(PhysicsShape *child)
Finds the index that the child shape occupies.

◆ GetChildByIndex()

DLLEXPORT PhysicsShape::pointer PhysicsShape::GetChildByIndex ( size_t  index)
Note
This assumes that AddChildShape and RemoveChildShape properly update ChildShapes indexes to match what bullet stores internally

Definition at line 42 of file PhysicsShape.cpp.

43 {
44  if(!Compound || ChildShapes.size() <= index)
45  return nullptr;
46  return ChildShapes[index];
47 }

◆ GetChildCustomTag()

DLLEXPORT int PhysicsShape::GetChildCustomTag ( size_t  index) const

Calls GetCustomTag on the child at index. If invalid index returns -1.

See also
GetChildByIndex

Definition at line 90 of file PhysicsShape.cpp.

91 {
92  if(!Compound || ChildShapes.size() <= index)
93  return -1;
94  return ChildShapes[index]->GetCustomTag();
95 }

◆ GetCustomTag()

DLLEXPORT int Leviathan::PhysicsShape::GetCustomTag ( ) const
inline

Custom tags allow storing one int of application specific info in this class.

Definition at line 55 of file PhysicsShape.h.

56  {
57  return CustomData;
58  }

◆ GetShape()

DLLEXPORT btCollisionShape* Leviathan::PhysicsShape::GetShape ( )
inline

Definition at line 26 of file PhysicsShape.h.

27  {
28  return Shape1.get();
29  }

◆ REFERENCE_COUNTED_PTR_TYPE()

Leviathan::PhysicsShape::REFERENCE_COUNTED_PTR_TYPE ( PhysicsShape  )

◆ RemoveChildShape()

DLLEXPORT bool PhysicsShape::RemoveChildShape ( PhysicsShape child)

Definition at line 49 of file PhysicsShape.cpp.

50 {
51  if(!Compound)
52  return false;
53 
54  for(auto iter = ChildShapes.begin(); iter != ChildShapes.end(); ++iter) {
55 
56  if(iter->get() == child) {
57 
58  static_cast<btCompoundShape*>(Shape1.get())->removeChildShape((*iter)->GetShape());
59  ChildShapes.erase(iter);
60  return true;
61  }
62  }
63 
64  return false;
65 }

◆ SetCustomTag()

DLLEXPORT void Leviathan::PhysicsShape::SetCustomTag ( int  value)
inline

Definition at line 60 of file PhysicsShape.h.

61  {
62  CustomData = value;
63  }

Friends And Related Function Documentation

◆ PhysicalWorld

friend class PhysicalWorld
friend

Definition at line 18 of file PhysicsShape.h.

Member Data Documentation

◆ ReferenceCounted

friend Leviathan::PhysicsShape::ReferenceCounted
protected

Definition at line 21 of file PhysicsShape.h.


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