UnlockMatrix
This function resumes entity matrix updating after a matrix is locked. For faster performance, use Entity::LockMatrix() before calling multiple animation commands, then use Entity::UnlockMatrix() to resume entity matrix updating.
Syntax
Example
#include "Leadwerks.h"
using namespace Leadwerks;
Model* model = NULL;
int counter;
void UpdateMatrixHook(Entity* entity)
{
counter++;
}
int main(int argc, const char *argv[])
{
Leadwerks::Window* window = Leadwerks::Window::Create();
Context* context = Context::Create(window);
World* world = World::Create();
Camera* camera = Camera::Create();
camera->Move(0, 1, -3);
Light* light = DirectionalLight::Create();
light->SetRotation(35, 35, 0);
//Load a model
model = Model::Load("Models/Grass/grass01.mdl");
model->AddHook(Entity::UpdateMatrixHook, UpdateMatrixHook);
while (true)
{
if (window->Closed() || window->KeyDown(Key::Escape)) return false;
counter = 0;
//We're going to make a lot of changes to the entity orientation, but the expensive update
//stuff will only occur once per loop when we call Entity::UnlockMatrix()
bool mode = !window->KeyDown(Key::Space);
if (mode) model->LockMatrix();
model->SetAnimationFrame(Leadwerks::Time::GetCurrent() / 100.0, 1);
model->SetAnimationFrame(Leadwerks::Time::GetCurrent() / 100.0, 0.5, 1);
model->SetAnimationFrame(Leadwerks::Time::GetCurrent() / 100.0, 0.5, 2);
if (mode) model->UnlockMatrix();
Leadwerks::Time::Update();
world->Update();
world->Render();
context->SetBlendMode(Blend::Alpha);
context->DrawText("UpdateMatrixHook was called " + String(counter) + " times.", 2, 2);
context->DrawText("Hold space for slower mode.", 2, 22);
context->Sync();
}
return 0;
}