-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathObject3dHitbox.c
37 lines (30 loc) · 989 Bytes
/
Object3dHitbox.c
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
#include "Object3dHitbox.h"
void Object3dHitboxCreate(Object3dHitbox* self, Mesh* mesh, vec4 position, vec4 scale, vec4 rotationAxis, float rotationAngle)
{
Object3dCreate(&self->obj, mesh, position, scale, rotationAxis, rotationAngle);
self->hitboxesCount = 0;
}
void Object3dHitboxAddHitbox(Object3dHitbox* self, const Hitbox* hitbox)
{
if (self->hitboxesCount == OBJECT3D_HITBOXES_MAX_COUNT) return;
self->hitboxes[self->hitboxesCount] = *hitbox;
self->hitboxesCount++;
}
int Object3dHitboxCollide(const Object3dHitbox* self, const Object3dHitbox* other)
{
for (short i = 0; i < self->hitboxesCount; i++)
{
for (short j = 0; j < other->hitboxesCount; j++)
{
if (HitboxCollide(&self->hitboxes[i], &other->hitboxes[j])) return 1;
}
}
return 0;
}
void Object3dHitboxUpdate(Object3dHitbox* self)
{
for (size_t i = 0; i < self->hitboxesCount; i++)
{
self->hitboxes[i].position = make_vec3(self->obj.position.x, self->obj.position.y, self->obj.position.z);
}
}