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 bool AddChildShapeWrapper (PhysicsShape *child, const Float3 &offset=Float3(0, 0, 0), const Float4 &orientation=Float4::IdentityQuaternion())
 
- Public Member Functions inherited from Leviathan::ReferenceCounted
 ReferenceCounted (const ReferenceCounted &other)=delete
 
ReferenceCountedoperator= (const ReferenceCounted &other)=delete
 
FORCE_INLINE void AddRef ()
 
FORCE_INLINE void Release ()
 removes a reference and deletes the object if reference count reaches zero More...
 
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:84

◆ AddChildShapeWrapper()

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

Definition at line 41 of file PhysicsShape.h.

44  {
45  return AddChildShape(ReferenceCounted::WrapPtr(child), offset, orientation);
46  }
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.

◆ 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 42 of file PhysicsShape.cpp.

43 {
44  if(!Compound)
45  return false;
46 
47  for(auto iter = ChildShapes.begin(); iter != ChildShapes.end(); ++iter) {
48 
49  if(iter->get() == child) {
50 
51  static_cast<btCompoundShape*>(Shape1.get())->removeChildShape((*iter)->GetShape());
52  ChildShapes.erase(iter);
53  return true;
54  }
55  }
56 
57  return false;
58 }

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: