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