ShitEngine
基于 C++20 与 SDL3 的轻量级 2D 游戏引擎
载入中...
搜索中...
未找到
BoxCollider2D.h
浏览该文件的文档.
1#pragma once
2#include "../Core/Core.h"
3#include "../Math.h"
5#include <cstdint>
6
7namespace Shit {
21 class SHIT_API SHIT_REFLECT(BlackList) BoxCollider2D : public Component {
23 public:
25 explicit BoxCollider2D(const Vector2& size);
26 ~BoxCollider2D() override;
27
28 void onAttach() override;
29 void onDetach() override;
30 void onDestroy() override;
31
34
35 // --- 配置(可在 onAttach 前后调用) ---
36 void setSize(const Vector2& size);
37 const Vector2& getSize() const { return m_size; }
38
39 void setDensity(float density);
40 float getDensity() const { return m_density; }
41
42 void setFriction(float friction);
43 float getFriction() const { return m_friction; }
44
45 void setRestitution(float restitution);
46 float getRestitution() const { return m_restitution; }
47
48 private:
49 SHIT_META(({.displayName = "Size", .tooltip = "碰撞盒像素尺寸(宽/高)"}))
50 Vector2 m_size{ 32.0f, 32.0f };
51 SHIT_META(({.displayName = "Density", .range = {0, 100}, .step = 0.1}))
52 float m_density = 1.0f;
53 SHIT_META(({.displayName = "Friction", .tooltip = "摩擦系数", .range = {0, 1}, .step = 0.05}))
54 float m_friction = 0.3f;
55 SHIT_META(({.displayName = "Restitution", .tooltip = "弹性系数", .range = {0, 1}, .step = 0.05}))
56 float m_restitution = 0.0f;
57
58 // b2ShapeId = {int32_t index1; uint16_t world0; uint16_t generation;}
59 SHIT_META(Disable)
60 int32_t m_shapeIndex = 0;
61 SHIT_META(Disable)
62 uint16_t m_shapeWorld0 = 0;
63 SHIT_META(Disable)
64 uint16_t m_shapeGeneration = 0;
65 SHIT_META(Disable)
66 bool m_shapeValid = false;
67 };
68}
#define SHIT_API
定义 Core.h:14
#define SHIT_REFLECT_BODY(Type)
定义 Macros.h:62
#define SHIT_REFLECT(Mode)
定义 Macros.h:59
#define SHIT_META(...)
定义 Macros.h:68
void setDensity(float density)
密度,默认 1.0f
void setSize(const Vector2 &size)
像素尺寸(宽/高)默认 {32, 32}
void setFriction(float friction)
摩擦系数,默认 0.3f
void setRestitution(float restitution)
弹性系数,默认 0.0f
float getFriction() const
定义 BoxCollider2D.h:43
float getRestitution() const
定义 BoxCollider2D.h:46
BoxCollider2D(const Vector2 &size)
~BoxCollider2D() override
float getDensity() const
定义 BoxCollider2D.h:40
const Vector2 & getSize() const
定义 BoxCollider2D.h:37
void onAttach() override
void onDetach() override
void ensureShape()
内部:若同物体存在有效刚体则创建碰撞形状(幂等)。刚体后置挂载时由物理系统补调。
void onDestroy() override
定义 AudioPlayer.h:10
glm::vec2 Vector2
定义 Math.h:5