From 873e12e3cfae164b436d927f12dda3f8cfd0351d Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Wed, 9 Dec 2009 22:31:07 +0000 Subject: [PATCH] added std.loadModelBounds() git-svn-id: svn://anubis/anaglym/trunk@202 99a6e188-d820-4881-8870-2d33a10e2619 --- lib/std.lua | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/lib/std.lua b/lib/std.lua index 2554cf9..6565578 100644 --- a/lib/std.lua +++ b/lib/std.lua @@ -63,3 +63,31 @@ std.pcty = function(percent) local width, height = ag.getScreenSize() return height * percent end + +-- Load an object from a model file and figure out what scale +-- to use based on a maximum specified bounding box the model must fit in. +-- Input: +-- model_name: the string containing the name of the model to load +-- max_x, max_y, max_z: +std.loadModelBounds = function(model_name, max_x, max_y, max_z) + local tmp_model = ag.loadModel(model_name) + local sx, sy, sz = tmp_model:getSize() + tmp_model:destroy() + local scale = 1.0 + if (max_x > 0 and sx > 0) then + scale = max_x / sx + end + if (max_y > 0 and sy > 0) then + local s = max_y / sy + if (s < scale) then + scale = s + end + end + if (max_z > 0 and sz > 0) then + local s = max_z / sz + if (s < scale) then + scale = s + end + end + return ag.loadModel(model_name, scale) +end