Physical2D.cpp
Go to the documentation of this file.
1 #include "Physical2D.hpp"
2 
3 namespace comp
4 {
5 
6 //--------------------- Physical2D -------------------------------------------------
8  entity( nullptr ),
9  body( nullptr ),
10  cm( owner ),
11  _world( nullptr )
12 {
13 }
14 
15 void Physical2D::Register( Physical2D_World * world, playrho::d2::BodyConf const & conf )
16 {
17  if( this->_world )
18  {
19  this->cm->warning( SRC_INFO, "This Physical2D is already registered to a world." );
20  return;
21  }
22 
23  this->_world = world;
24  this->body = this->_world->CreateBody( this, conf );
25  this->_world->Register( this );
26 }
27 
29 {
30  if( !this->_world )
31  return;
32 
33  this->_world->Unregister( this );
34  this->_world->DestroyBody( this->body );
35  this->body = nullptr;
36  this->_world = nullptr;
37 }
38 
40 {
41  return this->cm;
42 }
43 
45 {
46  return this->_world;
47 }
48 
50 {
51  return this->_world;
52 }
53 
54 //--------------------- Physical2D_Listener -------------------------------------------------
56  iv::GenericListener< Physical2D_Listener >( inst, world ),
57  cm( inst, this, "Physical2D_Listener" )
58 {
60 }
61 
62 //--------------------- Physical2D_World -------------------------------------------------
64  iv::World< Physical2D >( inst ),
65  iv::GenericListener_Index< Physical2D_Listener >( inst ),
66  playrho::d2::ContactListener(),
67  cm( inst, this, "Physical2D_World" ),
68  world()
69 {
71  this->world.SetContactListener( this );
72 }
73 
74 void Physical2D_World::Step( float timeStep )
75 {
76  playrho::StepConf conf;
77  conf.SetTime( timeStep );
78  this->world.Step( conf );
79 }
80 
81 playrho::d2::Body * Physical2D_World::CreateBody( Physical2D * component, playrho::d2::BodyConf const & conf )
82 {
83  auto body = this->world.CreateBody( conf );
84  body->SetUserData( reinterpret_cast< void * >( component ) );
85  return body;
86 }
87 
88 void Physical2D_World::DestroyBody( playrho::d2::Body * body )
89 {
90  this->world.Destroy( body );
91 }
92 
94 {
95 }
96 
98 {
99 }
100 
101 void Physical2D_World::BeginContact( playrho::d2::Contact & contact )
102 {
103  playrho::d2::Body * bodyA = contact.GetFixtureA()->GetBody();
104  playrho::d2::Body * bodyB = contact.GetFixtureB()->GetBody();
105  Physical2D * phyA = reinterpret_cast< Physical2D * >( bodyA->GetUserData() );
106  Physical2D * phyB = reinterpret_cast< Physical2D * >( bodyB->GetUserData() );
107 
109 }
110 
111 void Physical2D_World::EndContact( playrho::d2::Contact & contact )
112 {
113  playrho::d2::Body * bodyA = contact.GetFixtureA()->GetBody();
114  playrho::d2::Body * bodyB = contact.GetFixtureB()->GetBody();
115  Physical2D * phyA = reinterpret_cast< Physical2D * >( bodyA->GetUserData() );
116  Physical2D * phyB = reinterpret_cast< Physical2D * >( bodyB->GetUserData() );
117 
119 }
120 
121 }