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

--Create a window
window = Window:Create()
context = Context:Create(window)
world = World:Create()
local camera = Camera:Create()
camera:SetRotation(35,0,0)
camera:Move(0,0,-4)
local light = DirectionalLight:Create()
light:SetRotation(35,35,0)

--Create a model from scratch
local model = Model:Create()
local 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)
model:UpdateAABB(Entity.GlobalAABB)

--Load a material and apply it
local material = Material:Load("Materials/Concrete/concrete_dirty.mat")
model:SetMaterial(material)
material:Release()

while true do
if window:Closed() or window:KeyHit(Key.Escape) then return false end

Time:Update()
world:Update()
world:Render()
context:Sync()

end