remove 'Physic' prefix

This commit is contained in:
Nomango 2019-11-06 16:29:36 +08:00
parent 06554f1378
commit 4667333e7c
14 changed files with 460 additions and 460 deletions

View File

@ -26,7 +26,7 @@ namespace kiwano
namespace physics namespace physics
{ {
PhysicBody::PhysicBody() Body::Body()
: body_(nullptr) : body_(nullptr)
, actor_(nullptr) , actor_(nullptr)
, world_(nullptr) , world_(nullptr)
@ -36,25 +36,25 @@ namespace kiwano
{ {
} }
PhysicBody::PhysicBody(b2Body* body, Actor* actor) Body::Body(b2Body* body, Actor* actor)
: PhysicBody() : Body()
{ {
SetB2Body(body); SetB2Body(body);
SetActor(actor); SetActor(actor);
} }
PhysicBody::PhysicBody(PhysicWorld* world, Actor* actor) Body::Body(World* world, Actor* actor)
: PhysicBody() : Body()
{ {
Init(world, actor); Init(world, actor);
} }
PhysicBody::~PhysicBody() Body::~Body()
{ {
Destroy(); Destroy();
} }
void PhysicBody::Init(PhysicWorld* world, Actor* actor) void Body::Init(World* world, Actor* actor)
{ {
KGE_ASSERT(world); KGE_ASSERT(world);
@ -69,38 +69,38 @@ namespace kiwano
UpdateFromActor(); UpdateFromActor();
} }
PhysicFixture PhysicBody::AddFixture(PhysicShape* shape, const PhysicFixture::Param& param) Fixture Body::AddFixture(Shape* shape, const Fixture::Param& param)
{ {
KGE_ASSERT(body_ && world_); KGE_ASSERT(body_ && world_);
return PhysicFixture(this, shape, param); return Fixture(this, shape, param);
} }
PhysicFixture PhysicBody::AddCircleShape(float radius, float density) Fixture Body::AddCircleShape(float radius, float density)
{ {
return AddFixture(&PhysicCircleShape(radius), PhysicFixture::Param(density)); return AddFixture(&CircleShape(radius), Fixture::Param(density));
} }
PhysicFixture PhysicBody::AddBoxShape(Vec2 const& size, float density) Fixture Body::AddBoxShape(Vec2 const& size, float density)
{ {
return AddFixture(&PhysicBoxShape(size), PhysicFixture::Param(density)); return AddFixture(&BoxShape(size), Fixture::Param(density));
} }
PhysicFixture PhysicBody::AddPolygonShape(Vector<Point> const& vertexs, float density) Fixture Body::AddPolygonShape(Vector<Point> const& vertexs, float density)
{ {
return AddFixture(&PhysicPolygonShape(vertexs), PhysicFixture::Param(density)); return AddFixture(&PolygonShape(vertexs), Fixture::Param(density));
} }
PhysicFixture PhysicBody::AddEdgeShape(Point const& p1, Point const& p2, float density) Fixture Body::AddEdgeShape(Point const& p1, Point const& p2, float density)
{ {
return AddFixture(&PhysicEdgeShape(p1, p2), PhysicFixture::Param(density)); return AddFixture(&EdgeShape(p1, p2), Fixture::Param(density));
} }
PhysicFixture PhysicBody::AddChainShape(Vector<Point> const& vertexs, bool loop, float density) Fixture Body::AddChainShape(Vector<Point> const& vertexs, bool loop, float density)
{ {
return AddFixture(&PhysicChainShape(vertexs, loop), PhysicFixture::Param(density)); return AddFixture(&ChainShape(vertexs, loop), Fixture::Param(density));
} }
void PhysicBody::RemoveFixture(PhysicFixture const& fixture) void Body::RemoveFixture(Fixture const& fixture)
{ {
if (fixture.GetB2Fixture()) if (fixture.GetB2Fixture())
{ {
@ -109,7 +109,7 @@ namespace kiwano
} }
} }
void PhysicBody::SetCategoryBits(uint16_t category_bits) void Body::SetCategoryBits(uint16_t category_bits)
{ {
KGE_ASSERT(body_); KGE_ASSERT(body_);
@ -126,7 +126,7 @@ namespace kiwano
} }
} }
void PhysicBody::SetMaskBits(uint16_t mask_bits) void Body::SetMaskBits(uint16_t mask_bits)
{ {
KGE_ASSERT(body_); KGE_ASSERT(body_);
@ -143,7 +143,7 @@ namespace kiwano
} }
} }
void PhysicBody::SetGroupIndex(int16_t index) void Body::SetGroupIndex(int16_t index)
{ {
KGE_ASSERT(body_); KGE_ASSERT(body_);
@ -160,7 +160,7 @@ namespace kiwano
} }
} }
void PhysicBody::GetMassData(float* mass, Point* center, float* inertia) const void Body::GetMassData(float* mass, Point* center, float* inertia) const
{ {
KGE_ASSERT(body_ && world_); KGE_ASSERT(body_ && world_);
@ -172,7 +172,7 @@ namespace kiwano
if (inertia) *inertia = data.I; if (inertia) *inertia = data.I;
} }
void PhysicBody::SetMassData(float mass, Point const& center, float inertia) void Body::SetMassData(float mass, Point const& center, float inertia)
{ {
KGE_ASSERT(body_ && world_); KGE_ASSERT(body_ && world_);
@ -183,67 +183,67 @@ namespace kiwano
body_->SetMassData(&data); body_->SetMassData(&data);
} }
void PhysicBody::ResetMassData() void Body::ResetMassData()
{ {
KGE_ASSERT(body_); KGE_ASSERT(body_);
body_->ResetMassData(); body_->ResetMassData();
} }
Point PhysicBody::GetBodyPosition() const Point Body::GetBodyPosition() const
{ {
KGE_ASSERT(body_ && world_); KGE_ASSERT(body_ && world_);
return world_->World2Stage(body_->GetPosition()); return world_->World2Stage(body_->GetPosition());
} }
void PhysicBody::SetBodyTransform(Point const& pos, float angle) void Body::SetBodyTransform(Point const& pos, float angle)
{ {
KGE_ASSERT(body_ && world_); KGE_ASSERT(body_ && world_);
body_->SetTransform(world_->Stage2World(pos), math::Degree2Radian(angle)); body_->SetTransform(world_->Stage2World(pos), math::Degree2Radian(angle));
} }
Point PhysicBody::GetLocalPoint(Point const& world) const Point Body::GetLocalPoint(Point const& world) const
{ {
KGE_ASSERT(body_ && world_); KGE_ASSERT(body_ && world_);
return world_->World2Stage(body_->GetLocalPoint(world_->Stage2World(world))); return world_->World2Stage(body_->GetLocalPoint(world_->Stage2World(world)));
} }
Point PhysicBody::GetWorldPoint(Point const& local) const Point Body::GetWorldPoint(Point const& local) const
{ {
KGE_ASSERT(body_ && world_); KGE_ASSERT(body_ && world_);
return world_->World2Stage(body_->GetWorldPoint(world_->Stage2World(local))); return world_->World2Stage(body_->GetWorldPoint(world_->Stage2World(local)));
} }
Point PhysicBody::GetLocalCenter() const Point Body::GetLocalCenter() const
{ {
KGE_ASSERT(body_ && world_); KGE_ASSERT(body_ && world_);
return world_->World2Stage(body_->GetLocalCenter()); return world_->World2Stage(body_->GetLocalCenter());
} }
Point PhysicBody::GetWorldCenter() const Point Body::GetWorldCenter() const
{ {
KGE_ASSERT(body_ && world_); KGE_ASSERT(body_ && world_);
return world_->World2Stage(body_->GetWorldCenter()); return world_->World2Stage(body_->GetWorldCenter());
} }
void PhysicBody::ApplyForce(Vec2 const& force, Point const& point, bool wake) void Body::ApplyForce(Vec2 const& force, Point const& point, bool wake)
{ {
KGE_ASSERT(body_ && world_); KGE_ASSERT(body_ && world_);
body_->ApplyForce(b2Vec2(force.x, force.y), world_->Stage2World(point), wake); body_->ApplyForce(b2Vec2(force.x, force.y), world_->Stage2World(point), wake);
} }
void PhysicBody::ApplyForceToCenter(Vec2 const& force, bool wake) void Body::ApplyForceToCenter(Vec2 const& force, bool wake)
{ {
KGE_ASSERT(body_ && world_); KGE_ASSERT(body_ && world_);
body_->ApplyForceToCenter(b2Vec2(force.x, force.y), wake); body_->ApplyForceToCenter(b2Vec2(force.x, force.y), wake);
} }
void PhysicBody::ApplyTorque(float torque, bool wake) void Body::ApplyTorque(float torque, bool wake)
{ {
KGE_ASSERT(body_ && world_); KGE_ASSERT(body_ && world_);
body_->ApplyTorque(torque, wake); body_->ApplyTorque(torque, wake);
} }
void PhysicBody::SetB2Body(b2Body* body) void Body::SetB2Body(b2Body* body)
{ {
body_ = body; body_ = body;
if (body_) if (body_)
@ -252,7 +252,7 @@ namespace kiwano
} }
} }
void PhysicBody::Destroy() void Body::Destroy()
{ {
if (world_) if (world_)
{ {
@ -264,7 +264,7 @@ namespace kiwano
actor_ = nullptr; actor_ = nullptr;
} }
void PhysicBody::UpdateActor() void Body::UpdateActor()
{ {
if (actor_ && body_) if (actor_ && body_)
{ {
@ -280,7 +280,7 @@ namespace kiwano
} }
} }
void PhysicBody::UpdateFromActor() void Body::UpdateFromActor()
{ {
if (actor_ && body_) if (actor_ && body_)
{ {
@ -301,7 +301,7 @@ namespace kiwano
} }
} }
void PhysicBody::UpdateFixtureFilter(b2Fixture* fixture) void Body::UpdateFixtureFilter(b2Fixture* fixture)
{ {
b2Filter filter; b2Filter filter;
filter.categoryBits = category_bits_; filter.categoryBits = category_bits_;

View File

@ -28,11 +28,11 @@ namespace kiwano
{ {
namespace physics namespace physics
{ {
class PhysicWorld; class World;
// 膠竟 // 膠竟
KGE_DECLARE_SMART_PTR(PhysicBody); KGE_DECLARE_SMART_PTR(Body);
class KGE_API PhysicBody class KGE_API Body
: public virtual RefCounter : public virtual RefCounter
{ {
public: public:
@ -43,33 +43,33 @@ namespace kiwano
Dynamic, Dynamic,
}; };
PhysicBody(); Body();
PhysicBody(b2Body* body, Actor* actor); Body(b2Body* body, Actor* actor);
PhysicBody(PhysicWorld* world, Actor* actor); Body(World* world, Actor* actor);
PhysicBody(PhysicWorld* world, ActorPtr actor) : PhysicBody(world, actor.get()) {} Body(World* world, ActorPtr actor) : Body(world, actor.get()) {}
virtual ~PhysicBody(); virtual ~Body();
// 놓迦뺏 // 놓迦뺏
void Init(PhysicWorld* world, Actor* actor); void Init(World* world, Actor* actor);
// 警속셸야 // 警속셸야
PhysicFixture AddFixture(PhysicShape* shape, const PhysicFixture::Param& param); Fixture AddFixture(Shape* shape, const Fixture::Param& param);
// 警속近榴 // 警속近榴
PhysicFixture AddCircleShape(float radius, float density = 0.f); Fixture AddCircleShape(float radius, float density = 0.f);
PhysicFixture AddBoxShape(Vec2 const& size, float density = 0.f); Fixture AddBoxShape(Vec2 const& size, float density = 0.f);
PhysicFixture AddPolygonShape(Vector<Point> const& vertexs, float density = 0.f); Fixture AddPolygonShape(Vector<Point> const& vertexs, float density = 0.f);
PhysicFixture AddEdgeShape(Point const& p1, Point const& p2, float density = 0.f); Fixture AddEdgeShape(Point const& p1, Point const& p2, float density = 0.f);
PhysicFixture AddChainShape(Vector<Point> const& vertexs, bool loop, float density = 0.f); Fixture AddChainShape(Vector<Point> const& vertexs, bool loop, float density = 0.f);
// 삿혤셸야 // 삿혤셸야
PhysicFixture GetFixtureList() const { KGE_ASSERT(body_); return PhysicFixture(body_->GetFixtureList()); } Fixture GetFixtureList() const { KGE_ASSERT(body_); return Fixture(body_->GetFixtureList()); }
// 盧뇜셸야 // 盧뇜셸야
void RemoveFixture(PhysicFixture const& fixture); void RemoveFixture(Fixture const& fixture);
// 삿혤쌈뇰긋 // 삿혤쌈뇰긋
PhysicContactEdge GetContactList() const { KGE_ASSERT(body_); PhysicContactEdge(body_->GetContactList()); } ContactEdge GetContactList() const { KGE_ASSERT(body_); ContactEdge(body_->GetContactList()); }
// 잚깎쯤 // 잚깎쯤
uint16_t GetCategoryBits() const { return category_bits_; } uint16_t GetCategoryBits() const { return category_bits_; }
@ -153,8 +153,8 @@ namespace kiwano
const b2Body* GetB2Body() const { return body_; } const b2Body* GetB2Body() const { return body_; }
void SetB2Body(b2Body* body); void SetB2Body(b2Body* body);
PhysicWorld* GetWorld() { return world_; } World* GetWorld() { return world_; }
const PhysicWorld* GetWorld() const { return world_; } const World* GetWorld() const { return world_; }
void Destroy(); void Destroy();
@ -166,7 +166,7 @@ namespace kiwano
protected: protected:
Actor* actor_; Actor* actor_;
PhysicWorld* world_; World* world_;
b2Body* body_; b2Body* body_;
uint16_t category_bits_; uint16_t category_bits_;

View File

@ -27,87 +27,87 @@ namespace kiwano
namespace physics namespace physics
{ {
PhysicContact::PhysicContact() Contact::Contact()
: contact_(nullptr) : contact_(nullptr)
{ {
} }
PhysicContact::PhysicContact(b2Contact* contact) Contact::Contact(b2Contact* contact)
: PhysicContact() : Contact()
{ {
SetB2Contact(contact); SetB2Contact(contact);
} }
PhysicContact PhysicContact::GetNext() Contact Contact::GetNext()
{ {
KGE_ASSERT(contact_); KGE_ASSERT(contact_);
return PhysicContact(contact_->GetNext()); return Contact(contact_->GetNext());
} }
const PhysicContact PhysicContact::GetNext() const const Contact Contact::GetNext() const
{ {
KGE_ASSERT(contact_); KGE_ASSERT(contact_);
return PhysicContact(contact_->GetNext()); return Contact(contact_->GetNext());
} }
PhysicFixture PhysicContact::GetFixtureA() Fixture Contact::GetFixtureA()
{ {
KGE_ASSERT(contact_); KGE_ASSERT(contact_);
return PhysicFixture(contact_->GetFixtureA()); return Fixture(contact_->GetFixtureA());
} }
const PhysicFixture PhysicContact::GetFixtureA() const const Fixture Contact::GetFixtureA() const
{ {
KGE_ASSERT(contact_); KGE_ASSERT(contact_);
return PhysicFixture(contact_->GetFixtureA()); return Fixture(contact_->GetFixtureA());
} }
PhysicFixture PhysicContact::GetFixtureB() Fixture Contact::GetFixtureB()
{ {
KGE_ASSERT(contact_); KGE_ASSERT(contact_);
return PhysicFixture(contact_->GetFixtureB()); return Fixture(contact_->GetFixtureB());
} }
const PhysicFixture PhysicContact::GetFixtureB() const const Fixture Contact::GetFixtureB() const
{ {
KGE_ASSERT(contact_); KGE_ASSERT(contact_);
return PhysicFixture(contact_->GetFixtureB()); return Fixture(contact_->GetFixtureB());
} }
void PhysicContact::SetTangentSpeed(float speed) void Contact::SetTangentSpeed(float speed)
{ {
KGE_ASSERT(contact_); KGE_ASSERT(contact_);
PhysicBody* body = GetFixtureA().GetBody(); Body* body = GetFixtureA().GetBody();
KGE_ASSERT(body); KGE_ASSERT(body);
PhysicWorld* world = body->GetWorld(); World* world = body->GetWorld();
KGE_ASSERT(world); KGE_ASSERT(world);
contact_->SetTangentSpeed(world->Stage2World(speed)); contact_->SetTangentSpeed(world->Stage2World(speed));
} }
float PhysicContact::GetTangentSpeed() const float Contact::GetTangentSpeed() const
{ {
KGE_ASSERT(contact_); KGE_ASSERT(contact_);
const PhysicBody* body = GetFixtureA().GetBody(); const Body* body = GetFixtureA().GetBody();
KGE_ASSERT(body); KGE_ASSERT(body);
const PhysicWorld* world = body->GetWorld(); const World* world = body->GetWorld();
KGE_ASSERT(world); KGE_ASSERT(world);
return world->World2Stage(contact_->GetTangentSpeed()); return world->World2Stage(contact_->GetTangentSpeed());
} }
PhysicContactEdge::PhysicContactEdge() ContactEdge::ContactEdge()
: edge_(nullptr) : edge_(nullptr)
{ {
} }
PhysicContactEdge::PhysicContactEdge(b2ContactEdge* edge) ContactEdge::ContactEdge(b2ContactEdge* edge)
: PhysicContactEdge() : ContactEdge()
{ {
SetB2ContactEdge(edge); SetB2ContactEdge(edge);
} }

View File

@ -26,14 +26,14 @@ namespace kiwano
{ {
namespace physics namespace physics
{ {
class PhysicBody; class Body;
// 接触 // 接触
class KGE_API PhysicContact class KGE_API Contact
{ {
public: public:
PhysicContact(); Contact();
PhysicContact(b2Contact* contact); Contact(b2Contact* contact);
// 是否是接触 // 是否是接触
bool IsTouching() const { KGE_ASSERT(contact_); return contact_->IsTouching(); } bool IsTouching() const { KGE_ASSERT(contact_); return contact_->IsTouching(); }
@ -43,16 +43,16 @@ namespace kiwano
bool IsEnabled() const { KGE_ASSERT(contact_); return contact_->IsEnabled(); } bool IsEnabled() const { KGE_ASSERT(contact_); return contact_->IsEnabled(); }
// 获取下一接触 // 获取下一接触
PhysicContact GetNext(); Contact GetNext();
const PhysicContact GetNext() const; const Contact GetNext() const;
// 夹具 A // 夹具 A
PhysicFixture GetFixtureA(); Fixture GetFixtureA();
const PhysicFixture GetFixtureA() const; const Fixture GetFixtureA() const;
// 夹具 B // 夹具 B
PhysicFixture GetFixtureB(); Fixture GetFixtureB();
const PhysicFixture GetFixtureB() const; const Fixture GetFixtureB() const;
// 摩擦 // 摩擦
void SetFriction(float friction) { KGE_ASSERT(contact_); contact_->SetFriction(friction); } void SetFriction(float friction) { KGE_ASSERT(contact_); contact_->SetFriction(friction); }
@ -78,27 +78,27 @@ namespace kiwano
// 接触边 // 接触边
class KGE_API PhysicContactEdge class KGE_API ContactEdge
{ {
public: public:
PhysicContactEdge(); ContactEdge();
PhysicContactEdge(b2ContactEdge* edge); ContactEdge(b2ContactEdge* edge);
// 获取接触物体 // 获取接触物体
PhysicBody* GetOtherBody() { KGE_ASSERT(edge_); return static_cast<PhysicBody*>(edge_->other->GetUserData()); } Body* GetOtherBody() { KGE_ASSERT(edge_); return static_cast<Body*>(edge_->other->GetUserData()); }
const PhysicBody* GetOtherBody() const { KGE_ASSERT(edge_); return static_cast<PhysicBody*>(edge_->other->GetUserData()); } const Body* GetOtherBody() const { KGE_ASSERT(edge_); return static_cast<Body*>(edge_->other->GetUserData()); }
// 获取接触 // 获取接触
PhysicContact GetContact() { KGE_ASSERT(edge_); return PhysicContact(edge_->contact); } Contact GetContact() { KGE_ASSERT(edge_); return Contact(edge_->contact); }
const PhysicContact GetContact() const { KGE_ASSERT(edge_); return PhysicContact(edge_->contact); } const Contact GetContact() const { KGE_ASSERT(edge_); return Contact(edge_->contact); }
// 获取上一接触边 // 获取上一接触边
PhysicContactEdge GetPrev() { KGE_ASSERT(edge_); return PhysicContactEdge(edge_->prev); } ContactEdge GetPrev() { KGE_ASSERT(edge_); return ContactEdge(edge_->prev); }
const PhysicContactEdge GetPrev() const { KGE_ASSERT(edge_); return PhysicContactEdge(edge_->prev); } const ContactEdge GetPrev() const { KGE_ASSERT(edge_); return ContactEdge(edge_->prev); }
// 获取下一接触边 // 获取下一接触边
PhysicContactEdge GetNext() { KGE_ASSERT(edge_); return PhysicContactEdge(edge_->next); } ContactEdge GetNext() { KGE_ASSERT(edge_); return ContactEdge(edge_->next); }
const PhysicContactEdge GetNext() const { KGE_ASSERT(edge_); return PhysicContactEdge(edge_->next); } const ContactEdge GetNext() const { KGE_ASSERT(edge_); return ContactEdge(edge_->next); }
b2ContactEdge* GetB2ContactEdge() { return edge_; } b2ContactEdge* GetB2ContactEdge() { return edge_; }
const b2ContactEdge* GetB2ContactEdge() const { return edge_; } const b2ContactEdge* GetB2ContactEdge() const { return edge_; }

View File

@ -26,31 +26,31 @@ namespace kiwano
{ {
namespace physics namespace physics
{ {
PhysicContactListener::PhysicContactListener() ContactListener::ContactListener()
: running_(true) : running_(true)
{ {
} }
PhysicContactListener::~PhysicContactListener() ContactListener::~ContactListener()
{ {
} }
PhysicContactCallbackListener::PhysicContactCallbackListener() ContactCallbackListener::ContactCallbackListener()
{ {
} }
PhysicContactCallbackListener::~PhysicContactCallbackListener() ContactCallbackListener::~ContactCallbackListener()
{ {
} }
PhysicContactListener* PhysicContactDispatcher::AddContactListener(PhysicContactListenerPtr listener) ContactListener* ContactDispatcher::AddContactListener(ContactListenerPtr listener)
{ {
return AddContactListener(listener.get()); return AddContactListener(listener.get());
} }
PhysicContactListener* PhysicContactDispatcher::AddContactListener(PhysicContactListener* listener) ContactListener* ContactDispatcher::AddContactListener(ContactListener* listener)
{ {
KGE_ASSERT(listener && "AddListener failed, NULL pointer exception"); KGE_ASSERT(listener && "AddListener failed, NULL pointer exception");
@ -61,7 +61,7 @@ namespace kiwano
return listener; return listener;
} }
void PhysicContactDispatcher::StartContactListeners(String const& listener_name) void ContactDispatcher::StartContactListeners(String const& listener_name)
{ {
for (auto listener : listeners_) for (auto listener : listeners_)
{ {
@ -72,7 +72,7 @@ namespace kiwano
} }
} }
void PhysicContactDispatcher::StopContactListeners(String const& listener_name) void ContactDispatcher::StopContactListeners(String const& listener_name)
{ {
for (auto listener : listeners_) for (auto listener : listeners_)
{ {
@ -83,9 +83,9 @@ namespace kiwano
} }
} }
void PhysicContactDispatcher::RemoveContactListeners(String const& listener_name) void ContactDispatcher::RemoveContactListeners(String const& listener_name)
{ {
PhysicContactListenerPtr next; ContactListenerPtr next;
for (auto listener = listeners_.first_item(); listener; listener = next) for (auto listener = listeners_.first_item(); listener; listener = next)
{ {
next = listener->next_item(); next = listener->next_item();
@ -97,7 +97,7 @@ namespace kiwano
} }
} }
void PhysicContactDispatcher::StartAllContactListeners() void ContactDispatcher::StartAllContactListeners()
{ {
for (auto listener : listeners_) for (auto listener : listeners_)
{ {
@ -105,7 +105,7 @@ namespace kiwano
} }
} }
void PhysicContactDispatcher::StopAllContactListeners() void ContactDispatcher::StopAllContactListeners()
{ {
for (auto listener : listeners_) for (auto listener : listeners_)
{ {
@ -113,18 +113,18 @@ namespace kiwano
} }
} }
void PhysicContactDispatcher::RemoveAllContactListeners() void ContactDispatcher::RemoveAllContactListeners()
{ {
listeners_.clear(); listeners_.clear();
} }
void PhysicContactDispatcher::OnContactBegin(b2Contact* b2contact) void ContactDispatcher::OnContactBegin(b2Contact* b2contact)
{ {
if (listeners_.empty()) if (listeners_.empty())
return; return;
PhysicContact contact(b2contact); Contact contact(b2contact);
PhysicContactListenerPtr next; ContactListenerPtr next;
for (auto listener = listeners_.first_item(); listener; listener = next) for (auto listener = listeners_.first_item(); listener; listener = next)
{ {
next = listener->next_item(); next = listener->next_item();
@ -136,13 +136,13 @@ namespace kiwano
} }
} }
void PhysicContactDispatcher::OnContactEnd(b2Contact* b2contact) void ContactDispatcher::OnContactEnd(b2Contact* b2contact)
{ {
if (listeners_.empty()) if (listeners_.empty())
return; return;
PhysicContact contact(b2contact); Contact contact(b2contact);
PhysicContactListenerPtr next; ContactListenerPtr next;
for (auto listener = listeners_.first_item(); listener; listener = next) for (auto listener = listeners_.first_item(); listener; listener = next)
{ {
next = listener->next_item(); next = listener->next_item();

View File

@ -25,27 +25,27 @@ namespace kiwano
{ {
namespace physics namespace physics
{ {
class PhysicContactDispatcher; class ContactDispatcher;
KGE_DECLARE_SMART_PTR(PhysicContactListener); KGE_DECLARE_SMART_PTR(ContactListener);
// 接触监听器 // 接触监听器
class KGE_API PhysicContactListener class KGE_API ContactListener
: public ObjectBase : public ObjectBase
, protected IntrusiveListItem<PhysicContactListenerPtr> , protected IntrusiveListItem<ContactListenerPtr>
{ {
friend IntrusiveList<PhysicContactListenerPtr>; friend IntrusiveList<ContactListenerPtr>;
friend class PhysicContactDispatcher; friend class ContactDispatcher;
public: public:
PhysicContactListener(); ContactListener();
virtual ~PhysicContactListener(); virtual ~ContactListener();
// 接触开始 // 接触开始
virtual void OnContactBegin(PhysicContact contact) { KGE_NOT_USED(contact); } virtual void OnContactBegin(Contact contact) { KGE_NOT_USED(contact); }
// 接触结束 // 接触结束
virtual void OnContactEnd(PhysicContact contact) { KGE_NOT_USED(contact); } virtual void OnContactEnd(Contact contact) { KGE_NOT_USED(contact); }
inline void Start() { running_ = true; } inline void Start() { running_ = true; }
inline void Stop() { running_ = true; } inline void Stop() { running_ = true; }
@ -56,21 +56,21 @@ namespace kiwano
}; };
KGE_DECLARE_SMART_PTR(PhysicContactCallbackListener); KGE_DECLARE_SMART_PTR(ContactCallbackListener);
// 接触回调监听器 // 接触回调监听器
class KGE_API PhysicContactCallbackListener class KGE_API ContactCallbackListener
: public PhysicContactListener : public ContactListener
{ {
friend IntrusiveList<PhysicContactListenerPtr>; friend IntrusiveList<ContactListenerPtr>;
friend class PhysicContactDispatcher; friend class ContactDispatcher;
public: public:
using ContactBeginCallback = Function<void(PhysicContact)>; using ContactBeginCallback = Function<void(Contact)>;
using ContactEndCallback = Function<void(PhysicContact)>; using ContactEndCallback = Function<void(Contact)>;
PhysicContactCallbackListener(); ContactCallbackListener();
virtual ~PhysicContactCallbackListener(); virtual ~ContactCallbackListener();
// 接触开始回调 // 接触开始回调
void SetCallbackOnContactBegin(ContactBeginCallback const& cb) { begin_ = cb; } void SetCallbackOnContactBegin(ContactBeginCallback const& cb) { begin_ = cb; }
@ -80,8 +80,8 @@ namespace kiwano
void SetCallbackOnContactEnd(ContactEndCallback const& cb) { end_ = cb; } void SetCallbackOnContactEnd(ContactEndCallback const& cb) { end_ = cb; }
ContactEndCallback GetCallbackOnContactEnd() const { return end_; } ContactEndCallback GetCallbackOnContactEnd() const { return end_; }
void OnContactBegin(PhysicContact contact) override { if (begin_) begin_(contact); } void OnContactBegin(Contact contact) override { if (begin_) begin_(contact); }
void OnContactEnd(PhysicContact contact) override { if (end_) end_(contact); } void OnContactEnd(Contact contact) override { if (end_) end_(contact); }
protected: protected:
ContactBeginCallback begin_; ContactBeginCallback begin_;
@ -90,19 +90,19 @@ namespace kiwano
// 接触分发器 // 接触分发器
class KGE_API PhysicContactDispatcher class KGE_API ContactDispatcher
{ {
public: public:
using Listeners = IntrusiveList<PhysicContactListenerPtr>; using Listeners = IntrusiveList<ContactListenerPtr>;
// 添加监听器 // 添加监听器
PhysicContactListener* AddContactListener( ContactListener* AddContactListener(
PhysicContactListenerPtr listener ContactListenerPtr listener
); );
// 添加监听器 // 添加监听器
PhysicContactListener* AddContactListener( ContactListener* AddContactListener(
PhysicContactListener* listener ContactListener* listener
); );
// 启动监听器 // 启动监听器

View File

@ -27,19 +27,19 @@ namespace kiwano
namespace physics namespace physics
{ {
PhysicFixture::PhysicFixture() Fixture::Fixture()
: fixture_(nullptr) : fixture_(nullptr)
{ {
} }
PhysicFixture::PhysicFixture(b2Fixture* fixture) Fixture::Fixture(b2Fixture* fixture)
: PhysicFixture() : Fixture()
{ {
SetB2Fixture(fixture); SetB2Fixture(fixture);
} }
PhysicFixture::PhysicFixture(PhysicBody* body, PhysicShape* shape, const Param& param) Fixture::Fixture(Body* body, Shape* shape, const Param& param)
: PhysicFixture() : Fixture()
{ {
KGE_ASSERT(body); KGE_ASSERT(body);
@ -58,38 +58,38 @@ namespace kiwano
} }
} }
PhysicBody* PhysicFixture::GetBody() Body* Fixture::GetBody()
{ {
KGE_ASSERT(fixture_); KGE_ASSERT(fixture_);
return static_cast<PhysicBody*>(fixture_->GetBody()->GetUserData()); return static_cast<Body*>(fixture_->GetBody()->GetUserData());
} }
const PhysicBody* PhysicFixture::GetBody() const const Body* Fixture::GetBody() const
{ {
KGE_ASSERT(fixture_); KGE_ASSERT(fixture_);
return static_cast<const PhysicBody*>(fixture_->GetBody()->GetUserData()); return static_cast<const Body*>(fixture_->GetBody()->GetUserData());
} }
PhysicShape PhysicFixture::GetShape() const Shape Fixture::GetShape() const
{ {
KGE_ASSERT(fixture_); KGE_ASSERT(fixture_);
return PhysicShape(fixture_->GetShape()); return Shape(fixture_->GetShape());
} }
PhysicFixture PhysicFixture::GetNext() const Fixture Fixture::GetNext() const
{ {
KGE_ASSERT(fixture_); KGE_ASSERT(fixture_);
return PhysicFixture(fixture_->GetNext()); return Fixture(fixture_->GetNext());
} }
void PhysicFixture::GetMassData(float* mass, Point* center, float* inertia) const void Fixture::GetMassData(float* mass, Point* center, float* inertia) const
{ {
KGE_ASSERT(fixture_); KGE_ASSERT(fixture_);
const PhysicBody* body = GetBody(); const Body* body = GetBody();
KGE_ASSERT(body); KGE_ASSERT(body);
const PhysicWorld* world = body->GetWorld(); const World* world = body->GetWorld();
KGE_ASSERT(world); KGE_ASSERT(world);
b2MassData data; b2MassData data;
@ -100,14 +100,14 @@ namespace kiwano
if (inertia) *inertia = data.I; if (inertia) *inertia = data.I;
} }
bool PhysicFixture::TestPoint(const Point& p) const bool Fixture::TestPoint(const Point& p) const
{ {
KGE_ASSERT(fixture_); KGE_ASSERT(fixture_);
const PhysicBody* body = GetBody(); const Body* body = GetBody();
KGE_ASSERT(body); KGE_ASSERT(body);
const PhysicWorld* world = body->GetWorld(); const World* world = body->GetWorld();
KGE_ASSERT(world); KGE_ASSERT(world);
return fixture_->TestPoint(world->Stage2World(p)); return fixture_->TestPoint(world->Stage2World(p));

View File

@ -26,10 +26,10 @@ namespace kiwano
{ {
namespace physics namespace physics
{ {
class PhysicBody; class Body;
// 夹具 // 夹具
class PhysicFixture class Fixture
{ {
public: public:
struct Param struct Param
@ -49,19 +49,19 @@ namespace kiwano
{} {}
}; };
PhysicFixture(); Fixture();
PhysicFixture(b2Fixture* fixture); Fixture(b2Fixture* fixture);
PhysicFixture(PhysicBody* body, PhysicShape* shape, const Param& param); Fixture(Body* body, Shape* shape, const Param& param);
// 物体 // 物体
PhysicBody* GetBody(); Body* GetBody();
const PhysicBody* GetBody() const; const Body* GetBody() const;
// 形状 // 形状
PhysicShape GetShape() const; Shape GetShape() const;
// 下一夹具 (同一物体上) // 下一夹具 (同一物体上)
PhysicFixture GetNext() const; Fixture GetNext() const;
// 接触传感器 // 接触传感器
bool IsSensor() const { KGE_ASSERT(fixture_); return fixture_->IsSensor(); } bool IsSensor() const { KGE_ASSERT(fixture_); return fixture_->IsSensor(); }

View File

@ -26,29 +26,29 @@ namespace kiwano
namespace physics namespace physics
{ {
// //
// PhysicJoint // Joint
// //
PhysicJoint::PhysicJoint() Joint::Joint()
: joint_(nullptr) : joint_(nullptr)
, world_(nullptr) , world_(nullptr)
, type_(Type::Unknown) , type_(Type::Unknown)
{ {
} }
PhysicJoint::PhysicJoint(b2Joint* joint) Joint::Joint(b2Joint* joint)
: PhysicJoint() : Joint()
{ {
SetB2Joint(joint); SetB2Joint(joint);
} }
PhysicJoint::PhysicJoint(PhysicWorld* world, b2JointDef* joint_def) Joint::Joint(World* world, b2JointDef* joint_def)
: PhysicJoint() : Joint()
{ {
Init(world, joint_def); Init(world, joint_def);
} }
PhysicJoint::~PhysicJoint() Joint::~Joint()
{ {
if (world_) if (world_)
{ {
@ -56,7 +56,7 @@ namespace kiwano
} }
} }
void PhysicJoint::Init(PhysicWorld* world, b2JointDef* joint_def) void Joint::Init(World* world, b2JointDef* joint_def)
{ {
world_ = world; world_ = world;
if (world_) if (world_)
@ -68,28 +68,28 @@ namespace kiwano
} }
} }
PhysicBodyPtr PhysicJoint::GetBodyA() const BodyPtr Joint::GetBodyA() const
{ {
KGE_ASSERT(joint_); KGE_ASSERT(joint_);
b2Body* body = joint_->GetBodyA(); b2Body* body = joint_->GetBodyA();
return PhysicBodyPtr(static_cast<PhysicBody*>(body->GetUserData())); return BodyPtr(static_cast<Body*>(body->GetUserData()));
} }
PhysicBodyPtr PhysicJoint::GetBodyB() const BodyPtr Joint::GetBodyB() const
{ {
KGE_ASSERT(joint_); KGE_ASSERT(joint_);
b2Body* body = joint_->GetBodyB(); b2Body* body = joint_->GetBodyB();
return PhysicBodyPtr(static_cast<PhysicBody*>(body->GetUserData())); return BodyPtr(static_cast<Body*>(body->GetUserData()));
} }
void PhysicJoint::SetB2Joint(b2Joint* joint) void Joint::SetB2Joint(b2Joint* joint)
{ {
joint_ = joint; joint_ = joint;
if (joint_) if (joint_)
{ {
type_ = PhysicJoint::Type(joint_->GetType()); type_ = Joint::Type(joint_->GetType());
} }
} }
@ -98,19 +98,19 @@ namespace kiwano
// //
DistanceJoint::DistanceJoint() DistanceJoint::DistanceJoint()
: PhysicJoint() : Joint()
, raw_joint_(nullptr) , raw_joint_(nullptr)
{ {
} }
DistanceJoint::DistanceJoint(PhysicWorld* world, b2DistanceJointDef* def) DistanceJoint::DistanceJoint(World* world, b2DistanceJointDef* def)
: PhysicJoint(world, def) : Joint(world, def)
, raw_joint_(nullptr) , raw_joint_(nullptr)
{ {
} }
DistanceJoint::DistanceJoint(PhysicWorld* world, DistanceJoint::Param const& param) DistanceJoint::DistanceJoint(World* world, DistanceJoint::Param const& param)
: PhysicJoint() : Joint()
, raw_joint_(nullptr) , raw_joint_(nullptr)
{ {
KGE_ASSERT(param.body_a && param.body_b); KGE_ASSERT(param.body_a && param.body_b);
@ -141,19 +141,19 @@ namespace kiwano
// //
FrictionJoint::FrictionJoint() FrictionJoint::FrictionJoint()
: PhysicJoint() : Joint()
, raw_joint_(nullptr) , raw_joint_(nullptr)
{ {
} }
FrictionJoint::FrictionJoint(PhysicWorld* world, b2FrictionJointDef* def) FrictionJoint::FrictionJoint(World* world, b2FrictionJointDef* def)
: PhysicJoint(world, def) : Joint(world, def)
, raw_joint_(nullptr) , raw_joint_(nullptr)
{ {
} }
FrictionJoint::FrictionJoint(PhysicWorld* world, FrictionJoint::Param const& param) FrictionJoint::FrictionJoint(World* world, FrictionJoint::Param const& param)
: PhysicJoint() : Joint()
, raw_joint_(nullptr) , raw_joint_(nullptr)
{ {
KGE_ASSERT(param.body_a && param.body_b); KGE_ASSERT(param.body_a && param.body_b);
@ -196,19 +196,19 @@ namespace kiwano
// //
GearJoint::GearJoint() GearJoint::GearJoint()
: PhysicJoint() : Joint()
, raw_joint_(nullptr) , raw_joint_(nullptr)
{ {
} }
GearJoint::GearJoint(PhysicWorld* world, b2GearJointDef* def) GearJoint::GearJoint(World* world, b2GearJointDef* def)
: PhysicJoint(world, def) : Joint(world, def)
, raw_joint_(nullptr) , raw_joint_(nullptr)
{ {
} }
GearJoint::GearJoint(PhysicWorld* world, GearJoint::Param const& param) GearJoint::GearJoint(World* world, GearJoint::Param const& param)
: PhysicJoint() : Joint()
, raw_joint_(nullptr) , raw_joint_(nullptr)
{ {
KGE_ASSERT(param.joint_a && param.joint_b); KGE_ASSERT(param.joint_a && param.joint_b);
@ -239,19 +239,19 @@ namespace kiwano
// //
MotorJoint::MotorJoint() MotorJoint::MotorJoint()
: PhysicJoint() : Joint()
, raw_joint_(nullptr) , raw_joint_(nullptr)
{ {
} }
MotorJoint::MotorJoint(PhysicWorld* world, b2MotorJointDef* def) MotorJoint::MotorJoint(World* world, b2MotorJointDef* def)
: PhysicJoint(world, def) : Joint(world, def)
, raw_joint_(nullptr) , raw_joint_(nullptr)
{ {
} }
MotorJoint::MotorJoint(PhysicWorld* world, MotorJoint::Param const& param) MotorJoint::MotorJoint(World* world, MotorJoint::Param const& param)
: PhysicJoint() : Joint()
, raw_joint_(nullptr) , raw_joint_(nullptr)
{ {
KGE_ASSERT(param.body_a && param.body_b); KGE_ASSERT(param.body_a && param.body_b);
@ -294,19 +294,19 @@ namespace kiwano
// //
PrismaticJoint::PrismaticJoint() PrismaticJoint::PrismaticJoint()
: PhysicJoint() : Joint()
, raw_joint_(nullptr) , raw_joint_(nullptr)
{ {
} }
PrismaticJoint::PrismaticJoint(PhysicWorld* world, b2PrismaticJointDef* def) PrismaticJoint::PrismaticJoint(World* world, b2PrismaticJointDef* def)
: PhysicJoint(world, def) : Joint(world, def)
, raw_joint_(nullptr) , raw_joint_(nullptr)
{ {
} }
PrismaticJoint::PrismaticJoint(PhysicWorld* world, PrismaticJoint::Param const& param) PrismaticJoint::PrismaticJoint(World* world, PrismaticJoint::Param const& param)
: PhysicJoint() : Joint()
, raw_joint_(nullptr) , raw_joint_(nullptr)
{ {
KGE_ASSERT(param.body_a && param.body_b); KGE_ASSERT(param.body_a && param.body_b);
@ -359,19 +359,19 @@ namespace kiwano
// //
PulleyJoint::PulleyJoint() PulleyJoint::PulleyJoint()
: PhysicJoint() : Joint()
, raw_joint_(nullptr) , raw_joint_(nullptr)
{ {
} }
PulleyJoint::PulleyJoint(PhysicWorld* world, b2PulleyJointDef* def) PulleyJoint::PulleyJoint(World* world, b2PulleyJointDef* def)
: PhysicJoint(world, def) : Joint(world, def)
, raw_joint_(nullptr) , raw_joint_(nullptr)
{ {
} }
PulleyJoint::PulleyJoint(PhysicWorld* world, PulleyJoint::Param const& param) PulleyJoint::PulleyJoint(World* world, PulleyJoint::Param const& param)
: PhysicJoint() : Joint()
, raw_joint_(nullptr) , raw_joint_(nullptr)
{ {
KGE_ASSERT(param.body_a && param.body_b); KGE_ASSERT(param.body_a && param.body_b);
@ -431,19 +431,19 @@ namespace kiwano
// //
RevoluteJoint::RevoluteJoint() RevoluteJoint::RevoluteJoint()
: PhysicJoint() : Joint()
, raw_joint_(nullptr) , raw_joint_(nullptr)
{ {
} }
RevoluteJoint::RevoluteJoint(PhysicWorld* world, b2RevoluteJointDef* def) RevoluteJoint::RevoluteJoint(World* world, b2RevoluteJointDef* def)
: PhysicJoint(world, def) : Joint(world, def)
, raw_joint_(nullptr) , raw_joint_(nullptr)
{ {
} }
RevoluteJoint::RevoluteJoint(PhysicWorld* world, RevoluteJoint::Param const& param) RevoluteJoint::RevoluteJoint(World* world, RevoluteJoint::Param const& param)
: PhysicJoint() : Joint()
, raw_joint_(nullptr) , raw_joint_(nullptr)
{ {
KGE_ASSERT(param.body_a && param.body_b); KGE_ASSERT(param.body_a && param.body_b);
@ -508,19 +508,19 @@ namespace kiwano
// //
RopeJoint::RopeJoint() RopeJoint::RopeJoint()
: PhysicJoint() : Joint()
, raw_joint_(nullptr) , raw_joint_(nullptr)
{ {
} }
RopeJoint::RopeJoint(PhysicWorld* world, b2RopeJointDef* def) RopeJoint::RopeJoint(World* world, b2RopeJointDef* def)
: PhysicJoint(world, def) : Joint(world, def)
, raw_joint_(nullptr) , raw_joint_(nullptr)
{ {
} }
RopeJoint::RopeJoint(PhysicWorld* world, RopeJoint::Param const& param) RopeJoint::RopeJoint(World* world, RopeJoint::Param const& param)
: PhysicJoint() : Joint()
, raw_joint_(nullptr) , raw_joint_(nullptr)
{ {
KGE_ASSERT(param.body_a && param.body_b); KGE_ASSERT(param.body_a && param.body_b);
@ -553,19 +553,19 @@ namespace kiwano
// //
WeldJoint::WeldJoint() WeldJoint::WeldJoint()
: PhysicJoint() : Joint()
, raw_joint_(nullptr) , raw_joint_(nullptr)
{ {
} }
WeldJoint::WeldJoint(PhysicWorld* world, b2WeldJointDef* def) WeldJoint::WeldJoint(World* world, b2WeldJointDef* def)
: PhysicJoint(world, def) : Joint(world, def)
, raw_joint_(nullptr) , raw_joint_(nullptr)
{ {
} }
WeldJoint::WeldJoint(PhysicWorld* world, WeldJoint::Param const& param) WeldJoint::WeldJoint(World* world, WeldJoint::Param const& param)
: PhysicJoint() : Joint()
, raw_joint_(nullptr) , raw_joint_(nullptr)
{ {
KGE_ASSERT(param.body_a && param.body_b); KGE_ASSERT(param.body_a && param.body_b);
@ -584,19 +584,19 @@ namespace kiwano
// //
WheelJoint::WheelJoint() WheelJoint::WheelJoint()
: PhysicJoint() : Joint()
, raw_joint_(nullptr) , raw_joint_(nullptr)
{ {
} }
WheelJoint::WheelJoint(PhysicWorld* world, b2WheelJointDef* def) WheelJoint::WheelJoint(World* world, b2WheelJointDef* def)
: PhysicJoint(world, def) : Joint(world, def)
, raw_joint_(nullptr) , raw_joint_(nullptr)
{ {
} }
WheelJoint::WheelJoint(PhysicWorld* world, WheelJoint::Param const& param) WheelJoint::WheelJoint(World* world, WheelJoint::Param const& param)
: PhysicJoint() : Joint()
, raw_joint_(nullptr) , raw_joint_(nullptr)
{ {
KGE_ASSERT(param.body_a && param.body_b); KGE_ASSERT(param.body_a && param.body_b);
@ -642,19 +642,19 @@ namespace kiwano
// //
MouseJoint::MouseJoint() MouseJoint::MouseJoint()
: PhysicJoint() : Joint()
, raw_joint_(nullptr) , raw_joint_(nullptr)
{ {
} }
MouseJoint::MouseJoint(PhysicWorld* world, b2MouseJointDef* def) MouseJoint::MouseJoint(World* world, b2MouseJointDef* def)
: PhysicJoint(world, def) : Joint(world, def)
, raw_joint_(nullptr) , raw_joint_(nullptr)
{ {
} }
MouseJoint::MouseJoint(PhysicWorld* world, MouseJoint::Param const& param) MouseJoint::MouseJoint(World* world, MouseJoint::Param const& param)
: PhysicJoint() : Joint()
, raw_joint_(nullptr) , raw_joint_(nullptr)
{ {
KGE_ASSERT(param.body_a && param.body_b); KGE_ASSERT(param.body_a && param.body_b);

View File

@ -26,7 +26,7 @@ namespace kiwano
{ {
namespace physics namespace physics
{ {
KGE_DECLARE_SMART_PTR(PhysicJoint); KGE_DECLARE_SMART_PTR(Joint);
KGE_DECLARE_SMART_PTR(DistanceJoint); KGE_DECLARE_SMART_PTR(DistanceJoint);
KGE_DECLARE_SMART_PTR(FrictionJoint); KGE_DECLARE_SMART_PTR(FrictionJoint);
KGE_DECLARE_SMART_PTR(GearJoint); KGE_DECLARE_SMART_PTR(GearJoint);
@ -40,7 +40,7 @@ namespace kiwano
KGE_DECLARE_SMART_PTR(WheelJoint); KGE_DECLARE_SMART_PTR(WheelJoint);
// 关节 // 关节
class KGE_API PhysicJoint class KGE_API Joint
: public virtual RefCounter : public virtual RefCounter
{ {
public: public:
@ -62,43 +62,43 @@ namespace kiwano
struct ParamBase struct ParamBase
{ {
PhysicBody* body_a; Body* body_a;
PhysicBody* body_b; Body* body_b;
ParamBase(PhysicBody* body_a, PhysicBody* body_b) : body_a(body_a), body_b(body_b) {} ParamBase(Body* body_a, Body* body_b) : body_a(body_a), body_b(body_b) {}
ParamBase(PhysicBodyPtr body_a, PhysicBodyPtr body_b) : body_a(body_a.get()), body_b(body_b.get()) {} ParamBase(BodyPtr body_a, BodyPtr body_b) : body_a(body_a.get()), body_b(body_b.get()) {}
}; };
PhysicJoint(); Joint();
PhysicJoint(b2Joint* joint); Joint(b2Joint* joint);
PhysicJoint(PhysicWorld* world, b2JointDef* joint_def); Joint(World* world, b2JointDef* joint_def);
virtual ~PhysicJoint(); virtual ~Joint();
void Init(PhysicWorld* world, b2JointDef* joint_def); void Init(World* world, b2JointDef* joint_def);
PhysicBodyPtr GetBodyA() const; BodyPtr GetBodyA() const;
PhysicBodyPtr GetBodyB() const; BodyPtr GetBodyB() const;
b2Joint* GetB2Joint() { return joint_; } b2Joint* GetB2Joint() { return joint_; }
const b2Joint* GetB2Joint() const { return joint_; } const b2Joint* GetB2Joint() const { return joint_; }
void SetB2Joint(b2Joint* joint); void SetB2Joint(b2Joint* joint);
PhysicWorld* GetWorld() { return world_; } World* GetWorld() { return world_; }
const PhysicWorld* GetWorld() const { return world_; } const World* GetWorld() const { return world_; }
protected: protected:
b2Joint* joint_; b2Joint* joint_;
PhysicWorld* world_; World* world_;
Type type_; Type type_;
}; };
// 固定距离关节 // 固定距离关节
class KGE_API DistanceJoint class KGE_API DistanceJoint
: public PhysicJoint : public Joint
{ {
public: public:
struct Param : public PhysicJoint::ParamBase struct Param : public Joint::ParamBase
{ {
Point anchor_a; Point anchor_a;
Point anchor_b; Point anchor_b;
@ -106,8 +106,8 @@ namespace kiwano
float damping_ratio; float damping_ratio;
Param( Param(
PhysicBody* body_a, Body* body_a,
PhysicBody* body_b, Body* body_b,
Point const& anchor_a, Point const& anchor_a,
Point const& anchor_b, Point const& anchor_b,
float frequency_hz = 0.f, float frequency_hz = 0.f,
@ -121,8 +121,8 @@ namespace kiwano
{} {}
Param( Param(
PhysicBodyPtr body_a, BodyPtr body_a,
PhysicBodyPtr body_b, BodyPtr body_b,
Point const& anchor_a, Point const& anchor_a,
Point const& anchor_b, Point const& anchor_b,
float frequency_hz = 0.f, float frequency_hz = 0.f,
@ -133,8 +133,8 @@ namespace kiwano
}; };
DistanceJoint(); DistanceJoint();
DistanceJoint(PhysicWorld* world, b2DistanceJointDef* def); DistanceJoint(World* world, b2DistanceJointDef* def);
DistanceJoint(PhysicWorld* world, Param const& param); DistanceJoint(World* world, Param const& param);
void SetLength(float length); void SetLength(float length);
float GetLength() const; float GetLength() const;
@ -154,18 +154,18 @@ namespace kiwano
// 摩擦关节 // 摩擦关节
class KGE_API FrictionJoint class KGE_API FrictionJoint
: public PhysicJoint : public Joint
{ {
public: public:
struct Param : public PhysicJoint::ParamBase struct Param : public Joint::ParamBase
{ {
Point anchor; Point anchor;
float max_force; float max_force;
float max_torque; float max_torque;
Param( Param(
PhysicBody* body_a, Body* body_a,
PhysicBody* body_b, Body* body_b,
Point const& anchor, Point const& anchor,
float max_force = 0.f, float max_force = 0.f,
float max_torque = 0.f float max_torque = 0.f
@ -177,8 +177,8 @@ namespace kiwano
{} {}
Param( Param(
PhysicBodyPtr body_a, BodyPtr body_a,
PhysicBodyPtr body_b, BodyPtr body_b,
Point const& anchor, Point const& anchor,
float max_force = 0.f, float max_force = 0.f,
float max_torque = 0.f float max_torque = 0.f
@ -188,8 +188,8 @@ namespace kiwano
}; };
FrictionJoint(); FrictionJoint();
FrictionJoint(PhysicWorld* world, b2FrictionJointDef* def); FrictionJoint(World* world, b2FrictionJointDef* def);
FrictionJoint(PhysicWorld* world, Param const& param); FrictionJoint(World* world, Param const& param);
// 设定最大摩擦力 // 设定最大摩擦力
void SetMaxForce(float force); void SetMaxForce(float force);
@ -206,18 +206,18 @@ namespace kiwano
// 齿轮关节 // 齿轮关节
class KGE_API GearJoint class KGE_API GearJoint
: public PhysicJoint : public Joint
{ {
public: public:
struct Param : public PhysicJoint::ParamBase struct Param : public Joint::ParamBase
{ {
PhysicJointPtr joint_a; JointPtr joint_a;
PhysicJointPtr joint_b; JointPtr joint_b;
float ratio; float ratio;
Param( Param(
PhysicJoint* joint_a, Joint* joint_a,
PhysicJoint* joint_b, Joint* joint_b,
float ratio = 1.f float ratio = 1.f
) )
: ParamBase(nullptr, nullptr) : ParamBase(nullptr, nullptr)
@ -227,8 +227,8 @@ namespace kiwano
{} {}
Param( Param(
PhysicJointPtr joint_a, JointPtr joint_a,
PhysicJointPtr joint_b, JointPtr joint_b,
float ratio = 1.f float ratio = 1.f
) )
: Param(joint_a.get(), joint_b.get(), ratio) : Param(joint_a.get(), joint_b.get(), ratio)
@ -236,8 +236,8 @@ namespace kiwano
}; };
GearJoint(); GearJoint();
GearJoint(PhysicWorld* world, b2GearJointDef* def); GearJoint(World* world, b2GearJointDef* def);
GearJoint(PhysicWorld* world, Param const& param); GearJoint(World* world, Param const& param);
// 设定齿轮传动比 // 设定齿轮传动比
void SetRatio(float ratio); void SetRatio(float ratio);
@ -250,18 +250,18 @@ namespace kiwano
// 马达关节 // 马达关节
class KGE_API MotorJoint class KGE_API MotorJoint
: public PhysicJoint : public Joint
{ {
public: public:
struct Param : public PhysicJoint::ParamBase struct Param : public Joint::ParamBase
{ {
float max_force; float max_force;
float max_torque; float max_torque;
float correction_factor; float correction_factor;
Param( Param(
PhysicBody* body_a, Body* body_a,
PhysicBody* body_b, Body* body_b,
float max_force = 1.f, float max_force = 1.f,
float max_torque = 100.f, float max_torque = 100.f,
float correction_factor = 0.3f float correction_factor = 0.3f
@ -273,8 +273,8 @@ namespace kiwano
{} {}
Param( Param(
PhysicBodyPtr body_a, BodyPtr body_a,
PhysicBodyPtr body_b, BodyPtr body_b,
float max_force = 0.f, float max_force = 0.f,
float max_torque = 0.f, float max_torque = 0.f,
float correction_factor = 0.3f float correction_factor = 0.3f
@ -284,8 +284,8 @@ namespace kiwano
}; };
MotorJoint(); MotorJoint();
MotorJoint(PhysicWorld* world, b2MotorJointDef* def); MotorJoint(World* world, b2MotorJointDef* def);
MotorJoint(PhysicWorld* world, Param const& param); MotorJoint(World* world, Param const& param);
// 设定最大摩擦力 // 设定最大摩擦力
void SetMaxForce(float force); void SetMaxForce(float force);
@ -302,10 +302,10 @@ namespace kiwano
// 平移关节 // 平移关节
class KGE_API PrismaticJoint class KGE_API PrismaticJoint
: public PhysicJoint : public Joint
{ {
public: public:
struct Param : public PhysicJoint::ParamBase struct Param : public Joint::ParamBase
{ {
Point anchor; Point anchor;
Vec2 axis; Vec2 axis;
@ -317,8 +317,8 @@ namespace kiwano
float motor_speed; float motor_speed;
Param( Param(
PhysicBody* body_a, Body* body_a,
PhysicBody* body_b, Body* body_b,
Point const& anchor, Point const& anchor,
Vec2 const& axis, Vec2 const& axis,
bool enable_limit = false, bool enable_limit = false,
@ -340,8 +340,8 @@ namespace kiwano
{} {}
Param( Param(
PhysicBodyPtr body_a, BodyPtr body_a,
PhysicBodyPtr body_b, BodyPtr body_b,
Point const& anchor, Point const& anchor,
Vec2 const& axis, Vec2 const& axis,
bool enable_limit = false, bool enable_limit = false,
@ -356,8 +356,8 @@ namespace kiwano
}; };
PrismaticJoint(); PrismaticJoint();
PrismaticJoint(PhysicWorld* world, b2PrismaticJointDef* def); PrismaticJoint(World* world, b2PrismaticJointDef* def);
PrismaticJoint(PhysicWorld* world, Param const& param); PrismaticJoint(World* world, Param const& param);
float GetReferenceAngle() const { KGE_ASSERT(raw_joint_); return math::Radian2Degree(raw_joint_->GetReferenceAngle()); } float GetReferenceAngle() const { KGE_ASSERT(raw_joint_); return math::Radian2Degree(raw_joint_->GetReferenceAngle()); }
float GetJointTranslation() const; float GetJointTranslation() const;
@ -388,10 +388,10 @@ namespace kiwano
// 滑轮关节 // 滑轮关节
class KGE_API PulleyJoint class KGE_API PulleyJoint
: public PhysicJoint : public Joint
{ {
public: public:
struct Param : public PhysicJoint::ParamBase struct Param : public Joint::ParamBase
{ {
Point anchor_a; Point anchor_a;
Point anchor_b; Point anchor_b;
@ -400,8 +400,8 @@ namespace kiwano
float ratio; float ratio;
Param( Param(
PhysicBody* body_a, Body* body_a,
PhysicBody* body_b, Body* body_b,
Point const& anchor_a, Point const& anchor_a,
Point const& anchor_b, Point const& anchor_b,
Point const& ground_anchor_a, Point const& ground_anchor_a,
@ -417,8 +417,8 @@ namespace kiwano
{} {}
Param( Param(
PhysicBodyPtr body_a, BodyPtr body_a,
PhysicBodyPtr body_b, BodyPtr body_b,
Point const& anchor_a, Point const& anchor_a,
Point const& anchor_b, Point const& anchor_b,
Point const& ground_anchor_a, Point const& ground_anchor_a,
@ -430,8 +430,8 @@ namespace kiwano
}; };
PulleyJoint(); PulleyJoint();
PulleyJoint(PhysicWorld* world, b2PulleyJointDef* def); PulleyJoint(World* world, b2PulleyJointDef* def);
PulleyJoint(PhysicWorld* world, Param const& param); PulleyJoint(World* world, Param const& param);
Point GetGroundAnchorA() const; Point GetGroundAnchorA() const;
Point GetGroundAnchorB() const; Point GetGroundAnchorB() const;
@ -451,10 +451,10 @@ namespace kiwano
// 旋转关节 // 旋转关节
class KGE_API RevoluteJoint class KGE_API RevoluteJoint
: public PhysicJoint : public Joint
{ {
public: public:
struct Param : public PhysicJoint::ParamBase struct Param : public Joint::ParamBase
{ {
Point anchor; Point anchor;
bool enable_limit; bool enable_limit;
@ -465,8 +465,8 @@ namespace kiwano
float motor_speed; float motor_speed;
Param( Param(
PhysicBody* body_a, Body* body_a,
PhysicBody* body_b, Body* body_b,
Point const& anchor, Point const& anchor,
bool enable_limit = false, bool enable_limit = false,
float lower_angle = 0.0f, float lower_angle = 0.0f,
@ -486,8 +486,8 @@ namespace kiwano
{} {}
Param( Param(
PhysicBodyPtr body_a, BodyPtr body_a,
PhysicBodyPtr body_b, BodyPtr body_b,
Point const& anchor, Point const& anchor,
bool enable_limit = false, bool enable_limit = false,
float lower_angle = 0.0f, float lower_angle = 0.0f,
@ -501,8 +501,8 @@ namespace kiwano
}; };
RevoluteJoint(); RevoluteJoint();
RevoluteJoint(PhysicWorld* world, b2RevoluteJointDef* def); RevoluteJoint(World* world, b2RevoluteJointDef* def);
RevoluteJoint(PhysicWorld* world, Param const& param); RevoluteJoint(World* world, Param const& param);
float GetReferenceAngle() const { KGE_ASSERT(raw_joint_); return math::Radian2Degree(raw_joint_->GetReferenceAngle()); } float GetReferenceAngle() const { KGE_ASSERT(raw_joint_); return math::Radian2Degree(raw_joint_->GetReferenceAngle()); }
float GetJointAngle() const; float GetJointAngle() const;
@ -533,18 +533,18 @@ namespace kiwano
// 绳关节 // 绳关节
class KGE_API RopeJoint class KGE_API RopeJoint
: public PhysicJoint : public Joint
{ {
public: public:
struct Param : public PhysicJoint::ParamBase struct Param : public Joint::ParamBase
{ {
Point local_anchor_a; Point local_anchor_a;
Point local_anchor_b; Point local_anchor_b;
float max_length; float max_length;
Param( Param(
PhysicBody* body_a, Body* body_a,
PhysicBody* body_b, Body* body_b,
Point const& local_anchor_a, Point const& local_anchor_a,
Point const& local_anchor_b, Point const& local_anchor_b,
float max_length = 0.f float max_length = 0.f
@ -556,8 +556,8 @@ namespace kiwano
{} {}
Param( Param(
PhysicBodyPtr body_a, BodyPtr body_a,
PhysicBodyPtr body_b, BodyPtr body_b,
Point const& local_anchor_a, Point const& local_anchor_a,
Point const& local_anchor_b, Point const& local_anchor_b,
float max_length = 0.f float max_length = 0.f
@ -567,8 +567,8 @@ namespace kiwano
}; };
RopeJoint(); RopeJoint();
RopeJoint(PhysicWorld* world, b2RopeJointDef* def); RopeJoint(World* world, b2RopeJointDef* def);
RopeJoint(PhysicWorld* world, Param const& param); RopeJoint(World* world, Param const& param);
void SetMaxLength(float length); void SetMaxLength(float length);
float GetMaxLength() const; float GetMaxLength() const;
@ -580,18 +580,18 @@ namespace kiwano
// 焊接关节 // 焊接关节
class KGE_API WeldJoint class KGE_API WeldJoint
: public PhysicJoint : public Joint
{ {
public: public:
struct Param : public PhysicJoint::ParamBase struct Param : public Joint::ParamBase
{ {
Point anchor; Point anchor;
float frequency_hz; float frequency_hz;
float damping_ratio; float damping_ratio;
Param( Param(
PhysicBody* body_a, Body* body_a,
PhysicBody* body_b, Body* body_b,
Point const& anchor, Point const& anchor,
float frequency_hz = 0.f, float frequency_hz = 0.f,
float damping_ratio = 0.f float damping_ratio = 0.f
@ -603,8 +603,8 @@ namespace kiwano
{} {}
Param( Param(
PhysicBodyPtr body_a, BodyPtr body_a,
PhysicBodyPtr body_b, BodyPtr body_b,
Point const& anchor, Point const& anchor,
float frequency_hz = 0.f, float frequency_hz = 0.f,
float damping_ratio = 0.f float damping_ratio = 0.f
@ -614,8 +614,8 @@ namespace kiwano
}; };
WeldJoint(); WeldJoint();
WeldJoint(PhysicWorld* world, b2WeldJointDef* def); WeldJoint(World* world, b2WeldJointDef* def);
WeldJoint(PhysicWorld* world, Param const& param); WeldJoint(World* world, Param const& param);
// 设置弹簧阻尼器频率 [赫兹] // 设置弹簧阻尼器频率 [赫兹]
void SetFrequency(float hz) { KGE_ASSERT(raw_joint_); raw_joint_->SetFrequency(hz); } void SetFrequency(float hz) { KGE_ASSERT(raw_joint_); raw_joint_->SetFrequency(hz); }
@ -632,10 +632,10 @@ namespace kiwano
// 轮关节 // 轮关节
class KGE_API WheelJoint class KGE_API WheelJoint
: public PhysicJoint : public Joint
{ {
public: public:
struct Param : public PhysicJoint::ParamBase struct Param : public Joint::ParamBase
{ {
Point anchor; Point anchor;
Vec2 axis; Vec2 axis;
@ -646,8 +646,8 @@ namespace kiwano
float damping_ratio; float damping_ratio;
Param( Param(
PhysicBody* body_a, Body* body_a,
PhysicBody* body_b, Body* body_b,
Point const& anchor, Point const& anchor,
Vec2 const& axis, Vec2 const& axis,
float frequency_hz = 2.0f, float frequency_hz = 2.0f,
@ -667,8 +667,8 @@ namespace kiwano
{} {}
Param( Param(
PhysicBodyPtr body_a, BodyPtr body_a,
PhysicBodyPtr body_b, BodyPtr body_b,
Point const& anchor, Point const& anchor,
Vec2 const& axis, Vec2 const& axis,
float frequency_hz = 2.0f, float frequency_hz = 2.0f,
@ -682,8 +682,8 @@ namespace kiwano
}; };
WheelJoint(); WheelJoint();
WheelJoint(PhysicWorld* world, b2WheelJointDef* def); WheelJoint(World* world, b2WheelJointDef* def);
WheelJoint(PhysicWorld* world, Param const& param); WheelJoint(World* world, Param const& param);
float GetJointTranslation() const; float GetJointTranslation() const;
float GetJointLinearSpeed() const; float GetJointLinearSpeed() const;
@ -715,10 +715,10 @@ namespace kiwano
// 鼠标关节 // 鼠标关节
// 用于使身体的某个点追踪世界上的指定点,例如让物体追踪鼠标位置 // 用于使身体的某个点追踪世界上的指定点,例如让物体追踪鼠标位置
class KGE_API MouseJoint class KGE_API MouseJoint
: public PhysicJoint : public Joint
{ {
public: public:
struct Param : public PhysicJoint::ParamBase struct Param : public Joint::ParamBase
{ {
Point target; Point target;
float max_force; float max_force;
@ -726,8 +726,8 @@ namespace kiwano
float damping_ratio; float damping_ratio;
Param( Param(
PhysicBody* body_a, Body* body_a,
PhysicBody* body_b, Body* body_b,
Point const& target, Point const& target,
float max_force, float max_force,
float frequency_hz = 5.0f, float frequency_hz = 5.0f,
@ -741,8 +741,8 @@ namespace kiwano
{} {}
Param( Param(
PhysicBodyPtr body_a, BodyPtr body_a,
PhysicBodyPtr body_b, BodyPtr body_b,
Point const& target, Point const& target,
float max_force, float max_force,
float frequency_hz = 5.0f, float frequency_hz = 5.0f,
@ -753,8 +753,8 @@ namespace kiwano
}; };
MouseJoint(); MouseJoint();
MouseJoint(PhysicWorld* world, b2MouseJointDef* def); MouseJoint(World* world, b2MouseJointDef* def);
MouseJoint(PhysicWorld* world, Param const& param); MouseJoint(World* world, Param const& param);
// 设定最大摩擦力 [N] // 设定最大摩擦力 [N]
void SetMaxForce(float force); void SetMaxForce(float force);

View File

@ -25,55 +25,55 @@ namespace kiwano
{ {
namespace physics namespace physics
{ {
PhysicShape::PhysicShape() Shape::Shape()
: shape_(nullptr) : shape_(nullptr)
{ {
} }
PhysicShape::PhysicShape(b2Shape* shape) Shape::Shape(b2Shape* shape)
: shape_(shape) : shape_(shape)
{ {
} }
b2Shape* PhysicShape::GetB2Shape() b2Shape* Shape::GetB2Shape()
{ {
return shape_; return shape_;
} }
const b2Shape* PhysicShape::GetB2Shape() const const b2Shape* Shape::GetB2Shape() const
{ {
return shape_; return shape_;
} }
void PhysicShape::SetB2Shape(b2Shape* shape) void Shape::SetB2Shape(b2Shape* shape)
{ {
shape_ = shape; shape_ = shape;
} }
// //
// PhysicCircleShape // CircleShape
// //
PhysicCircleShape::PhysicCircleShape() CircleShape::CircleShape()
: PhysicShape(&circle_) : Shape(&circle_)
, circle_() , circle_()
, radius_(0.f) , radius_(0.f)
{ {
} }
PhysicCircleShape::PhysicCircleShape(float radius, Point const& offset) CircleShape::CircleShape(float radius, Point const& offset)
: PhysicCircleShape() : CircleShape()
{ {
Set(radius, offset); Set(radius, offset);
} }
void PhysicCircleShape::Set(float radius, Point const& offset) void CircleShape::Set(float radius, Point const& offset)
{ {
radius_ = radius; radius_ = radius;
offset_ = offset; offset_ = offset;
} }
void PhysicCircleShape::FitWorld(PhysicWorld* world) void CircleShape::FitWorld(World* world)
{ {
KGE_ASSERT(world); KGE_ASSERT(world);
circle_.m_radius = world->Stage2World(radius_); circle_.m_radius = world->Stage2World(radius_);
@ -81,30 +81,30 @@ namespace kiwano
} }
// //
// PhysicBoxShape // BoxShape
// //
PhysicBoxShape::PhysicBoxShape() BoxShape::BoxShape()
: PhysicShape(&polygon_) : Shape(&polygon_)
, polygon_() , polygon_()
, rotation_(0.f) , rotation_(0.f)
{ {
} }
PhysicBoxShape::PhysicBoxShape(Vec2 const& size, Point const& offset, float rotation) BoxShape::BoxShape(Vec2 const& size, Point const& offset, float rotation)
: PhysicBoxShape() : BoxShape()
{ {
Set(size, offset, rotation); Set(size, offset, rotation);
} }
void PhysicBoxShape::Set(Vec2 const& size, Point const& offset, float rotation) void BoxShape::Set(Vec2 const& size, Point const& offset, float rotation)
{ {
box_size_ = size; box_size_ = size;
offset_ = offset; offset_ = offset;
rotation_ = rotation; rotation_ = rotation;
} }
void PhysicBoxShape::FitWorld(PhysicWorld* world) void BoxShape::FitWorld(World* world)
{ {
KGE_ASSERT(world); KGE_ASSERT(world);
@ -114,27 +114,27 @@ namespace kiwano
} }
// //
// PhysicPolygonShape // PolygonShape
// //
PhysicPolygonShape::PhysicPolygonShape() PolygonShape::PolygonShape()
: PhysicShape(&polygon_) : Shape(&polygon_)
, polygon_() , polygon_()
{ {
} }
PhysicPolygonShape::PhysicPolygonShape(Vector<Point> const& vertexs) PolygonShape::PolygonShape(Vector<Point> const& vertexs)
: PhysicPolygonShape() : PolygonShape()
{ {
Set(vertexs); Set(vertexs);
} }
void PhysicPolygonShape::Set(Vector<Point> const& vertexs) void PolygonShape::Set(Vector<Point> const& vertexs)
{ {
vertexs_ = vertexs; vertexs_ = vertexs;
} }
void PhysicPolygonShape::FitWorld(PhysicWorld* world) void PolygonShape::FitWorld(World* world)
{ {
KGE_ASSERT(world); KGE_ASSERT(world);
@ -149,28 +149,28 @@ namespace kiwano
} }
// //
// PhysicEdgeShape // EdgeShape
// //
PhysicEdgeShape::PhysicEdgeShape() EdgeShape::EdgeShape()
: PhysicShape(&edge_) : Shape(&edge_)
, edge_() , edge_()
{ {
} }
PhysicEdgeShape::PhysicEdgeShape(Point const& p1, Point const& p2) EdgeShape::EdgeShape(Point const& p1, Point const& p2)
: PhysicEdgeShape() : EdgeShape()
{ {
Set(p1, p2); Set(p1, p2);
} }
void PhysicEdgeShape::Set(Point const& p1, Point const& p2) void EdgeShape::Set(Point const& p1, Point const& p2)
{ {
p_[0] = p1; p_[0] = p1;
p_[1] = p2; p_[1] = p2;
} }
void PhysicEdgeShape::FitWorld(PhysicWorld* world) void EdgeShape::FitWorld(World* world)
{ {
KGE_ASSERT(world); KGE_ASSERT(world);
@ -180,29 +180,29 @@ namespace kiwano
} }
// //
// PhysicChainShape // ChainShape
// //
PhysicChainShape::PhysicChainShape() ChainShape::ChainShape()
: PhysicShape(&chain_) : Shape(&chain_)
, chain_() , chain_()
, loop_(false) , loop_(false)
{ {
} }
PhysicChainShape::PhysicChainShape(Vector<Point> const& vertexs, bool loop) ChainShape::ChainShape(Vector<Point> const& vertexs, bool loop)
: PhysicChainShape() : ChainShape()
{ {
Set(vertexs, loop); Set(vertexs, loop);
} }
void PhysicChainShape::Set(Vector<Point> const& vertexs, bool loop) void ChainShape::Set(Vector<Point> const& vertexs, bool loop)
{ {
vertexs_ = vertexs; vertexs_ = vertexs;
loop_ = loop; loop_ = loop;
} }
void PhysicChainShape::FitWorld(PhysicWorld* world) void ChainShape::FitWorld(World* world)
{ {
KGE_ASSERT(world); KGE_ASSERT(world);

View File

@ -25,37 +25,37 @@ namespace kiwano
{ {
namespace physics namespace physics
{ {
class PhysicWorld; class World;
// 形状基类 // 形状基类
class KGE_API PhysicShape class KGE_API Shape
{ {
public: public:
PhysicShape(); Shape();
PhysicShape(b2Shape* shape); Shape(b2Shape* shape);
b2Shape* GetB2Shape(); b2Shape* GetB2Shape();
const b2Shape* GetB2Shape() const; const b2Shape* GetB2Shape() const;
void SetB2Shape(b2Shape* shape); void SetB2Shape(b2Shape* shape);
virtual void FitWorld(PhysicWorld* world) {} virtual void FitWorld(World* world) {}
protected: protected:
b2Shape* shape_; b2Shape* shape_;
}; };
// 圆形形状 // 圆形形状
class KGE_API PhysicCircleShape class KGE_API CircleShape
: public PhysicShape : public Shape
{ {
public: public:
PhysicCircleShape(); CircleShape();
PhysicCircleShape(float radius, Point const& offset = Point()); CircleShape(float radius, Point const& offset = Point());
void Set(float radius, Point const& offset = Point()); void Set(float radius, Point const& offset = Point());
void FitWorld(PhysicWorld* world) override; void FitWorld(World* world) override;
protected: protected:
float radius_; float radius_;
@ -64,17 +64,17 @@ namespace kiwano
}; };
// 盒子形状 // 盒子形状
class KGE_API PhysicBoxShape class KGE_API BoxShape
: public PhysicShape : public Shape
{ {
public: public:
PhysicBoxShape(); BoxShape();
PhysicBoxShape(Vec2 const& size, Point const& offset = Point(), float rotation = 0.f); BoxShape(Vec2 const& size, Point const& offset = Point(), float rotation = 0.f);
void Set(Vec2 const& size, Point const& offset = Point(), float rotation = 0.f); void Set(Vec2 const& size, Point const& offset = Point(), float rotation = 0.f);
void FitWorld(PhysicWorld* world) override; void FitWorld(World* world) override;
protected: protected:
float rotation_; float rotation_;
@ -84,17 +84,17 @@ namespace kiwano
}; };
// 多边形形状 // 多边形形状
class KGE_API PhysicPolygonShape class KGE_API PolygonShape
: public PhysicShape : public Shape
{ {
public: public:
PhysicPolygonShape(); PolygonShape();
PhysicPolygonShape(Vector<Point> const& vertexs); PolygonShape(Vector<Point> const& vertexs);
void Set(Vector<Point> const& vertexs); void Set(Vector<Point> const& vertexs);
void FitWorld(PhysicWorld* world) override; void FitWorld(World* world) override;
protected: protected:
Vector<Point> vertexs_; Vector<Point> vertexs_;
@ -102,17 +102,17 @@ namespace kiwano
}; };
// 线段形状, 用于表示一条边 // 线段形状, 用于表示一条边
class KGE_API PhysicEdgeShape class KGE_API EdgeShape
: public PhysicShape : public Shape
{ {
public: public:
PhysicEdgeShape(); EdgeShape();
PhysicEdgeShape(Point const& p1, Point const& p2); EdgeShape(Point const& p1, Point const& p2);
void Set(Point const& p1, Point const& p2); void Set(Point const& p1, Point const& p2);
void FitWorld(PhysicWorld* world) override; void FitWorld(World* world) override;
protected: protected:
Point p_[2]; Point p_[2];
@ -120,17 +120,17 @@ namespace kiwano
}; };
// 链式形状 // 链式形状
class KGE_API PhysicChainShape class KGE_API ChainShape
: public PhysicShape : public Shape
{ {
public: public:
PhysicChainShape(); ChainShape();
PhysicChainShape(Vector<Point> const& vertexs, bool loop = false); ChainShape(Vector<Point> const& vertexs, bool loop = false);
void Set(Vector<Point> const& vertexs, bool loop = false); void Set(Vector<Point> const& vertexs, bool loop = false);
void FitWorld(PhysicWorld* world) override; void FitWorld(World* world) override;
protected: protected:
bool loop_; bool loop_;

View File

@ -29,12 +29,12 @@ namespace kiwano
const float DefaultGlobalScale = 100.f; // 100 pixels per meters const float DefaultGlobalScale = 100.f; // 100 pixels per meters
} }
class PhysicWorld::DestructionListener : public b2DestructionListener class World::DestructionListener : public b2DestructionListener
{ {
PhysicWorld* world_; World* world_;
public: public:
DestructionListener(PhysicWorld* world) DestructionListener(World* world)
: world_(world) : world_(world)
{ {
} }
@ -53,13 +53,13 @@ namespace kiwano
} }
}; };
class PhysicWorld::ContactListener class World::ContactListener
: public b2ContactListener : public b2ContactListener
{ {
PhysicWorld* world_; World* world_;
public: public:
ContactListener(PhysicWorld* world) ContactListener(World* world)
: world_(world) : world_(world)
{ {
} }
@ -70,7 +70,7 @@ namespace kiwano
void PostSolve(b2Contact* contact, const b2ContactImpulse* impulse) override { KGE_NOT_USED(contact); KGE_NOT_USED(impulse); } void PostSolve(b2Contact* contact, const b2ContactImpulse* impulse) override { KGE_NOT_USED(contact); KGE_NOT_USED(impulse); }
}; };
PhysicWorld::PhysicWorld() World::World()
: world_(b2Vec2(0, 10.0f)) : world_(b2Vec2(0, 10.0f))
, vel_iter_(6) , vel_iter_(6)
, pos_iter_(2) , pos_iter_(2)
@ -86,7 +86,7 @@ namespace kiwano
world_.SetContactListener(contact_listener_); world_.SetContactListener(contact_listener_);
} }
PhysicWorld::~PhysicWorld() World::~World()
{ {
world_.SetDestructionListener(nullptr); world_.SetDestructionListener(nullptr);
if (destruction_listener_) if (destruction_listener_)
@ -110,7 +110,7 @@ namespace kiwano
RemoveAllJoints(); RemoveAllJoints();
} }
void PhysicWorld::RemoveBody(PhysicBody* body) void World::RemoveBody(Body* body)
{ {
if (body && body->GetB2Body()) if (body && body->GetB2Body())
{ {
@ -118,7 +118,7 @@ namespace kiwano
} }
} }
void PhysicWorld::RemoveAllBodies() void World::RemoveAllBodies()
{ {
if (world_.GetBodyCount()) if (world_.GetBodyCount())
{ {
@ -132,7 +132,7 @@ namespace kiwano
} }
} }
void PhysicWorld::AddJoint(PhysicJoint* joint) void World::AddJoint(Joint* joint)
{ {
if (joint) if (joint)
{ {
@ -140,7 +140,7 @@ namespace kiwano
} }
} }
void PhysicWorld::RemoveJoint(PhysicJoint* joint) void World::RemoveJoint(Joint* joint)
{ {
if (joint) if (joint)
{ {
@ -159,7 +159,7 @@ namespace kiwano
} }
} }
void PhysicWorld::RemoveAllJoints() void World::RemoveAllJoints()
{ {
if (world_.GetJointCount()) if (world_.GetJointCount())
{ {
@ -178,14 +178,14 @@ namespace kiwano
joints_.clear(); joints_.clear();
} }
void PhysicWorld::JointRemoved(b2Joint* joint) void World::JointRemoved(b2Joint* joint)
{ {
if (!removing_joint_ && joint) if (!removing_joint_ && joint)
{ {
auto iter = std::find_if( auto iter = std::find_if(
joints_.begin(), joints_.begin(),
joints_.end(), joints_.end(),
[joint](PhysicJoint* j) -> bool { return j->GetB2Joint() == joint; } [joint](Joint* j) -> bool { return j->GetB2Joint() == joint; }
); );
if (iter != joints_.end()) if (iter != joints_.end())
@ -195,36 +195,36 @@ namespace kiwano
} }
} }
b2World* PhysicWorld::GetB2World() b2World* World::GetB2World()
{ {
return &world_; return &world_;
} }
const b2World* PhysicWorld::GetB2World() const const b2World* World::GetB2World() const
{ {
return &world_; return &world_;
} }
Vec2 PhysicWorld::GetGravity() const Vec2 World::GetGravity() const
{ {
b2Vec2 g = world_.GetGravity(); b2Vec2 g = world_.GetGravity();
return Vec2(g.x, g.y); return Vec2(g.x, g.y);
} }
void PhysicWorld::SetGravity(Vec2 gravity) void World::SetGravity(Vec2 gravity)
{ {
world_.SetGravity(b2Vec2(gravity.x, gravity.y)); world_.SetGravity(b2Vec2(gravity.x, gravity.y));
} }
void PhysicWorld::Update(Duration dt) void World::Update(Duration dt)
{ {
Stage::Update(dt); Stage::Update(dt);
b2Body* b2body = world_.GetBodyList(); b2Body* b2body = world_.GetBodyList();
while (b2body) while (b2body)
{ {
PhysicBody* body = static_cast<PhysicBody*>(b2body->GetUserData()); Body* body = static_cast<Body*>(b2body->GetUserData());
if (body && body->GetType() != PhysicBody::Type::Static) if (body && body->GetType() != Body::Type::Static)
{ {
body->UpdateFromActor(); body->UpdateFromActor();
} }
@ -237,8 +237,8 @@ namespace kiwano
b2body = world_.GetBodyList(); b2body = world_.GetBodyList();
while (b2body) while (b2body)
{ {
PhysicBody* body = static_cast<PhysicBody*>(b2body->GetUserData()); Body* body = static_cast<Body*>(b2body->GetUserData());
if (body && body->GetType() != PhysicBody::Type::Static) if (body && body->GetType() != Body::Type::Static)
{ {
body->UpdateActor(); body->UpdateActor();
} }

View File

@ -28,17 +28,17 @@ namespace kiwano
namespace physics namespace physics
{ {
// 物理世界 // 物理世界
class KGE_API PhysicWorld class KGE_API World
: public Stage : public Stage
, public PhysicContactDispatcher , public ContactDispatcher
{ {
friend class PhysicBody; friend class Body;
friend class PhysicJoint; friend class Joint;
public: public:
PhysicWorld(); World();
virtual ~PhysicWorld(); virtual ~World();
// 获取重力 // 获取重力
Vec2 GetGravity() const; Vec2 GetGravity() const;
@ -71,16 +71,16 @@ namespace kiwano
private: private:
// 移除物体 // 移除物体
void RemoveBody(PhysicBody* body); void RemoveBody(Body* body);
// 移除所有物体 // 移除所有物体
void RemoveAllBodies(); void RemoveAllBodies();
// 添加关节 // 添加关节
void AddJoint(PhysicJoint* joint); void AddJoint(Joint* joint);
// 移除关节 // 移除关节
void RemoveJoint(PhysicJoint* joint); void RemoveJoint(Joint* joint);
// 移除所有关节 // 移除所有关节
void RemoveAllJoints(); void RemoveAllJoints();
@ -105,9 +105,9 @@ namespace kiwano
ContactListener* contact_listener_; ContactListener* contact_listener_;
bool removing_joint_; bool removing_joint_;
Vector<PhysicJoint*> joints_; Vector<Joint*> joints_;
}; };
KGE_DECLARE_SMART_PTR(PhysicWorld); KGE_DECLARE_SMART_PTR(World);
} }
} }