2017-01-14 17:14:23 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <unordered_map>
|
|
|
|
|
|
|
|
#include "math_types.h"
|
|
|
|
|
|
|
|
#include "Globals.h"
|
|
|
|
|
|
|
|
#include "imgui_protot_ext.h"
|
2017-02-22 21:35:14 +01:00
|
|
|
#include "rbdl/rbdl.h"
|
|
|
|
#include "rbdl/addons/luamodel/luamodel.h"
|
|
|
|
|
|
|
|
namespace RigidBodyDynamics {
|
|
|
|
struct Model;
|
|
|
|
}
|
2017-01-14 17:14:23 +01:00
|
|
|
|
|
|
|
struct CharacterController {
|
|
|
|
enum ControllerState {
|
|
|
|
ControlStateJump,
|
|
|
|
ControlStateLast
|
|
|
|
};
|
|
|
|
|
2017-02-22 21:35:14 +01:00
|
|
|
bool mState[ControlStateLast];
|
2017-01-14 17:14:23 +01:00
|
|
|
|
2017-02-22 21:35:14 +01:00
|
|
|
Vector3f mDirection = Vector3f::Zero();
|
2017-01-14 17:14:23 +01:00
|
|
|
|
|
|
|
void reset() {
|
|
|
|
for (int i = 0; i < ControlStateLast; i++) {
|
2017-02-22 21:35:14 +01:00
|
|
|
mState[i] = false;
|
2017-01-14 17:14:23 +01:00
|
|
|
}
|
|
|
|
|
2017-02-22 21:35:14 +01:00
|
|
|
mDirection.setZero();
|
2017-01-14 17:14:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
CharacterController() {
|
|
|
|
reset();
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2017-03-11 22:16:12 +01:00
|
|
|
struct Animation {
|
|
|
|
bool Load(const char* filename);
|
|
|
|
void Sample (float cur_time, VectorNf& state);
|
|
|
|
bool mIsLooped = true;
|
|
|
|
float mDuration;
|
|
|
|
std::vector<VectorNf> mFrames;
|
|
|
|
std::vector<float> mFrameTimes;
|
|
|
|
};
|
|
|
|
|
2017-04-11 14:07:11 +02:00
|
|
|
struct IKConstraint {
|
|
|
|
bool mEnabled = true;
|
|
|
|
int mEffectorBodyId;
|
|
|
|
Vector3f mEffectorLocalOffset;
|
|
|
|
Vector3f mEffectorWorldTarget;
|
|
|
|
};
|
|
|
|
|
2017-01-14 17:14:23 +01:00
|
|
|
struct CharacterEntity {
|
|
|
|
/// Render entity
|
2017-02-26 14:28:08 +01:00
|
|
|
Entity *mEntity = nullptr;
|
2017-02-22 21:35:14 +01:00
|
|
|
Vector3f mPosition;
|
|
|
|
Vector3f mVelocity;
|
|
|
|
CharacterController mController;
|
|
|
|
|
|
|
|
RigidBodyDynamics::Model* mRigModel = nullptr;
|
2017-03-11 22:16:12 +01:00
|
|
|
struct RigState {
|
|
|
|
VectorNf q;
|
|
|
|
};
|
|
|
|
std::vector<int> mBoneFrameIndices;
|
|
|
|
RigState mRigState;
|
|
|
|
|
2017-04-11 14:07:11 +02:00
|
|
|
std::vector<IKConstraint> mIKConstraints;
|
|
|
|
RigidBodyDynamics::InverseKinematicsConstraintSet mIKConstraintSet;
|
|
|
|
|
2017-03-11 22:16:12 +01:00
|
|
|
Animation mAnimation;
|
|
|
|
float mAnimTime;
|
2017-01-14 17:14:23 +01:00
|
|
|
|
|
|
|
CharacterEntity ();
|
|
|
|
~CharacterEntity ();
|
|
|
|
|
2017-02-22 22:44:05 +01:00
|
|
|
void Reset() {
|
2017-02-22 21:35:14 +01:00
|
|
|
mPosition.setZero();
|
|
|
|
mVelocity.setZero();
|
|
|
|
mController.reset();
|
2017-01-14 17:14:23 +01:00
|
|
|
}
|
|
|
|
|
2017-02-22 22:44:05 +01:00
|
|
|
bool LoadRig (const char* filename);
|
2017-04-11 14:07:11 +02:00
|
|
|
void UpdateIKConstraintSet();
|
|
|
|
|
|
|
|
void ApplyCharacterController(float dt);
|
|
|
|
void ApplyIKConstraints();
|
2017-03-11 22:16:12 +01:00
|
|
|
void UpdateBoneMatrices();
|
2017-02-22 22:44:05 +01:00
|
|
|
|
|
|
|
void Update(float dt);
|
2017-01-14 17:14:23 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
void ShowCharacterPropertiesWindow (CharacterEntity* character);
|