AddTriangle
This function adds a single triangle to the surface indice buffer. The indice values must be greater than -1 and less than Surface::CountVertices().
Syntax
- int AddTriangle(int a, int b, int c)
Parameters
- a: the first vertex indice to add.
- b: the second vertex indice to add.
- c: the third vertex indice to add.
Returns
Returns the new triangle index, equal to the number of triangles minus one.
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, -3);
Light* light = DirectionalLight::Create();
light->SetRotation(35, 35, 0);
Model* model = Model::Create();
model->SetColor(1.0, 0.0, 1.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->Update();
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;
}