2019-10-18 11:50:46 +08:00
|
|
|
|
// Copyright (c) 2018-2019 Kiwano - Nomango
|
2020-01-21 10:09:55 +08:00
|
|
|
|
//
|
2019-10-18 11:50:46 +08:00
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
|
|
// of this software and associated documentation files (the "Software"), to deal
|
|
|
|
|
|
// in the Software without restriction, including without limitation the rights
|
|
|
|
|
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
|
|
// copies of the Software, and to permit persons to whom the Software is
|
|
|
|
|
|
// furnished to do so, subject to the following conditions:
|
2020-01-21 10:09:55 +08:00
|
|
|
|
//
|
2019-10-18 11:50:46 +08:00
|
|
|
|
// The above copyright notice and this permission notice shall be included in
|
|
|
|
|
|
// all copies or substantial portions of the Software.
|
2020-01-21 10:09:55 +08:00
|
|
|
|
//
|
2019-10-18 11:50:46 +08:00
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
|
|
// THE SOFTWARE.
|
|
|
|
|
|
|
|
|
|
|
|
#pragma once
|
2020-01-07 17:44:51 +08:00
|
|
|
|
#include <kiwano-physics/ContactEdge.h>
|
2020-01-21 10:09:55 +08:00
|
|
|
|
#include <kiwano-physics/Fixture.h>
|
|
|
|
|
|
#include <kiwano-physics/helper.h>
|
2019-10-18 11:50:46 +08:00
|
|
|
|
|
|
|
|
|
|
namespace kiwano
|
|
|
|
|
|
{
|
2020-01-21 10:09:55 +08:00
|
|
|
|
namespace physics
|
|
|
|
|
|
{
|
|
|
|
|
|
class World;
|
2019-10-31 20:34:38 +08:00
|
|
|
|
|
2020-01-21 10:09:55 +08:00
|
|
|
|
KGE_DECLARE_SMART_PTR(Body);
|
2019-12-31 16:01:41 +08:00
|
|
|
|
|
2020-01-21 10:09:55 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* \addtogroup Physics
|
|
|
|
|
|
* @{
|
|
|
|
|
|
*/
|
2019-12-31 16:01:41 +08:00
|
|
|
|
|
2020-01-21 10:09:55 +08:00
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD>
|
|
|
|
|
|
class KGE_API Body : public virtual ObjectBase
|
|
|
|
|
|
{
|
|
|
|
|
|
public:
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
enum class Type
|
|
|
|
|
|
{
|
|
|
|
|
|
Static = 0, ///< <20><>̬<EFBFBD><CCAC><EFBFBD><EFBFBD>
|
|
|
|
|
|
Kinematic, ///< <20><><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD>
|
|
|
|
|
|
Dynamic, ///< <20><>̬<EFBFBD><CCAC><EFBFBD><EFBFBD>
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2020-02-06 16:54:47 +08:00
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><>ʼ<EFBFBD><CABC>
|
|
|
|
|
|
/// @param[in] world <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
/// @param[in] actor <20>Ľ<F3B6A8B5>ɫ
|
|
|
|
|
|
/// @param[in] type <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
static BodyPtr Create(World* world, ActorPtr actor, Type type);
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><>ʼ<EFBFBD><CABC>
|
|
|
|
|
|
/// @param[in] world <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
/// @param[in] actor <20>Ľ<F3B6A8B5>ɫ
|
|
|
|
|
|
/// @param[in] type <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
static BodyPtr Create(World* world, Actor* actor, Type type);
|
|
|
|
|
|
|
2020-01-21 10:09:55 +08:00
|
|
|
|
Body();
|
|
|
|
|
|
|
|
|
|
|
|
virtual ~Body();
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><>ʼ<EFBFBD><CABC>
|
|
|
|
|
|
/// @param[in] world <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
/// @param[in] actor <20>Ľ<F3B6A8B5>ɫ
|
|
|
|
|
|
bool InitBody(World* world, ActorPtr actor);
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><>ʼ<EFBFBD><CABC>
|
|
|
|
|
|
/// @param[in] world <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
/// @param[in] actor <20>Ľ<F3B6A8B5>ɫ
|
|
|
|
|
|
bool InitBody(World* world, Actor* actor);
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD>Ӽо<D3BC>
|
2020-02-06 16:54:47 +08:00
|
|
|
|
void AddFixture(FixturePtr fixture);
|
2020-01-21 10:09:55 +08:00
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD>Բ<EFBFBD>μо<CEBC>
|
|
|
|
|
|
/// @param radius Բ<>ΰ뾶
|
|
|
|
|
|
/// @param density <20><><EFBFBD><EFBFBD><EFBFBD>ܶ<EFBFBD>
|
2020-02-06 16:54:47 +08:00
|
|
|
|
/// @param
|
|
|
|
|
|
Fixture* AddCircleShape(float radius, float density, float friction = 0.2f, float restitution = 0.f,
|
|
|
|
|
|
bool is_sensor = false);
|
2020-01-21 10:09:55 +08:00
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
2020-02-06 16:54:47 +08:00
|
|
|
|
/// @brief <20><><EFBFBD>Ӿ<EFBFBD><D3BE>μо<CEBC>
|
|
|
|
|
|
/// @param size <20><><EFBFBD>δ<EFBFBD>С
|
2020-01-21 10:09:55 +08:00
|
|
|
|
/// @param density <20><><EFBFBD><EFBFBD><EFBFBD>ܶ<EFBFBD>
|
2020-02-06 16:54:47 +08:00
|
|
|
|
Fixture* AddRectShape(Vec2 const& size, float density, float friction = 0.2f, float restitution = 0.f,
|
|
|
|
|
|
bool is_sensor = false);
|
2020-01-21 10:09:55 +08:00
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD>Ӷ<EFBFBD><D3B6><EFBFBD><EFBFBD>μо<CEBC>
|
|
|
|
|
|
/// @param vertexs <20><><EFBFBD><EFBFBD><EFBFBD>ζ˵<CEB6>
|
|
|
|
|
|
/// @param density <20><><EFBFBD><EFBFBD><EFBFBD>ܶ<EFBFBD>
|
2020-02-06 16:54:47 +08:00
|
|
|
|
Fixture* AddPolygonShape(Vector<Point> const& vertexs, float density, float friction = 0.2f,
|
|
|
|
|
|
float restitution = 0.f, bool is_sensor = false);
|
2020-01-21 10:09:55 +08:00
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD>߶<EFBFBD><DFB6>μо<CEBC>
|
|
|
|
|
|
/// @param p1 <20>߶<EFBFBD><DFB6><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
/// @param p2 <20>߶<EFBFBD><DFB6>յ<EFBFBD>
|
|
|
|
|
|
/// @param density <20><><EFBFBD><EFBFBD><EFBFBD>ܶ<EFBFBD>
|
2020-02-06 16:54:47 +08:00
|
|
|
|
Fixture* AddEdgeShape(Point const& p1, Point const& p2, float density, float friction = 0.2f,
|
|
|
|
|
|
float restitution = 0.f, bool is_sensor = false);
|
2020-01-21 10:09:55 +08:00
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>μо<CEBC>
|
|
|
|
|
|
/// @param vertexs <20><><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD>
|
|
|
|
|
|
/// @param loop <20>Ƿ<EFBFBD><C7B7>պ<EFBFBD>
|
|
|
|
|
|
/// @param density <20><><EFBFBD><EFBFBD><EFBFBD>ܶ<EFBFBD>
|
2020-02-06 16:54:47 +08:00
|
|
|
|
Fixture* AddChainShape(Vector<Point> const& vertexs, bool loop, float density, float friction = 0.2f,
|
|
|
|
|
|
float restitution = 0.f, bool is_sensor = false);
|
2020-01-21 10:09:55 +08:00
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
2020-02-06 16:54:47 +08:00
|
|
|
|
/// @brief <20>Ƴ<EFBFBD><C6B3>о<EFBFBD>
|
|
|
|
|
|
void RemoveFixture(FixturePtr fixture);
|
2020-01-21 10:09:55 +08:00
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
2020-02-06 16:54:47 +08:00
|
|
|
|
/// @brief <20><>ȡ<EFBFBD>о<EFBFBD><D0BE>б<EFBFBD>
|
|
|
|
|
|
FixtureList GetFixtureList() const;
|
2020-01-21 10:09:55 +08:00
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><>ȡ<EFBFBD>Ӵ<EFBFBD><D3B4><EFBFBD><EFBFBD>б<EFBFBD>
|
|
|
|
|
|
ContactEdgeList GetContactList() const;
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
uint16_t GetCategoryBits() const;
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
void SetCategoryBits(uint16_t category_bits);
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><>ȡ<EFBFBD><C8A1>ײ<EFBFBD><D7B2><EFBFBD><EFBFBD>
|
|
|
|
|
|
uint16_t GetMaskBits() const;
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ײ<EFBFBD><D7B2><EFBFBD><EFBFBD>
|
|
|
|
|
|
void SetMaskBits(uint16_t mask_bits);
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
int16_t GetGroupIndex() const;
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
void SetGroupIndex(int16_t index);
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><>ȡ<EFBFBD><C8A1>ת<EFBFBD>Ƕ<EFBFBD>
|
|
|
|
|
|
float GetBodyRotation() const;
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD>Ƕ<EFBFBD>
|
|
|
|
|
|
void SetBodyRotation(float angle);
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
|
|
|
|
|
|
Point GetBodyPosition() const;
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
|
|
|
|
|
|
void SetBodyPosition(Point const& pos);
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief λ<>ú<EFBFBD><C3BA><EFBFBD>ת<EFBFBD>任
|
|
|
|
|
|
void SetBodyTransform(Point const& pos, float angle);
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD> [kg]
|
|
|
|
|
|
float GetMass() const;
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
|
|
|
|
|
|
float GetInertia() const;
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
/// @param[out] mass <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> [kg]
|
|
|
|
|
|
/// @param[out] center <20><><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
|
|
|
|
|
|
/// @param[out] inertia <20><><EFBFBD><EFBFBD>
|
|
|
|
|
|
void GetMassData(float* mass, Point* center, float* inertia) const;
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
/// @param mass <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> [kg]
|
|
|
|
|
|
/// @param center <20><><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
|
|
|
|
|
|
/// @param inertia <20><><EFBFBD><EFBFBD>
|
|
|
|
|
|
void SetMassData(float mass, Point const& center, float inertia);
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
void ResetMassData();
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ<EFBFBD>ϵĵ<CFB5><C4B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ<EFBFBD>λ<EFBFBD><CEBB>
|
|
|
|
|
|
Point GetLocalPoint(Point const& world) const;
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD>ϵĵ<CFB5><C4B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ<EFBFBD><CFB5>λ<EFBFBD><CEBB>
|
|
|
|
|
|
Point GetWorldPoint(Point const& local) const;
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
|
|
|
|
|
|
Point GetLocalCenter() const;
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
|
|
|
|
|
|
Point GetWorldCenter() const;
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
Type GetType() const;
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
void SetType(Type type);
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD><C4B1><EFBFBD>
|
|
|
|
|
|
float GetGravityScale() const;
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD><C4B1><EFBFBD>
|
|
|
|
|
|
void SetGravityScale(float scale);
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief ʩ<><CAA9>
|
|
|
|
|
|
/// @param force <20><><EFBFBD>Ĵ<EFBFBD>С<EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD>
|
|
|
|
|
|
/// @param point ʩ<><CAA9><EFBFBD><EFBFBD>
|
|
|
|
|
|
/// @param wake <20>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
void ApplyForce(Vec2 const& force, Point const& point, bool wake = true);
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʩ<EFBFBD><CAA9>
|
|
|
|
|
|
/// @param force <20><><EFBFBD>Ĵ<EFBFBD>С<EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD>
|
|
|
|
|
|
/// @param wake <20>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
void ApplyForceToCenter(Vec2 const& force, bool wake = true);
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief ʩ<><CAA9>Ť<EFBFBD><C5A4>
|
|
|
|
|
|
/// @param torque Ť<><C5A4>
|
|
|
|
|
|
/// @param wake <20>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
void ApplyTorque(float torque, bool wake = false);
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><>ת<EFBFBD>Ƕ<EFBFBD><C7B6>Ƿ<EFBFBD><C7B7>̶<EFBFBD>
|
|
|
|
|
|
bool IsIgnoreRotation() const;
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7>̶<EFBFBD><CCB6><EFBFBD>ת<EFBFBD>Ƕ<EFBFBD>
|
|
|
|
|
|
void SetIgnoreRotation(bool flag);
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>ӵ<EFBFBD><D3B5><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
bool IsBullet() const;
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>ӵ<EFBFBD><D3B5><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
void SetBullet(bool flag);
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>ڻ<EFBFBD><DABB><EFBFBD>״̬
|
|
|
|
|
|
bool IsAwake() const;
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD>û<EFBFBD><C3BB><EFBFBD>״̬
|
|
|
|
|
|
void SetAwake(bool flag);
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
bool IsSleepingAllowed() const;
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
void SetSleepingAllowed(bool flag);
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
bool IsActive() const;
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬
|
|
|
|
|
|
void SetActive(bool flag);
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
World* GetWorld() const;
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD>Ľ<F3B6A8B5>ɫ
|
|
|
|
|
|
Actor* GetActor() const;
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ľ<F3B6A8B5>ɫ
|
|
|
|
|
|
void SetActor(Actor* actor);
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD>µ<EFBFBD><C2B5><EFBFBD>ɫ
|
|
|
|
|
|
void UpdateActor();
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD>ɫ<EFBFBD><C9AB>Ϣ<EFBFBD><CFA2><EFBFBD>µ<EFBFBD><C2B5><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
void UpdateFromActor();
|
|
|
|
|
|
|
|
|
|
|
|
b2Body* GetB2Body() const;
|
|
|
|
|
|
void SetB2Body(b2Body* body);
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
void UpdateFixtureFilter(b2Fixture* fixture);
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
void Destroy();
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
Actor* actor_;
|
|
|
|
|
|
World* world_;
|
|
|
|
|
|
b2Body* body_;
|
|
|
|
|
|
|
|
|
|
|
|
uint16_t category_bits_;
|
|
|
|
|
|
uint16_t mask_bits_;
|
|
|
|
|
|
int16_t group_index_;
|
2020-02-06 16:54:47 +08:00
|
|
|
|
|
|
|
|
|
|
Vector<FixturePtr> fixtures_;
|
2020-01-21 10:09:55 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/** @} */
|
|
|
|
|
|
|
2020-02-06 16:54:47 +08:00
|
|
|
|
inline BodyPtr Body::Create(World* world, ActorPtr actor, Type type)
|
|
|
|
|
|
{
|
|
|
|
|
|
return Body::Create(world, actor.get(), type);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-01-21 10:09:55 +08:00
|
|
|
|
inline bool Body::InitBody(World* world, ActorPtr actor)
|
|
|
|
|
|
{
|
|
|
|
|
|
return InitBody(world, actor.get());
|
|
|
|
|
|
}
|
2019-12-31 16:01:41 +08:00
|
|
|
|
|
2020-01-21 10:09:55 +08:00
|
|
|
|
inline FixtureList Body::GetFixtureList() const
|
|
|
|
|
|
{
|
|
|
|
|
|
KGE_ASSERT(body_);
|
2020-02-06 16:54:47 +08:00
|
|
|
|
|
|
|
|
|
|
if (!body_->GetFixtureList())
|
|
|
|
|
|
return FixtureList();
|
|
|
|
|
|
|
|
|
|
|
|
Fixture* fixture = static_cast<Fixture*>(body_->GetFixtureList()->GetUserData());
|
|
|
|
|
|
return FixtureList(fixture);
|
2020-01-21 10:09:55 +08:00
|
|
|
|
}
|
2019-12-31 16:01:41 +08:00
|
|
|
|
|
2020-01-21 10:09:55 +08:00
|
|
|
|
inline ContactEdgeList Body::GetContactList() const
|
|
|
|
|
|
{
|
|
|
|
|
|
KGE_ASSERT(body_);
|
|
|
|
|
|
return ContactEdgeList(ContactEdge(body_->GetContactList()));
|
|
|
|
|
|
}
|
2019-12-31 16:01:41 +08:00
|
|
|
|
|
2020-01-21 10:09:55 +08:00
|
|
|
|
inline uint16_t Body::GetCategoryBits() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return category_bits_;
|
|
|
|
|
|
}
|
2019-12-31 16:01:41 +08:00
|
|
|
|
|
2020-01-21 10:09:55 +08:00
|
|
|
|
inline uint16_t Body::GetMaskBits() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return mask_bits_;
|
|
|
|
|
|
}
|
2019-12-31 16:01:41 +08:00
|
|
|
|
|
2020-01-21 10:09:55 +08:00
|
|
|
|
inline int16_t Body::GetGroupIndex() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return group_index_;
|
|
|
|
|
|
}
|
2019-12-31 16:01:41 +08:00
|
|
|
|
|
2020-01-21 10:09:55 +08:00
|
|
|
|
inline float Body::GetBodyRotation() const
|
|
|
|
|
|
{
|
|
|
|
|
|
KGE_ASSERT(body_);
|
|
|
|
|
|
return math::Radian2Degree(body_->GetAngle());
|
|
|
|
|
|
}
|
2019-12-31 16:01:41 +08:00
|
|
|
|
|
2020-01-21 10:09:55 +08:00
|
|
|
|
inline void Body::SetBodyRotation(float angle)
|
|
|
|
|
|
{
|
|
|
|
|
|
SetBodyTransform(GetBodyPosition(), angle);
|
|
|
|
|
|
}
|
2019-12-31 16:01:41 +08:00
|
|
|
|
|
2020-01-21 10:09:55 +08:00
|
|
|
|
inline void Body::SetBodyPosition(Point const& pos)
|
|
|
|
|
|
{
|
|
|
|
|
|
SetBodyTransform(pos, GetBodyRotation());
|
|
|
|
|
|
}
|
2019-12-31 16:01:41 +08:00
|
|
|
|
|
2020-01-21 10:09:55 +08:00
|
|
|
|
inline float Body::GetMass() const
|
|
|
|
|
|
{
|
|
|
|
|
|
KGE_ASSERT(body_);
|
|
|
|
|
|
return body_->GetMass();
|
|
|
|
|
|
}
|
2019-12-31 16:01:41 +08:00
|
|
|
|
|
2020-01-21 10:09:55 +08:00
|
|
|
|
inline float Body::GetInertia() const
|
|
|
|
|
|
{
|
|
|
|
|
|
KGE_ASSERT(body_);
|
|
|
|
|
|
return body_->GetInertia();
|
|
|
|
|
|
}
|
2019-12-31 16:01:41 +08:00
|
|
|
|
|
2020-01-21 10:09:55 +08:00
|
|
|
|
inline Body::Type Body::GetType() const
|
|
|
|
|
|
{
|
|
|
|
|
|
KGE_ASSERT(body_);
|
|
|
|
|
|
return Type(body_->GetType());
|
|
|
|
|
|
}
|
2019-12-31 16:01:41 +08:00
|
|
|
|
|
2020-01-21 10:09:55 +08:00
|
|
|
|
inline void Body::SetType(Type type)
|
|
|
|
|
|
{
|
|
|
|
|
|
KGE_ASSERT(body_);
|
|
|
|
|
|
body_->SetType(static_cast<b2BodyType>(type));
|
|
|
|
|
|
}
|
2019-12-31 16:01:41 +08:00
|
|
|
|
|
2020-01-21 10:09:55 +08:00
|
|
|
|
inline float Body::GetGravityScale() const
|
|
|
|
|
|
{
|
|
|
|
|
|
KGE_ASSERT(body_);
|
|
|
|
|
|
return body_->GetGravityScale();
|
|
|
|
|
|
}
|
2019-12-31 16:01:41 +08:00
|
|
|
|
|
2020-01-21 10:09:55 +08:00
|
|
|
|
inline void Body::SetGravityScale(float scale)
|
|
|
|
|
|
{
|
|
|
|
|
|
KGE_ASSERT(body_);
|
|
|
|
|
|
body_->SetGravityScale(scale);
|
|
|
|
|
|
}
|
2019-12-31 16:01:41 +08:00
|
|
|
|
|
2020-01-21 10:09:55 +08:00
|
|
|
|
inline bool Body::IsIgnoreRotation() const
|
|
|
|
|
|
{
|
|
|
|
|
|
KGE_ASSERT(body_);
|
|
|
|
|
|
return body_->IsFixedRotation();
|
|
|
|
|
|
}
|
2019-12-31 16:01:41 +08:00
|
|
|
|
|
2020-01-21 10:09:55 +08:00
|
|
|
|
inline void Body::SetIgnoreRotation(bool flag)
|
|
|
|
|
|
{
|
|
|
|
|
|
KGE_ASSERT(body_);
|
|
|
|
|
|
body_->SetFixedRotation(flag);
|
|
|
|
|
|
}
|
2019-12-31 16:01:41 +08:00
|
|
|
|
|
2020-01-21 10:09:55 +08:00
|
|
|
|
inline bool Body::IsBullet() const
|
|
|
|
|
|
{
|
|
|
|
|
|
KGE_ASSERT(body_);
|
|
|
|
|
|
return body_->IsBullet();
|
|
|
|
|
|
}
|
2019-12-31 16:01:41 +08:00
|
|
|
|
|
2020-01-21 10:09:55 +08:00
|
|
|
|
inline void Body::SetBullet(bool flag)
|
|
|
|
|
|
{
|
|
|
|
|
|
KGE_ASSERT(body_);
|
|
|
|
|
|
body_->SetBullet(flag);
|
|
|
|
|
|
}
|
2019-12-31 16:01:41 +08:00
|
|
|
|
|
2020-01-21 10:09:55 +08:00
|
|
|
|
inline bool Body::IsAwake() const
|
|
|
|
|
|
{
|
|
|
|
|
|
KGE_ASSERT(body_);
|
|
|
|
|
|
return body_->IsAwake();
|
|
|
|
|
|
}
|
2019-12-31 16:01:41 +08:00
|
|
|
|
|
2020-01-21 10:09:55 +08:00
|
|
|
|
inline void Body::SetAwake(bool flag)
|
|
|
|
|
|
{
|
|
|
|
|
|
KGE_ASSERT(body_);
|
|
|
|
|
|
body_->SetAwake(flag);
|
|
|
|
|
|
}
|
2019-12-31 16:01:41 +08:00
|
|
|
|
|
2020-01-21 10:09:55 +08:00
|
|
|
|
inline bool Body::IsSleepingAllowed() const
|
|
|
|
|
|
{
|
|
|
|
|
|
KGE_ASSERT(body_);
|
|
|
|
|
|
return body_->IsSleepingAllowed();
|
|
|
|
|
|
}
|
2019-12-31 16:01:41 +08:00
|
|
|
|
|
2020-01-21 10:09:55 +08:00
|
|
|
|
inline void Body::SetSleepingAllowed(bool flag)
|
|
|
|
|
|
{
|
|
|
|
|
|
KGE_ASSERT(body_);
|
|
|
|
|
|
body_->SetSleepingAllowed(flag);
|
|
|
|
|
|
}
|
2019-12-31 16:01:41 +08:00
|
|
|
|
|
2020-01-21 10:09:55 +08:00
|
|
|
|
inline bool Body::IsActive() const
|
|
|
|
|
|
{
|
|
|
|
|
|
KGE_ASSERT(body_);
|
|
|
|
|
|
return body_->IsActive();
|
|
|
|
|
|
}
|
2019-12-31 16:01:41 +08:00
|
|
|
|
|
2020-01-21 10:09:55 +08:00
|
|
|
|
inline void Body::SetActive(bool flag)
|
|
|
|
|
|
{
|
|
|
|
|
|
KGE_ASSERT(body_);
|
|
|
|
|
|
body_->SetActive(flag);
|
|
|
|
|
|
}
|
2019-12-31 16:01:41 +08:00
|
|
|
|
|
2020-01-21 10:09:55 +08:00
|
|
|
|
inline Actor* Body::GetActor() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return actor_;
|
|
|
|
|
|
}
|
2019-12-31 16:01:41 +08:00
|
|
|
|
|
2020-01-21 10:09:55 +08:00
|
|
|
|
inline void Body::SetActor(Actor* actor)
|
|
|
|
|
|
{
|
|
|
|
|
|
actor_ = actor;
|
|
|
|
|
|
}
|
2019-12-31 16:01:41 +08:00
|
|
|
|
|
2020-01-21 10:09:55 +08:00
|
|
|
|
inline b2Body* Body::GetB2Body() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return body_;
|
|
|
|
|
|
}
|
2019-12-31 16:01:41 +08:00
|
|
|
|
|
2020-01-21 10:09:55 +08:00
|
|
|
|
inline World* Body::GetWorld() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return world_;
|
2019-10-18 11:50:46 +08:00
|
|
|
|
}
|
2020-01-21 10:09:55 +08:00
|
|
|
|
} // namespace physics
|
|
|
|
|
|
} // namespace kiwano
|