UpdateTangentsAndBinormals

This function calculates binormals and tangets for an entire surface. These are needed for normal mapping to appear correctly.

Syntax

Returns

Returns true if the routine is able to successfully calculate binormals and tangets, otherwise false is returned.

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

//Create a model from scratch
Model* model = Model::Create();
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);

//Update the vertex tangents and binormals so normal mapping appears correctly
surface->UpdateTangentsAndBinormals();

model->UpdateAABB(Entity::LocalAABB|Entity::GlobalAABB);

//Load a material and apply it
Material* material = Material::Load("Materials/Concrete/concrete_dirty.mat");
model->SetMaterial(material);
material->Release();
while (true)
{
if (window->Closed() || window->KeyDown(Key::Escape)) return false;

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