working on bowling demo -- problem with destroying first instance of a loaded model
git-svn-id: svn://anubis/anaglym/trunk@206 99a6e188-d820-4881-8870-2d33a10e2619
This commit is contained in:
1 parent
bb76eb6e9b
commit
81738dec8a
7 files changed
+101
-21
No files matched your search
+37
-19
@@ -1,41 +1,59 @@
|
||||
|
||||
function setupPins()
|
||||
ag.import("std")
|
||||
|
||||
function resetPins()
|
||||
local head_x = 0
|
||||
local head_y = 15
|
||||
local spacing = 0.7
|
||||
for i = 1, 10 do
|
||||
if (pins[i] ~= nil) then
|
||||
pins[i]:destroy()
|
||||
end
|
||||
end
|
||||
local n = 1
|
||||
for row = 0, 4 do
|
||||
for j = 0, row do
|
||||
pins[n] = reference_pin:clone()
|
||||
pins[n]:setPosition(head_x - row * spacing / 2 + j * spacing,
|
||||
head_y + 0.866 * spacing * row,
|
||||
1 - pin_minz)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function setupStars()
|
||||
stars = {}
|
||||
stars = ag.startList()
|
||||
local dist = 500
|
||||
for i = 1, 1000 do
|
||||
local star = {}
|
||||
for i = 1, 500 do
|
||||
local rx = math.random() * math.pi * 2
|
||||
local ry = (math.random() - 0.5) * math.pi
|
||||
star.x = dist * math.cos(ry) * math.cos(rx)
|
||||
star.y = dist * math.cos(ry) * math.sin(rx)
|
||||
star.z = dist * math.sin(ry)
|
||||
star.size = math.random(2, 8)
|
||||
stars[i] = star
|
||||
end
|
||||
end
|
||||
|
||||
function drawStars()
|
||||
for i = 1, #stars do
|
||||
ag.drawPoint(stars[i].size, 1, 1, 1, stars[i].x, stars[i].y, stars[i].z)
|
||||
local x = dist * math.cos(ry) * math.cos(rx)
|
||||
local y = dist * math.cos(ry) * math.sin(rx)
|
||||
local z = dist * math.sin(ry)
|
||||
local size = math.random(1, 6)
|
||||
ag.drawPoint(size, 1, 1, 1, x, y, z)
|
||||
end
|
||||
ag.endList()
|
||||
end
|
||||
|
||||
function init_event()
|
||||
pins = {}
|
||||
lane = ag.loadModelStatic("bowling_lane")
|
||||
setupPins()
|
||||
local minx, miny, minz, maxx, maxy, maxz = lane:getAABB()
|
||||
local lane_bottom = minz
|
||||
pins = {}
|
||||
reference_pin = ag.loadModel("bowling_pin", 1.0/4.3)
|
||||
minx, miny, minz, maxx, maxy, maxz = reference_pin:getAABB()
|
||||
pin_minz = minz
|
||||
pin_maxz = maxz
|
||||
local box = ag.createBoxStatic(1, 1, 0.1)
|
||||
box:setColor(0, 0, 0)
|
||||
box:setPosition(0, 0, lane_bottom - (maxz - minz) - 0.4)
|
||||
reference_pin:setPosition(0, 0, lane_bottom - maxz - 0.1)
|
||||
resetPins()
|
||||
setupStars()
|
||||
ag.setCamera(0, -20, 5, 0, 20, 0)
|
||||
ag.setCamera(0, -10, 5, 0, 20, 0)
|
||||
end
|
||||
|
||||
function update_event()
|
||||
drawStars()
|
||||
ag.callList(stars)
|
||||
end
|
||||
+6
-2
@@ -74,19 +74,23 @@ std.loadModelBounds = function(model_name, max_x, max_y, max_z)
|
||||
local sx, sy, sz = tmp_model:getSize()
|
||||
tmp_model:destroy()
|
||||
local scale = 1.0
|
||||
local scale_set = false
|
||||
if (max_x > 0 and sx > 0) then
|
||||
scale = max_x / sx
|
||||
scale_set = true
|
||||
end
|
||||
if (max_y > 0 and sy > 0) then
|
||||
local s = max_y / sy
|
||||
if (s < scale) then
|
||||
if (s < scale or not scale_set) then
|
||||
scale = s
|
||||
scale_set = true
|
||||
end
|
||||
end
|
||||
if (max_z > 0 and sz > 0) then
|
||||
local s = max_z / sz
|
||||
if (s < scale) then
|
||||
if (s < scale or not scale_set) then
|
||||
scale = s
|
||||
scale_set = true
|
||||
end
|
||||
end
|
||||
return ag.loadModel(model_name, scale)
|
||||
|
||||
Reference in new issue
Block a user