ShitEngine
基于 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
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
}
Component.h
Core.h
SHIT_API
#define SHIT_API
定义
Core.h:14
SHIT_REFLECT_BODY
#define SHIT_REFLECT_BODY(Type)
定义
Macros.h:62
SHIT_REFLECT
#define SHIT_REFLECT(Mode)
定义
Macros.h:59
SHIT_META
#define SHIT_META(...)
定义
Macros.h:68
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:43
Shit::BoxCollider2D::getRestitution
float getRestitution() const
定义
BoxCollider2D.h:46
Shit::BoxCollider2D::BoxCollider2D
BoxCollider2D(const Vector2 &size)
Shit::BoxCollider2D::~BoxCollider2D
~BoxCollider2D() override
Shit::BoxCollider2D::getDensity
float getDensity() const
定义
BoxCollider2D.h:40
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
定义
AudioPlayer.h:10
Shit::Vector2
glm::vec2 Vector2
定义
Math.h:5
include
ShitEngine
Physics
BoxCollider2D.h
制作者
1.17.0