AddVertex
This function adds a new triangle to a surface.
Syntax
- int AddVertex(float x, float y, float z, float nx=0.0, float ny=0.0, float nz=0.0, float u0=0.0, float v0=0.0, float u1=0.0, float v1=0.0, float r=1.0, float g=1.0, float b=1.0, float a=1.0)
- int AddVertex(const Vec3& position, const Vec3& normal=Vec3(0), const Vec2& texcoords0=Vec2(0), const Vec2& texcoords1=Vec2(0), const Vec4& color=Vec4(1))
Parameters
- x: the X component of the vertex position.
- y: the Y component of the vertex position.
- z: the Z component of the vertex position.
- nx: the X component of the vertex position.
- ny: the X component of the vertex position.
- nz: the X component of the vertex position.
- u0: the first vertex indice to add.
- v0: the second vertex indice to add.
- u1: the third vertex indice to add.
- v1: the first vertex indice to add.
- r: the red component of the vertex color.
- g: the green component of the vertex color.
- b: the blue component of the vertex color.
- a: the alpha component of the vertex color.
- position: the vertex position.
- normal: the vertex normal.
- texcoords0: the first vertex texcoord set.
- texcoords1: the second vertex texcoord set.
- color: the vertex color.
Returns
Returns the index of the new vertex, equal to the number of vertices 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;
}