NPC code
This commit is contained in:
1 parent
2e4a7ab467
commit
995e2c8e5b
10 files changed
+923706
-167
No files matched your search
@@ -0,0 +1,59 @@
|
||||
#pragma once
|
||||
#include "BoneAnimatedModel.h"
|
||||
#include "render/Renderer.h"
|
||||
#include "render/TextureManager.h"
|
||||
#include <memory>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <cstdint>
|
||||
|
||||
namespace ZL {
|
||||
|
||||
enum class AnimationState {
|
||||
IDLE = 0,
|
||||
WALK = 1
|
||||
};
|
||||
|
||||
class Character {
|
||||
public:
|
||||
void loadAnimation(AnimationState state, const std::string& filename, const std::string& zipFile = "");
|
||||
void setTexture(std::shared_ptr<Texture> texture);
|
||||
void update(int64_t deltaMs);
|
||||
void setTarget(const Eigen::Vector3f& target);
|
||||
void draw(Renderer& renderer);
|
||||
|
||||
// Public: read by Game for camera tracking and ray-cast origin
|
||||
Eigen::Vector3f position = Eigen::Vector3f(0.f, 0.f, 0.f);
|
||||
float facingAngle = 0.0f;
|
||||
|
||||
// Per-character tuning — set after construction, before first update
|
||||
float walkSpeed = 3.0f;
|
||||
float rotationSpeed = 4.0f;
|
||||
float modelScale = 0.12f;
|
||||
// Applied after scale, fixes model-space orientation (e.g. Blender Z-up exports)
|
||||
Eigen::Quaternionf modelCorrectionRotation = Eigen::Quaternionf::Identity();
|
||||
|
||||
private:
|
||||
struct AnimationData {
|
||||
BoneSystem model;
|
||||
VertexRenderStruct modelMutable;
|
||||
float currentFrame = 0.f;
|
||||
int lastFrame = -1;
|
||||
int totalFrames = 1;
|
||||
};
|
||||
|
||||
std::map<AnimationState, AnimationData> animations;
|
||||
AnimationState currentState = AnimationState::IDLE;
|
||||
std::shared_ptr<Texture> texture;
|
||||
|
||||
Eigen::Vector3f walkTarget = Eigen::Vector3f(0.f, 0.f, 0.f);
|
||||
float targetFacingAngle = 0.0f;
|
||||
|
||||
static constexpr float WALK_THRESHOLD = 0.05f;
|
||||
|
||||
// Returns the animation state to actually play/draw, falling back to IDLE
|
||||
// if the requested state has no loaded animation.
|
||||
AnimationState resolveActiveState() const;
|
||||
};
|
||||
|
||||
} // namespace ZL
|
||||
Reference in new issue
Block a user