LockMatrix

This function pauses entity matrix updating. For faster performance, use this 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;
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/Characters/Barbarian/barbarian.mdl");
model->AddHook(Entity::UpdateMatrixHook,UpdateMatrixHook);

//Load a model
Model* model = Model::Load("Models/Trees/pine01.mdl");

//Load an animation onto the model
int animationsequence = model->LoadAnimation("Models/Trees/pine01@walk.mdl");


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;
}