-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCollidableObject.cpp
More file actions
93 lines (69 loc) · 2.28 KB
/
CollidableObject.cpp
File metadata and controls
93 lines (69 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include "CollidableObject.h"
#include "../CollidableObjectManager.h"
std::vector<int32_t> CollidableObject::_collidableBitTable(static_cast<int>(Type::TYPE_NUM), INT32_MAX);
CollidableObject::CollidableObject(Vector2D pos, ColliderShape *shape, Physicalbody *rigidbody)
: _position(pos)
, _direction(0, 1)
, _parent(nullptr)
, _collider(shape, rigidbody, this)
, _type(Type::DEFAULT)
{
OBJECT_MGR->Add(this);
}
CollidableObject::~CollidableObject()
{
OBJECT_MGR->Remove(this);
for (auto child : _children)
{
if (child != nullptr)
{
child->_parent = nullptr;
OBJECT_MGR->Remove(child);
}
}
}
void CollidableObject::ResetOnFrame()
{
_collider._physicalbody->_move = Vector2D::zero;
}
void CollidableObject::Update()
{
}
void CollidableObject::CollisionWith(CollidableObject &obj, const Solver &solver)
{
}
void CollidableObject::ContactWith(CollidableObject &obj)
{
}
void CollidableObject::LateUpdate()
{
}
void CollidableObject::SetCollidableFlag(Type type, Type opponentType, bool flag)
{
//�ǂ̃I�u�W�F�N�g�̃r�b�g�����X�V���邩�����o��
int index = static_cast<int>(type);
int opponentIndex = static_cast<int>(opponentType);
//�ΏۂƂ̔����ɗp�����r�b�g�̌��������o��
int32_t mine = static_cast<int32_t>(1 << index);
int32_t opponent = static_cast<int32_t>(1 << opponentIndex);
//�w�茅��0�ɂ������Ȃ��r�b�g���]���Ă���
if (!flag)
{
mine = INT32_MAX - mine;
opponent = INT32_MAX - opponent;
}
mine &= INT32_MAX;
opponent &= INT32_MAX;
//�w�����������o�������̒l�ōX�V
_collidableBitTable[index] &= opponent;
_collidableBitTable[opponentIndex] &= mine;
}
bool CollidableObject::IsCollidablePair(Type type, Type opponentType)
{
int index = static_cast<int>(type);
int shift = static_cast<int>(opponentType);
int32_t opponent = static_cast<int32_t>(1 << shift);
int32_t value = (_collidableBitTable[index] & opponent);
//�ω��Z���� 0 �łȂ����Γ������ׂ��y�A
return (value != 0);
}