|
ShitEngine
基于 C++20 与 SDL3 的轻量级 2D 游戏引擎
|
刚体组件 更多...
#include <RigidBody2D.h>
Public 类型 | |
| enum class | Type { Static = 0 , Kinematic = 1 , Dynamic = 2 } |
Public 成员函数 | |
| RigidBody2D () | |
| ~RigidBody2D () override | |
| void | onCreate () override |
| void | onAttach () override |
| void | onDetach () override |
| void | onDestroy () override |
| void | setBodyType (Type type) |
| Type | getBodyType () const |
| void | setGravityScale (float scale) |
| float | getGravityScale () const |
| void | setLinearDamping (float damping) |
| float | getLinearDamping () const |
| void | setFixedRotation (bool fixed) |
| bool | isFixedRotation () const |
| void | applyForce (const Vector2 &force, bool wake=true) |
| void | applyForceToCenter (const Vector2 &force, bool wake=true) |
| void | applyImpulse (const Vector2 &impulse, bool wake=true) |
| void | setLinearVelocity (const Vector2 &velocity) |
| Vector2 | getLinearVelocity () const |
| void | setTransform (const Vector2 &position, float rotationDegrees) |
| 传送/设置刚体位置与旋转(角度制,度)。Dynamic/Kinematic 会同时唤醒。 | |
| bool | hasValidBody () const |
| 物理体是否已创建 | |
| int32_t | getBodyIndex () const |
| uint16_t | getBodyWorld0 () const |
| uint16_t | getBodyGeneration () const |
| Public 成员函数 继承自 Component | |
| Component () | |
| virtual | ~Component ()=default |
| virtual void | onAfterDeserialize () |
| 反序列化完成后回调(Prefab::apply 逐组件调用一次,字段已写入)。 用于重建"直写字段绕过了 setter、无法自动触发的引擎状态"(如精灵纹理加载)。 | |
| Component (const Component &)=delete | |
| Component & | operator= (const Component &)=delete |
| Component (Component &&)=delete | |
| Component & | operator= (Component &&)=delete |
| GameObject * | getOwner () const |
| bool | isRegistered () const |
友元 | |
| class | PhysicsSystem2D |
额外继承的成员函数 | |
| Protected 成员函数 继承自 Component | |
| void | setRegistered (bool registered) |
| Protected 属性 继承自 Component | |
| GameObject * | m_owner = nullptr |
| bool | m_isRegistered = false |
刚体组件
为 GameObject 提供物理刚体属性。必须与 TransformComponent 同挂一个 GameObject 上(由 onAttach 从中读取初始位置)。
使用方式: auto* body = go->addComponent<Shit::RigidBody2D>(); body->setBodyType(Shit::RigidBody2D::Type::Dynamic); body->setGravityScale(1.0f);
创建 Collider 前必须先挂 RigidBody2D(BoxCollider2D/CircleCollider2D 的 onAttach 会自动查找同 GameObject 上的 RigidBody2D)。
|
strong |
| RigidBody2D | ( | ) |
|
override |
| void applyForce | ( | const Vector2 & | force, |
| bool | wake = true ) |
| void applyForceToCenter | ( | const Vector2 & | force, |
| bool | wake = true ) |
| void applyImpulse | ( | const Vector2 & | impulse, |
| bool | wake = true ) |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
| Vector2 getLinearVelocity | ( | ) | const |
|
inline |
物理体是否已创建
|
inline |
|
overridevirtual |
重载 Component .
|
overridevirtual |
重载 Component .
|
overridevirtual |
重载 Component .
|
overridevirtual |
重载 Component .
| void setBodyType | ( | Type | type | ) |
|
inline |
|
inline |
|
inline |
| void setLinearVelocity | ( | const Vector2 & | velocity | ) |
| void setTransform | ( | const Vector2 & | position, |
| float | rotationDegrees ) |
传送/设置刚体位置与旋转(角度制,度)。Dynamic/Kinematic 会同时唤醒。
|
friend |