AddSurface

This function adds and returns a new surface on a model.

Syntax

Returns

Returns a new shape.

Remarks

A polymesh shape will collide with other objects, but does not move, i.e. it will react as if the mass is zero. If you want to create a shape from a surface that is physically reactive, use the Shape::ConvexHull() or Shape::ConvexDecomposition() functions.

Example

#include "Leadwerks.h"

using namespace Leadwerks;

Light* light = 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, -6);
Light* light = DirectionalLight::Create();
light->SetRotation(35, 35, 0);

Model* model = NULL;

model = Model::Box();
model->SetColor(1.0, 0.0, 0.0);
model->SetPosition(-4, 0, 0);

model = Model::Cylinder();
model->SetColor(0.0, 1.0, 0.0);
model->SetPosition(-2, 0, 0);

model = Model::Cone();
model->SetColor(0.0, 0.0, 1.0);
model->SetPosition(0, 0, 0);

model = Model::Sphere();
model->SetColor(0.0, 1.0, 1.0);
model->SetPosition(2, 0, 0);

model = Model::Create();
model->SetColor(1.0, 0.0, 1.0);
model->SetPosition(4, 0, 0);

Surface* surface = model->AddSurface();
surface->AddVertex(-0.5, -0.5, 0, 0, 0, -1);
surface->AddVertex(0.5, -0.5, 0, 0, 0, -1);
surface->AddVertex(0.5, 0.5, 0, 0, 0, -1);
surface->AddVertex(-0.5, 0.5, 0, 0, 0, -1);
surface->AddTriangle(2, 1, 0);
surface->AddTriangle(0, 3, 2);
surface->UpdateAABB();
model->UpdateAABB(Entity::LocalAABB | Entity::GlobalAABB);

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

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