Added loading of model rig via LuaTables, minor code style cleanups

master
Martin Felis 2017-02-22 22:44:05 +01:00
parent aee0a433e8
commit caf00bc3ac
3 changed files with 35 additions and 6 deletions

View File

@ -15,8 +15,20 @@
#include "CharacterModule.h"
#include "rbdl/addons/luamodel/luatables.h"
// forward declaration of a function that is in the LuaModel addon
// of RBDL. We make it visible here to extract more information
// from the Lua file.
namespace RigidBodyDynamics {
namespace Addons {
bool LuaModelReadFromTable (LuaTable &model_table, Model *model, bool verbose);
}
}
using namespace std;
using namespace RigidBodyDynamics;
using namespace RigidBodyDynamics::Addons;
const float cJumpVelocity = 4.0f;
const float cVelocityDamping = 4.0f;
@ -24,6 +36,7 @@ const float cGravity = 9.81f;
const float cGroundAcceleration = 30.0f;
const float cCharacterHeight = 1.8f;
const float cCharacterWidth = 1.f;
const char* cRigModelFile = "data/models/model.lua";
CharacterEntity::CharacterEntity() {
entity = gRenderer->createEntity();
@ -31,7 +44,9 @@ CharacterEntity::CharacterEntity() {
mRigModel = new Model();
cout << "Creating render entity ... success!" << endl;
bool load_result = LoadRig (cRigModelFile);
assert (load_result);
cout << "Creating render entity mesh ..." << endl;
// Mesh* base_mesh = Mesh::sCreateUVSphere(45, 45, 0.9);
@ -84,9 +99,21 @@ CharacterEntity::~CharacterEntity() {
mRigModel = nullptr;
}
bool CharacterEntity::LoadRig(const char* filename) {
gLog ("Creating rig model from %s ... ", filename);
LuaTable model_table = LuaTable::fromFile (filename);
bool load_result = LuaModelReadFromTable (model_table, mRigModel, false);
gLog ("Creating rig model from %s ... %s", filename, load_result ? "success" : "failed!");
gLog ("Rig model has %d degrees of freedom", mRigModel->qdot_size);
return load_result;
}
static float cur_time = 0.0f;
void CharacterEntity::update(float dt) {
void CharacterEntity::Update(float dt) {
Vector3f mController_acceleration (
mController.mDirection[0] * cGroundAcceleration,
mController.mDirection[1] * cGroundAcceleration,
@ -144,7 +171,7 @@ void ShowCharacterPropertiesWindow (CharacterEntity* character) {
ImGui::Begin("Character");
if (ImGui::Button ("Reset")) {
character->reset();
character->Reset();
}
ImGui::DragFloat3 ("Position", character->mPosition.data(), 0.01, -10.0f, 10.0f);

View File

@ -52,13 +52,15 @@ struct CharacterEntity {
CharacterEntity ();
~CharacterEntity ();
void reset() {
void Reset() {
mPosition.setZero();
mVelocity.setZero();
mController.reset();
}
void update(float dt);
bool LoadRig (const char* filename);
void Update(float dt);
};
void ShowCharacterPropertiesWindow (CharacterEntity* character);

View File

@ -168,7 +168,7 @@ void handle_keyboard (struct module_state *state, float dt) {
void update_character(module_state* state, float dt) {
if (state->character != nullptr) {
state->character->update(dt);
state->character->Update(dt);
}
}