require "luascape.math"
require "luascape.reflect"
require "luascape.scene"
require "luascape.visuals"

reflect.loadReflectors("physics")
reflect.makeNamespaceGlobal("scape::physics")

function randomPos(randomness, height)
  if not height then height = math.random()*randomness end
  return Vector(math.random()*randomness-randomness/2, height, math.random()*randomness-randomness/2)
end

function spawnPhysicsObject(type, root, space, position)
  print("Spawning "..type.name)
  local node = root.children:add(Node())
  node.name = type.name.." Node"
  local visual = type()
  node.visual = visual
  node.translation = position
  local controller = space:createControllerForNode(node)
end

function spawnRandomPhysicsObject(type, root, space, randomness, height)
  spawnPhysicsObject(type, root, space, randomPos(randomness, height))
end
