![]() |
ShitEngine 1.4.2
基于 C++20 与 SDL3 的轻量级 2D 游戏引擎
|
2D 物理关节组件 更多...
#include <Joint2D.h>
Public 成员函数 | |
| Joint2D () | |
| ~Joint2D () override | |
| void | onCreate () override |
| void | onAttach () override |
| void | onDetach () override |
| void | onDestroy () override |
| void | onFieldChanged (const std::string &fieldName) override |
| 检查器直写反射字段后回调:把运行时字段改动同步到已创建的 Box2D 关节 | |
| void | setType (JointType type) |
| JointType | getType () const |
| void | setConnectedBody (RigidBody2D *body) |
| 设置另一端刚体(bodyB)。传 nullptr 清空。 | |
| RigidBody2D * | getConnectedBody () const |
| void | setAnchor (const Vector2 &anchor) |
| 世界锚点(像素)。默认取本刚体位置;revolute/weld/distance 共用心智模型。 | |
| const Vector2 & | getAnchor () const |
| void | setLength (float length) |
| 自然长度(像素),默认取两锚点当前距离 | |
| float | getLength () const |
| void | setEnableSpring (bool enable) |
| 是否作为弹簧(false=刚性距离) | |
| void | setHertz (float hertz) |
| 弹簧刚度(Hz) | |
| void | setDampingRatio (float ratio) |
| 弹簧阻尼比 | |
| void | setEnableMotor (bool enable) |
| void | setMotorSpeed (float speed) |
| 目标角速度(度/秒) | |
| void | setMaxMotorTorque (float torque) |
| void | setEnableLimit (bool enable) |
| void | setLowerAngle (float deg) |
| 角度下限(度) | |
| void | setUpperAngle (float deg) |
| 角度上限(度) | |
| void | setAxisAngle (float deg) |
| 滑动轴方向(度,相对 bodyA 局部) | |
| void | setLowerTranslation (float v) |
| 滑动下限(像素) | |
| void | setUpperTranslation (float v) |
| 滑动上限(像素) | |
| void | setMaxMotorForce (float force) |
| bool | hasValidJoint () const |
| int32_t | getJointIndex () const |
| uint16_t | getJointWorld0 () const |
| uint16_t | getJointGeneration () 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 |
| uint64_t | getUuid () const |
| 组件持久 ID(随 .scene 序列化,是 ComponentRef<T> 引用字段的寻址依据) | |
| void | setUuid (uint64_t uuid) |
| 直接设置组件 ID(仅引擎反序列化/索引维护使用;正常流程由构造函数随机分配) | |
友元 | |
| class | PhysicsSystem2D |
额外继承的成员函数 | |
| Protected 成员函数 继承自 Component | |
| void | setRegistered (bool registered) |
| Protected 属性 继承自 Component | |
| GameObject * | m_owner = nullptr |
| bool | m_isRegistered = false |
| uint64_t | m_uuid = 0 |
| 持久 ID(构造时随机分配;0 仅在序列化前尚未赋值时短暂存在) | |
2D 物理关节组件
把本 GameObject 上的 RigidBody2D(bodyA)与另一个刚体(bodyB,由 connectedBody 引用字段指定)用 Box2D 关节约束连接。必须挂在一个已挂 RigidBody2D 的 GameObject 上。
使用方式: auto* joint = go->addComponent<Shit::Joint2D>(); joint->setType(Shit::JointType::Revolute); joint->setConnectedBody(otherBody); // 或编辑器拖拽引用字段 joint->setAnchor({ 400, 100 }); // 世界锚点
关节生命周期由 PhysicsSystem2D 驱动:onAttach 时注册、Box2D joint 创建, 目标刚体缺失时每帧补建(自愈),卸下时销毁。
| Joint2D | ( | ) |
|
override |
|
inline |
| RigidBody2D * getConnectedBody | ( | ) | const |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
overridevirtual |
重载 Component .
|
overridevirtual |
重载 Component .
|
overridevirtual |
重载 Component .
|
overridevirtual |
重载 Component .
|
overridevirtual |
检查器直写反射字段后回调:把运行时字段改动同步到已创建的 Box2D 关节
重载 Component .
| void setAnchor | ( | const Vector2 & | anchor | ) |
世界锚点(像素)。默认取本刚体位置;revolute/weld/distance 共用心智模型。
| void setAxisAngle | ( | float | deg | ) |
滑动轴方向(度,相对 bodyA 局部)
| void setConnectedBody | ( | RigidBody2D * | body | ) |
设置另一端刚体(bodyB)。传 nullptr 清空。
| void setDampingRatio | ( | float | ratio | ) |
弹簧阻尼比
| void setEnableLimit | ( | bool | enable | ) |
| void setEnableMotor | ( | bool | enable | ) |
| void setEnableSpring | ( | bool | enable | ) |
是否作为弹簧(false=刚性距离)
| void setHertz | ( | float | hertz | ) |
弹簧刚度(Hz)
| void setLength | ( | float | length | ) |
自然长度(像素),默认取两锚点当前距离
| void setLowerAngle | ( | float | deg | ) |
角度下限(度)
| void setLowerTranslation | ( | float | v | ) |
滑动下限(像素)
| void setMaxMotorForce | ( | float | force | ) |
| void setMaxMotorTorque | ( | float | torque | ) |
| void setMotorSpeed | ( | float | speed | ) |
目标角速度(度/秒)
| void setType | ( | JointType | type | ) |
| void setUpperAngle | ( | float | deg | ) |
角度上限(度)
| void setUpperTranslation | ( | float | v | ) |
滑动上限(像素)
|
friend |