SetMatrix
This function sets an entity's 4x4 matrix and updates the position, rotation, and scale.
Syntax
- void SetMatrix(const Mat4& mat, bool global = true)
Parameters
- global: if set to true, the entity matrix will be set in global space. Otherwise, the matrix will be set in local space.
Example
#include "Leadwerks.h"
using namespace Leadwerks;
Entity* entity1;
Entity* entity2;
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->SetRotation(35, 0, 0);
camera->Move(0, 0, -5);
Light* light = DirectionalLight::Create();
light->SetRotation(35, 35, 0);
//Create a model
entity1 = Model::Box();
entity1->SetColor(0.0, 0.0, 1.0);
entity1->SetPosition(-1, 0, 0);
entity2 = entity1->Instance();
entity2->SetColor(0.0, 1.0, 0.0);
while (true)
{
if (window->Closed() || window->KeyDown(Key::Escape)) return false;
Leadwerks::Time::Update();
world->Update();
world->Render();
entity1->Turn(0, Time::GetSpeed()*1.0, 0);
entity2->SetMatrix(entity1->GetMatrix());
entity2->Turn(0, 45, 0);
entity2->Translate(2, 0, 0);
context->Sync();
}
}