Skip to content

Instantly share code, notes, and snippets.

@tylerneylon
Created October 13, 2015 01:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tylerneylon/5c7fc6cf2775e3f6ba9a to your computer and use it in GitHub Desktop.
Save tylerneylon/5c7fc6cf2775e3f6ba9a to your computer and use it in GitHub Desktop.
--[[ Summary: Below, "entity" and "item" may be different types.
They simply implement same-name methods.
--]]
-- A bit from entities.lua:
function entities.runloop(dt)
for _, entity in pairs(all_entities) do
entity:update_and_draw(dt)
end
end
-- A bit from Model.lua (caps because it's a type):
-- Call this as in model:look_at({x, y, z}).
-- This expects the input vector to be approximately a unit vector.
function Model_mt:look_at(dir)
-- Check that the input direction is close to being a unit vector.
assert(math.abs(Vec3.length(dir) - 1.0) < 0.001)
for _, item in pairs(self.items) do
item:look_at(unpack(dir))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment