Copy
This function creates and returns a unique duplicate of the specified entity.
Syntax
- Entity* Copy(bool recursive=true)
Parameters
- recursive: if set to true, copies of the entity's children will be made and parented to the new entity.
Example
#include "Leadwerks.h"
using namespace Leadwerks;
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, -6);
Light* light = DirectionalLight::Create();
light->SetRotation(35, 35, 0);
//Create a model
Model* model1 = Model::Box();
model1->SetPosition(-1, 0, 0);
model1->SetColor(0.0, 0.0, 1.0);
//Create a copy
Model* model2 = (Model*)model1->Copy();
model2->SetPosition(1, 0, 0);
model2->SetColor(0.0, 1.0, 0.0);
//Lets modify some vertices to show the copy is unique
Surface* surface = model2->GetSurface(0);
surface->SetVertexPosition(0, -0.5, -2, -0.5);
surface->UpdateAABB();
model2->UpdateAABB(Entity::LocalAABB | Entity::GlobalAABB);
while (true)
{
if (window->Closed() || window->KeyDown(Key::Escape)) return false;
Leadwerks::Leadwerks::Time::Update();
world->Update();
world->Render();
context->Sync();
}
}