PolyMesh

This function creates s new polymesh shape.

Syntax

Parameters

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;

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

//Create the ground
Model* ground = Model::Box(10,1,10);
ground->SetPosition(0,-0.5,0);
ground->SetColor(0,1,0);

//Create a shape
Shape* shape = Shape::Box(0,0,0, 0,0,0, 10,1,10);
ground->SetShape(shape);
shape->Release();

//Load a model
Model* model = Model::Load("Models/teapot.mdl");
model->SetPosition(0,0,0);
model->SetColor(0,0,1);
model->SetScale(4,4,4);

//Create a shape
shape = Shape::PolyMesh(model->GetSurface(0));
model->SetShape(shape);
model->SetPosition(0,0,0);
shape->Release();

//Create some objects to fall
model = Model::Sphere();
shape = Shape::Sphere();
model->SetShape(shape);
shape->Release();
model->SetMass(1);
model->SetColor(Math::Rnd(0,1),Math::Rnd(0,1),Math::Rnd(0,1));
model->SetPosition(Math::Rnd(-1,1),Math::Rnd(3,6),Math::Rnd(-1,1));

for (int i=0; i < 10; i++)
{
model = (Model*)model->Instance();
model->SetCollisionType(Collision::Prop);
model->SetColor(Math::Rnd(0,1),Math::Rnd(0,1),Math::Rnd(0,1));
model->SetPosition(Math::Rnd(-1,1),5+i*2,Math::Rnd(-1,1));
}


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

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