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 2.00f, // Head
129 1.80f, // Neck
130 1.00f, // UpperTorso
131 1.00f, // LowerTorso
132 1.00f, // LeftUpperArm
133 1.00f, // LeftLowerArm
134 1.00f, // RightUpperArm
135 1.00f, // RightLowerArm
136 1.00f, // LeftUpperLeg
137 0.8f, // LeftLowerLeg
138 0.8f, // RightUpperLeg
139 0.8f, // 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
173 {
174 HitboxRig rig;
175 auto& defs = rig.definitions;
176 defs.reserve(12);
177
178 // clang-format off
179 // NOTE: In Mixamo rigs imported via assimp/ozz the bone-local +Y axis
180 // points from child toward parent (i.e. "up" for legs, "inward" for arms).
181 // Therefore offsets that push the capsule ALONG the bone (toward the child
182 // joint) use negative Y. The localAxis {0,-1,0} makes halfHeight extend
183 // in the -Y direction (along the bone) so the capsule covers from the bone
184 // origin toward the next joint. All magnitudes are WORLD units (player = 72 tall).
185 // boneName region offset radius halfH axis
186 defs.push_back({"mixamorig:Head", -1, BodyRegion::Head, {0, 3.4f, 1.1f}, 5.8f, 1.0f, {0,-1,0}});
187 defs.push_back({"mixamorig:Neck", -1, BodyRegion::Neck, {0, 1.3f, 0.6f}, 2.5f, 0.8f, {0,-1,0}});
188 defs.push_back({"mixamorig:Spine2", -1, BodyRegion::UpperTorso, {0, -2.8f, 0}, 7.45f, 2.5f, {0,-1,0}});
189 defs.push_back({"mixamorig:Spine1", -1, BodyRegion::LowerTorso, {0, -9.05f,-0.8f}, 8.0f, 0.9f, {0,-1,0}});
190 defs.push_back({"mixamorig:LeftArm", -1, BodyRegion::LeftUpperArm, {0, 4.2f, 0}, 2.8f, 5.1f, {0,-1,0}});
191 defs.push_back({"mixamorig:LeftForeArm", -1, BodyRegion::LeftLowerArm, {0, 9.7f, 0}, 2.5f, 7.7f, {0,-1,0}});
192 defs.push_back({"mixamorig:RightArm", -1, BodyRegion::RightUpperArm, {0, 4.2f, 0}, 2.8f, 5.1f, {0,-1,0}});
193 defs.push_back({"mixamorig:RightForeArm", -1, BodyRegion::RightLowerArm, {0, 9.7f, 0}, 2.5f, 7.7f, {0,-1,0}});
194 defs.push_back({"mixamorig:LeftUpLeg", -1, BodyRegion::LeftUpperLeg, {-1.1f,10.4f, 0}, 4.4f, 6.5f, {0,-1,0}});
195 defs.push_back({"mixamorig:LeftLeg", -1, BodyRegion::LeftLowerLeg, {0, 10.4f, 0}, 4.4f, 8.5f, {0,-1,0}});
196 defs.push_back({"mixamorig:RightUpLeg", -1, BodyRegion::RightUpperLeg, {1.1f, 10.4f, 0}, 4.4f, 6.5f, {0,-1,0}});
197 defs.push_back({"mixamorig:RightLeg", -1, BodyRegion::RightLowerLeg, {0, 10.4f, 0}, 4.4f, 8.5f, {0,-1,0}});
198 // clang-format on
199
200 return rig;
201 }
202
205 void resolveIndices(const std::unordered_map<std::string, int>& jointMap)
206 {
207 for (auto& def : definitions) {
208 auto it = jointMap.find(def.boneName);
209 if (it != jointMap.end()) {
210 def.boneIndex = it->second;
211 } else {
212 def.boneIndex = -1;
213 }
214 }
215 }
216};
217
219
225{
226 uint32_t tick = 0;
227 glm::vec3 shooterEye{0.0f};
228 glm::vec3 shooterDir{0.0f};
229 glm::vec3 targetPos{0.0f};
230 float targetYaw = 0.0f;
231 std::vector<WorldCapsule> clientCapsules;
232 std::vector<WorldCapsule> serverCapsules;
234 bool serverConfirmed = false;
235 bool serverRejected = false;
236};
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:225
uint32_t tick
Tick when the shot was fired.
Definition Hitbox.hpp:226
bool serverRejected
True if server rejected the hit.
Definition Hitbox.hpp:235
glm::vec3 shooterEye
Ray origin.
Definition Hitbox.hpp:227
glm::vec3 targetPos
Target entity position at time of shot.
Definition Hitbox.hpp:229
std::vector< WorldCapsule > clientCapsules
Client-side hitbox state.
Definition Hitbox.hpp:231
BodyRegion clientHitRegion
What the client thought it hit.
Definition Hitbox.hpp:233
float targetYaw
Target yaw at time of shot.
Definition Hitbox.hpp:230
std::vector< WorldCapsule > serverCapsules
Server-side state (filled on rejection).
Definition Hitbox.hpp:232
glm::vec3 shooterDir
Ray direction.
Definition Hitbox.hpp:228
bool serverConfirmed
True if server confirmed the hit.
Definition Hitbox.hpp:234
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, bone-local dir, WORLD-unit magnitude.
Definition Hitbox.hpp:85
float halfHeight
Capsule half-height of centerline (WORLD units).
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 (WORLD units; scale-invariant across rigs).
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:205
static HitboxRig buildMixamoDefault()
Build the default Mixamo-rig hitbox definitions (12 capsules).
Definition Hitbox.hpp:172
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