group2 0.1.0
CSE 125 Group 2
Loading...
Searching...
No Matches
Hitbox.hpp
Go to the documentation of this file.
1
9
10#pragma once
11
12#include <array>
13#include <cstdint>
14#include <glm/glm.hpp>
15#include <string>
16#include <unordered_map>
17#include <vector>
18
20
38
40inline const char* bodyRegionName(BodyRegion region)
41{
42 switch (region) {
44 return "Head";
46 return "Neck";
48 return "Upper Torso";
50 return "Lower Torso";
52 return "L Upper Arm";
54 return "L Lower Arm";
56 return "R Upper Arm";
58 return "R Lower Arm";
60 return "L Upper Leg";
62 return "L Lower Leg";
64 return "R Upper Leg";
66 return "R Lower Leg";
68 return "(none)";
69 }
70 return "(unknown)";
71}
72
74
81{
82 std::string boneName;
83 int boneIndex = -1;
85 glm::vec3 localOffset{0.0f};
86 float radius = 4.0f;
87 float halfHeight = 4.0f;
88 glm::vec3 localAxis{0.0f, 1.0f, 0.0f};
89};
90
92
95{
96 glm::vec3 pointA{0.0f};
97 glm::vec3 pointB{0.0f};
98 float radius = 0.0f;
100};
101
103
108{
109 std::vector<WorldCapsule> capsules;
110};
111
117{
118 std::vector<glm::mat4> matrices;
119};
120
122
125{
126 // clang-format off
127 std::array<float, static_cast<size_t>(BodyRegion::Count)> multipliers = {{
128 4.00f, // Head
129 2.00f, // Neck
130 1.00f, // UpperTorso
131 1.00f, // LowerTorso
132 0.90f, // LeftUpperArm
133 0.90f, // LeftLowerArm
134 0.90f, // RightUpperArm
135 0.90f, // RightLowerArm
136 0.75f, // LeftUpperLeg
137 0.75f, // LeftLowerLeg
138 0.75f, // RightUpperLeg
139 0.75f, // RightLowerLeg
140 }};
141 // clang-format on
142};
143
146{
147 static const DamageProfile profile;
148 return profile;
149}
150
152
159{
160 std::vector<HitboxDef> definitions;
161
168 {
169 HitboxRig rig;
170 auto& defs = rig.definitions;
171 defs.reserve(12);
172
173 // clang-format off
174 // NOTE: In Mixamo rigs imported via assimp/ozz the bone-local +Y axis
175 // points from child toward parent (i.e. "up" for legs, "inward" for arms).
176 // Therefore offsets that push the capsule ALONG the bone (toward the child
177 // joint) use negative Y. The localAxis {0,-1,0} makes halfHeight extend
178 // in the -Y direction (along the bone) so the capsule covers from the bone
179 // origin toward the next joint.
180 // boneName region offset radius halfH axis
181 defs.push_back({"mixamorig:Head", -1, BodyRegion::Head, {0, 8, 2.5f}, 13.7f, 2.4f, {0,-1,0}});
182 defs.push_back({"mixamorig:Neck", -1, BodyRegion::Neck, {0, 3, 1.5f}, 6.0f, 2.0f, {0,-1,0}});
183 defs.push_back({"mixamorig:Spine2", -1, BodyRegion::UpperTorso, {0, 0.5f,0}, 15.4f, 3.9f, {0,-1,0}});
184 defs.push_back({"mixamorig:Spine1", -1, BodyRegion::LowerTorso, {0, -22.5f,-2.0f}, 16.3f, 0.5f, {0,-1,0}});
185 defs.push_back({"mixamorig:LeftArm", -1, BodyRegion::LeftUpperArm, {0, 10, 0}, 6.7f, 12.0f, {0,-1,0}});
186 defs.push_back({"mixamorig:LeftForeArm", -1, BodyRegion::LeftLowerArm, {0, 23, 0}, 6.0f, 18.3f, {0,-1,0}});
187 defs.push_back({"mixamorig:RightArm", -1, BodyRegion::RightUpperArm, {0, 10, 0}, 6.7f, 12.0f, {0,-1,0}});
188 defs.push_back({"mixamorig:RightForeArm", -1, BodyRegion::RightLowerArm, {0, 23, 0}, 6.0f, 18.3f, {0,-1,0}});
189 defs.push_back({"mixamorig:LeftUpLeg", -1, BodyRegion::LeftUpperLeg, {-2.5f,24.5f,0}, 10.5f, 15.4f, {0,-1,0}});
190 defs.push_back({"mixamorig:LeftLeg", -1, BodyRegion::LeftLowerLeg, {0, 24.5f,0}, 8.3f, 20.0f, {0,-1,0}});
191 defs.push_back({"mixamorig:RightUpLeg", -1, BodyRegion::RightUpperLeg, {2.5f,24.5f,0}, 10.5f, 15.4f, {0,-1,0}});
192 defs.push_back({"mixamorig:RightLeg", -1, BodyRegion::RightLowerLeg, {0, 24.5f,0}, 8.3f, 20.0f, {0,-1,0}});
193 // clang-format on
194
195 return rig;
196 }
197
200 void resolveIndices(const std::unordered_map<std::string, int>& jointMap)
201 {
202 for (auto& def : definitions) {
203 auto it = jointMap.find(def.boneName);
204 if (it != jointMap.end()) {
205 def.boneIndex = it->second;
206 } else {
207 def.boneIndex = -1;
208 }
209 }
210 }
211};
212
214
220{
221 uint32_t tick = 0;
222 glm::vec3 shooterEye{0.0f};
223 glm::vec3 shooterDir{0.0f};
224 glm::vec3 targetPos{0.0f};
225 float targetYaw = 0.0f;
226 std::vector<WorldCapsule> clientCapsules;
227 std::vector<WorldCapsule> serverCapsules;
229 bool serverConfirmed = false;
230 bool serverRejected = false;
231};
const char * bodyRegionName(BodyRegion region)
Human-readable name for a body region (UI / kill feed / logging).
Definition Hitbox.hpp:40
BodyRegion
Body regions.
Definition Hitbox.hpp:23
@ RightLowerLeg
Definition Hitbox.hpp:35
@ LeftUpperLeg
Definition Hitbox.hpp:32
@ UpperTorso
Definition Hitbox.hpp:26
@ LeftLowerArm
Definition Hitbox.hpp:29
@ LowerTorso
Definition Hitbox.hpp:27
@ RightUpperLeg
Definition Hitbox.hpp:34
@ Neck
Definition Hitbox.hpp:25
@ RightUpperArm
Definition Hitbox.hpp:30
@ Head
Definition Hitbox.hpp:24
@ LeftUpperArm
Definition Hitbox.hpp:28
@ RightLowerArm
Definition Hitbox.hpp:31
@ LeftLowerLeg
Definition Hitbox.hpp:33
@ Count
Definition Hitbox.hpp:36
const DamageProfile & defaultDamageProfile()
Global (default) damage profile accessor.
Definition Hitbox.hpp:145
Damage profile.
Definition Hitbox.hpp:125
std::array< float, static_cast< size_t >(BodyRegion::Count)> multipliers
Definition Hitbox.hpp:127
Debug: hit detection snapshot (for client-server mismatch debugging).
Definition Hitbox.hpp:220
uint32_t tick
Tick when the shot was fired.
Definition Hitbox.hpp:221
bool serverRejected
True if server rejected the hit.
Definition Hitbox.hpp:230
glm::vec3 shooterEye
Ray origin.
Definition Hitbox.hpp:222
glm::vec3 targetPos
Target entity position at time of shot.
Definition Hitbox.hpp:224
std::vector< WorldCapsule > clientCapsules
Client-side hitbox state.
Definition Hitbox.hpp:226
BodyRegion clientHitRegion
What the client thought it hit.
Definition Hitbox.hpp:228
float targetYaw
Target yaw at time of shot.
Definition Hitbox.hpp:225
std::vector< WorldCapsule > serverCapsules
Server-side state (filled on rejection).
Definition Hitbox.hpp:227
glm::vec3 shooterDir
Ray direction.
Definition Hitbox.hpp:223
bool serverConfirmed
True if server confirmed the hit.
Definition Hitbox.hpp:229
Hitbox definition (static, per-rig).
Definition Hitbox.hpp:81
glm::vec3 localAxis
Capsule axis direction in bone-local space.
Definition Hitbox.hpp:88
glm::vec3 localOffset
Offset from bone origin in bone-local space.
Definition Hitbox.hpp:85
float halfHeight
Capsule half-height of centerline.
Definition Hitbox.hpp:87
int boneIndex
Resolved runtime joint index (-1 = unresolved).
Definition Hitbox.hpp:83
std::string boneName
Skeleton joint name (e.g. "mixamorig:Head").
Definition Hitbox.hpp:82
BodyRegion region
Which body part this covers.
Definition Hitbox.hpp:84
float radius
Capsule radius (rig model-space units).
Definition Hitbox.hpp:86
ECS components.
Definition Hitbox.hpp:108
std::vector< WorldCapsule > capsules
~12 capsules per character.
Definition Hitbox.hpp:109
Hitbox rig (shared per character archetype).
Definition Hitbox.hpp:159
std::vector< HitboxDef > definitions
Definition Hitbox.hpp:160
void resolveIndices(const std::unordered_map< std::string, int > &jointMap)
Resolve bone names to runtime joint indices.
Definition Hitbox.hpp:200
static HitboxRig buildMixamoDefault()
Build the default Mixamo-rig hitbox definitions (12 capsules).
Definition Hitbox.hpp:167
ECS component: per-entity model-space joint matrices from animation.
Definition Hitbox.hpp:117
std::vector< glm::mat4 > matrices
Model-space joint transforms, one per skeleton joint.
Definition Hitbox.hpp:118
Runtime capsule (world-space, per-entity, per-frame).
Definition Hitbox.hpp:95
glm::vec3 pointA
One endpoint of the capsule centerline.
Definition Hitbox.hpp:96
float radius
Capsule radius (world units).
Definition Hitbox.hpp:98
glm::vec3 pointB
Other endpoint of the capsule centerline.
Definition Hitbox.hpp:97
BodyRegion region
For damage multiplier lookup.
Definition Hitbox.hpp:99