UpdateAABB

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

Syntax

Parameters

Example

#include "Leadwerks.h"

using namespace Leadwerks;
Model* model = NULL;
int counter;

void UpdateMatrixHook(Entity* entity)
{
counter++;
}
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);

//Create a model
model = Model::Box();

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

while (true)
{
if (window->Closed() || window->KeyDown(Key::Escape)) return false;

Leadwerks::Time::Update();

//===========================================
//Begin Model Modification
//===========================================
Surface* surface = model->GetSurface(0);
for (int v = 0; v CountVertices(); v++)
{
Vec3 position = surface->GetVertexPosition(v);
Vec3 normal = surface->GetVertexNormal(v);
Vec2 texcoords = surface->GetVertexTexCoords(v);
Vec4 color = surface->GetVertexColor(v);

position = position + normal * Vec3(Math::Sin(Leadwerks::Time::GetCurrent() / 10.0) * 0.001);
texcoords += Leadwerks::Time::GetSpeed() / 100.0;

surface->SetVertexPosition(v, position);
surface->SetVertexNormal(v, normal);
surface->SetVertexTexCoords(v, texcoords);
surface->SetVertexColor(v, color);
}

//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 | Entity::GlobalAABB);

//===========================================
//End Model Modification
//===========================================

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