AddSurface

This function adds and returns a new surface on a model.

Syntax

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

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

local model = NULL

model = Model:Box()
model:SetColor(1.0,0.0,0.0)
model:SetPosition(-4,0,0)

model = Model:Cylinder()
model:SetColor(0.0,1.0,0.0)
model:SetPosition(-2,0,0)

model = Model:Cone()
model:SetColor(0.0,0.0,1.0)
model:SetPosition(0,0,0)

model = Model:Sphere()
model:SetColor(0.0,1.0,1.0)
model:SetPosition(2,0,0)

model = Model:Create()
model:SetColor(1.0,0.0,1.0)
model:SetPosition(4,0,0)

local surface = tolua.cast(model:AddSurface(),"Surface")
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:UpdateAABB()
model:UpdateAABB(Entity.LocalAABB)
model:UpdateAABB(Entity.GlobalAABB)

while true do

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

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

end