SetParent

This function can be used to parent one entity to another. A child entity will maintain the same local orientation when its parent moves.

Syntax

Example

#include "Leadwerks.h"

using namespace Leadwerks;
Entity* entity = NULL;
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, -4);
Light* light = DirectionalLight::Create();
light->SetRotation(35, 35, 0);

//Load a model
entity = Model::Box();

Entity* child = Model::Box(1, 1, 1);
child->SetParent(entity);
child->SetColor(1.0, 0.0, 0.0);
child->SetPosition(2, -2, 0);

child = Model::Box(1, 1, 1);
child->SetParent(entity);
child->SetColor(0.0, 1.0, 0.0);
child->SetPosition(-2, -2, 0);


while (true)
{
if (window->Closed() || window->KeyDown(Key::Escape)) return false;

Leadwerks::Time::Update();

entity->Turn(1.0*Leadwerks::Time::GetSpeed(), 2.0*Leadwerks::Time::GetSpeed(), 3.0*Leadwerks::Time::GetSpeed());

world->Update();
world->Render();
context->Sync();
}
return 0;
}