UpdateAABB

This function recalculates an entity's axis-aligned bounding box (AABB).

Syntax

Parameters

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,-6)
local light = DirectionalLight:Create()
light:SetRotation(35,35,0)

--Create a model
model = Model:Box()

--Load a material
local material = Material:Load("Materials/Grass/grass01.mat")
model:SetMaterial(material)
material:Release()

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

Time:Update()

--===========================================
--Begin Model Modification
--===========================================
local surface = model:GetSurface(0)
for v=0, surface:CountVertices()-1 do

local position = surface:GetVertexPosition(v)
local normal = surface:GetVertexNormal(v)
local texcoords = surface:GetVertexTexCoords(v)
local color = surface:GetVertexColor(v)

position = position + normal * Vec3(Math:Sin(Time:GetCurrent()/10.0) * 0.001)
texcoords.x = texcoords.x + Time:GetSpeed()/100.0
texcoords.y = texcoords.y + Time:GetSpeed()/100.0

surface:SetVertexPosition(v,position)
surface:SetVertexNormal(v,normal)
surface:SetVertexTexCoords(v,texcoords)
surface:SetVertexColor(v,color)
end

--Update the surface AABB
surface:UpdateAABB()

--Update the model local and global AABBs so the renderer keeps proper track of it
model:UpdateAABB(Entity.LocalAABB)
model:UpdateAABB(Entity.GlobalAABB)

--===========================================
--End Model Modification
--===========================================

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