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
{
PhysicBody::PhysicBody()
Body::Body()
: body_(nullptr)
, actor_(nullptr)
, world_(nullptr)
@ -36,25 +36,25 @@ namespace kiwano
{
}
PhysicBody::PhysicBody(b2Body* body, Actor* actor)
: PhysicBody()
Body::Body(b2Body* body, Actor* actor)
: Body()
{
SetB2Body(body);
SetActor(actor);
}
PhysicBody::PhysicBody(PhysicWorld* world, Actor* actor)
: PhysicBody()
Body::Body(World* world, Actor* actor)
: Body()
{
Init(world, actor);
}
PhysicBody::~PhysicBody()
Body::~Body()
{
Destroy();
}
void PhysicBody::Init(PhysicWorld* world, Actor* actor)
void Body::Init(World* world, Actor* actor)
{
KGE_ASSERT(world);
@ -69,38 +69,38 @@ namespace kiwano
UpdateFromActor();
}
PhysicFixture PhysicBody::AddFixture(PhysicShape* shape, const PhysicFixture::Param& param)
Fixture Body::AddFixture(Shape* shape, const Fixture::Param& param)
{
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())
{
@ -109,7 +109,7 @@ namespace kiwano
}
}
void PhysicBody::SetCategoryBits(uint16_t category_bits)
void Body::SetCategoryBits(uint16_t category_bits)
{
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_);
@ -143,7 +143,7 @@ namespace kiwano
}
}
void PhysicBody::SetGroupIndex(int16_t index)
void Body::SetGroupIndex(int16_t index)
{
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_);
@ -172,7 +172,7 @@ namespace kiwano
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_);
@ -183,67 +183,67 @@ namespace kiwano
body_->SetMassData(&data);
}
void PhysicBody::ResetMassData()
void Body::ResetMassData()
{
KGE_ASSERT(body_);
body_->ResetMassData();
}
Point PhysicBody::GetBodyPosition() const
Point Body::GetBodyPosition() const
{
KGE_ASSERT(body_ && world_);
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_);
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_);
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_);
return world_->World2Stage(body_->GetWorldPoint(world_->Stage2World(local)));
}
Point PhysicBody::GetLocalCenter() const
Point Body::GetLocalCenter() const
{
KGE_ASSERT(body_ && world_);
return world_->World2Stage(body_->GetLocalCenter());
}
Point PhysicBody::GetWorldCenter() const
Point Body::GetWorldCenter() const
{
KGE_ASSERT(body_ && world_);
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_);
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_);
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_);
body_->ApplyTorque(torque, wake);
}
void PhysicBody::SetB2Body(b2Body* body)
void Body::SetB2Body(b2Body* body)
{
body_ = body;
if (body_)
@ -252,7 +252,7 @@ namespace kiwano
}
}
void PhysicBody::Destroy()
void Body::Destroy()
{
if (world_)
{
@ -264,7 +264,7 @@ namespace kiwano
actor_ = nullptr;
}
void PhysicBody::UpdateActor()
void Body::UpdateActor()
{
if (actor_ && body_)
{
@ -280,7 +280,7 @@ namespace kiwano
}
}
void PhysicBody::UpdateFromActor()
void Body::UpdateFromActor()
{
if (actor_ && body_)
{
@ -301,7 +301,7 @@ namespace kiwano
}
}
void PhysicBody::UpdateFixtureFilter(b2Fixture* fixture)
void Body::UpdateFixtureFilter(b2Fixture* fixture)
{
b2Filter filter;
filter.categoryBits = category_bits_;

View File

@ -28,11 +28,11 @@ namespace kiwano
{
namespace physics
{
class PhysicWorld;
class World;
// 膠竟
KGE_DECLARE_SMART_PTR(PhysicBody);
class KGE_API PhysicBody
KGE_DECLARE_SMART_PTR(Body);
class KGE_API Body
: public virtual RefCounter
{
public:
@ -43,33 +43,33 @@ namespace kiwano
Dynamic,
};
PhysicBody();
PhysicBody(b2Body* body, Actor* actor);
PhysicBody(PhysicWorld* world, Actor* actor);
PhysicBody(PhysicWorld* world, ActorPtr actor) : PhysicBody(world, actor.get()) {}
virtual ~PhysicBody();
Body();
Body(b2Body* body, Actor* actor);
Body(World* world, Actor* actor);
Body(World* world, ActorPtr actor) : Body(world, actor.get()) {}
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);
PhysicFixture AddBoxShape(Vec2 const& size, float density = 0.f);
PhysicFixture AddPolygonShape(Vector<Point> const& vertexs, float density = 0.f);
PhysicFixture AddEdgeShape(Point const& p1, Point const& p2, float density = 0.f);
PhysicFixture AddChainShape(Vector<Point> const& vertexs, bool loop, float density = 0.f);
Fixture AddCircleShape(float radius, float density = 0.f);
Fixture AddBoxShape(Vec2 const& size, float density = 0.f);
Fixture AddPolygonShape(Vector<Point> const& vertexs, float density = 0.f);
Fixture AddEdgeShape(Point const& p1, Point const& p2, 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_; }
@ -153,8 +153,8 @@ namespace kiwano
const b2Body* GetB2Body() const { return body_; }
void SetB2Body(b2Body* body);
PhysicWorld* GetWorld() { return world_; }
const PhysicWorld* GetWorld() const { return world_; }
World* GetWorld() { return world_; }
const World* GetWorld() const { return world_; }
void Destroy();
@ -166,7 +166,7 @@ namespace kiwano
protected:
Actor* actor_;
PhysicWorld* world_;
World* world_;
b2Body* body_;
uint16_t category_bits_;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -26,10 +26,10 @@ namespace kiwano
{
namespace physics
{
class PhysicBody;
class Body;
// 夹具
class PhysicFixture
class Fixture
{
public:
struct Param
@ -49,19 +49,19 @@ namespace kiwano
{}
};
PhysicFixture();
PhysicFixture(b2Fixture* fixture);
PhysicFixture(PhysicBody* body, PhysicShape* shape, const Param& param);
Fixture();
Fixture(b2Fixture* fixture);
Fixture(Body* body, Shape* shape, const Param& param);
// 物体
PhysicBody* GetBody();
const PhysicBody* GetBody() const;
Body* GetBody();
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(); }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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