group2 0.1.0
CSE 125 Group 2
Loading...
Searching...
No Matches
CharacterAnimator.hpp
Go to the documentation of this file.
1
3
4#pragma once
5
7#include "CharacterRig.hpp"
8#include "SkinningBackend.hpp"
12
13#include <array>
14#include <glm/glm.hpp>
15#include <glm/gtc/quaternion.hpp>
16#include <memory>
17#include <vector>
18
24{
25 glm::vec3 velocityWorld{0.0f};
26 float yawRad = 0.0f;
27 float pitchRad = 0.0f;
28 float spineBendMultiplier = 1.0f;
29 float hipLeanMultiplier = 0.0f;
31 float dtSec =
32 0.0f;
33 bool grounded = false;
34 bool sprinting = false;
35 bool crouching = false;
36 int moveMode = 0;
37 int wallRunSide = 0;
42 int emoteClip = static_cast<int>(ClipId::_Count);
43};
44
52static constexpr size_t kNumSamplerSlots = 5;
53
56{
58 float timeRatio = 0.0f;
59 float playbackSpeed = 1.0f;
60 float weight = 0.0f;
61 bool active = false;
62};
63
66static constexpr size_t kHandFingerIkCount = 5;
67
77{
78public:
79 CharacterAnimator(const CharacterRig& rig, const AnimationLibrary& library);
84 CharacterAnimator& operator=(CharacterAnimator&&) noexcept = delete;
85
89 void setSkinningBackend(const ISkinningBackend* backend);
90
94 void update(const AnimationInputs& inputs, float dt);
95
116 void renderFromServer(const AnimSnapshot& serverState, const AnimationInputs& inputs);
117
120 void computeSkinnedVertices(std::vector<std::vector<ModelVertex>>& out) const;
121
125 void setDebugOverride(ClipId id, bool loop = true);
126
128 [[nodiscard]] ClipId debugOverride() const noexcept;
129
131 [[nodiscard]] const std::array<ClipSampler, kNumSamplerSlots>& samplers() const noexcept;
132
134 void setDebugPlaybackSpeed(float mul) noexcept;
135
147 void applyWeaponHoldPose(const WeaponHoldPose& pose, float weight);
148
151 void updateSkinMatrices();
152
162 void applyRecoilImpulse(float strengthRad);
163
165 [[nodiscard]] int numJoints() const noexcept;
166
170 [[nodiscard]] int currentModeValue() const noexcept;
171
180 void setFrozen(bool frozen) noexcept;
181
190 [[nodiscard]] const std::vector<glm::mat4>& jointModelMatrices() const noexcept;
191
197 [[nodiscard]] const std::vector<glm::mat4>& skinMatrices() const noexcept;
198
199private:
207 void runSamplingAndSkinning(const AnimationInputs& inputs);
208
209 struct Impl;
210 std::unique_ptr<Impl> impl_;
211};
212
226[[nodiscard]] float computeIdleGroundedMinY(const CharacterRig& rig, const AnimationLibrary& library,
227 const glm::quat& orientationFix, float bindMeshMinY);
PR-27 — per-entity animation state snapshot, decoupled from CharacterAnimator.
Catalog of ozz animation clips shared across all animated entities.
ClipId
Enumerated clip IDs.
Definition AnimationLibrary.hpp:21
@ _Count
Sentinel; also used as "no clip / no override".
Definition AnimationLibrary.hpp:57
@ Idle
Definition AnimationLibrary.hpp:22
float computeIdleGroundedMinY(const CharacterRig &rig, const AnimationLibrary &library, const glm::quat &orientationFix, float bindMeshMinY)
Grounding reference that aligns the IDLE pose's feet with the floor.
Definition CharacterAnimator.cpp:1286
static constexpr size_t kHandFingerIkCount
Number of fingers per hand.
Definition CharacterAnimator.hpp:66
static constexpr size_t kNumSamplerSlots
Number of sampler slots available for the per-frame blend.
Definition CharacterAnimator.hpp:52
Shared skinned-character rig: skeleton, bind-pose mesh, skin weights.
Authored per-weapon hand grip poses (Phase C of the AAA IK overhaul).
Pluggable skinning interface — phase-1 CPU LBS; GPU backend slots in later.
Authored per-weapon third-person hold pose (FK weapon-hold rewrite).
Collection of animation clips loaded on top of a shared skeleton.
Definition AnimationLibrary.hpp:75
std::unique_ptr< Impl > impl_
Definition CharacterAnimator.hpp:210
void applyRecoilImpulse(float strengthRad)
Phase F additive recoil kick.
Definition CharacterAnimator.cpp:498
void applyWeaponHoldPose(const WeaponHoldPose &pose, float weight)
Pose both arms (and the gun-holding fingers) for a held weapon.
Definition CharacterAnimator.cpp:507
void setSkinningBackend(const ISkinningBackend *backend)
Set the skinning backend (non-owning).
Definition CharacterAnimator.cpp:470
void setDebugPlaybackSpeed(float mul) noexcept
Playback-speed multiplier applied in debug-override mode.
Definition CharacterAnimator.cpp:493
void renderFromServer(const AnimSnapshot &serverState, const AnimationInputs &inputs)
PR-29: render the entity at server-authoritative animation state.
Definition CharacterAnimator.cpp:994
ClipId debugOverride() const noexcept
Current debug override clip (_Count = no override).
Definition CharacterAnimator.cpp:483
const std::array< ClipSampler, kNumSamplerSlots > & samplers() const noexcept
Snapshot of the current sampler slots (for UI inspection).
Definition CharacterAnimator.cpp:488
CharacterAnimator(CharacterAnimator &&) noexcept=delete
void runSamplingAndSkinning(const AnimationInputs &inputs)
PR-29: shared back end for update() and renderFromServer().
Definition CharacterAnimator.cpp:1053
CharacterAnimator(const CharacterRig &rig, const AnimationLibrary &library)
Definition CharacterAnimator.cpp:343
int numJoints() const noexcept
Number of joints in the underlying rig.
Definition CharacterAnimator.cpp:590
CharacterAnimator(const CharacterAnimator &)=delete
const std::vector< glm::mat4 > & skinMatrices() const noexcept
Per-joint LBS skin matrices: procedural * modelMat * inverseBind.
Definition CharacterAnimator.cpp:610
void computeSkinnedVertices(std::vector< std::vector< ModelVertex > > &out) const
Apply CPU skinning to every rig mesh, producing animated vertices.
Definition CharacterAnimator.cpp:1273
void update(const AnimationInputs &inputs, float dt)
Advance the state machine, sample + blend, and compute skin matrices.
Definition CharacterAnimator.cpp:687
int currentModeValue() const noexcept
Current high-level animator mode as the underlying int of the private Mode enum (0 = Locomotion,...
Definition CharacterAnimator.cpp:595
void setFrozen(bool frozen) noexcept
Freeze animation playback.
Definition CharacterAnimator.cpp:600
void updateSkinMatrices()
Recompute skinMatrices() = jointModelMats * inverseBindMats.
Definition CharacterAnimator.cpp:580
void setDebugOverride(ClipId id, bool loop=true)
Force a single clip to play, bypassing the graph.
Definition CharacterAnimator.cpp:475
const std::vector< glm::mat4 > & jointModelMatrices() const noexcept
Model-space joint matrices with all procedural transforms applied (head pitch, wallrun mirror) but WI...
Definition CharacterAnimator.cpp:605
CharacterAnimator & operator=(const CharacterAnimator &)=delete
Shared skinned rig — skeleton + bind-pose meshes + joint map.
Definition CharacterRig.hpp:45
Abstract skinning backend.
Definition SkinningBackend.hpp:20
Definition AudioRuntime.hpp:365
Snapshot of an entity's full animation state at one instant.
Definition AnimSnapshot.hpp:73
Driving inputs for the animation state machine.
Definition CharacterAnimator.hpp:24
float pitchRad
Player pitch (radians, positive = looking down).
Definition CharacterAnimator.hpp:27
bool crouching
Crouch currently held (phase 1: note-only).
Definition CharacterAnimator.hpp:35
bool sprinting
Sprint key currently held.
Definition CharacterAnimator.hpp:34
glm::vec3 velocityWorld
World-space velocity (u/s).
Definition CharacterAnimator.hpp:25
float hipLeanMultiplier
Per-weapon-class hip-lean magnitude (radians of pelvis pitch per radian of camera pitch,...
Definition CharacterAnimator.hpp:29
int emoteClip
Full-body emote clip to force this frame, as the integer value of a ClipId.
Definition CharacterAnimator.hpp:42
float yawRad
Player yaw (radians).
Definition CharacterAnimator.hpp:26
float spineBendMultiplier
Per-weapon-class scaler on Phase F spine bend (1.0 = full).
Definition CharacterAnimator.hpp:28
bool grounded
Touching the ground this tick.
Definition CharacterAnimator.hpp:33
int wallRunSide
WallSide value: 0=None, 1=Left, 2=Right.
Definition CharacterAnimator.hpp:37
float dtSec
Frame delta time (s). Used by the breathing oscillator and recoil decay in runSamplingAndSkinning.
Definition CharacterAnimator.hpp:31
int moveMode
MoveMode value: 0=OnFoot, 1=Sliding, 2=WallRunning.
Definition CharacterAnimator.hpp:36
Definition CharacterAnimator.cpp:242
One active sampler slot contributing to the per-frame blend.
Definition CharacterAnimator.hpp:56
bool active
False = slot unused this frame.
Definition CharacterAnimator.hpp:61
float playbackSpeed
Multiplier applied to clip duration when advancing.
Definition CharacterAnimator.hpp:59
float weight
Blend weight; slots with weight 0 are skipped.
Definition CharacterAnimator.hpp:60
float timeRatio
Normalised playback time ∈ [0, 1].
Definition CharacterAnimator.hpp:58
One vertex in a skinned bind-pose mesh.
Definition SkinVertex.hpp:17
Authored per-weapon third-person hold pose (see file header).
Definition WeaponHoldPose.hpp:57