

function OnAfterSceneLoaded(self)
    -- setup single key behavior
	Input:SetKeyAsSingleHit(Vision.KEY_SPACE)
    Input:SetKeyAsSingleHit(Vision.KEY_O)
    
	-- enable debugging output
    -- any draw or output call to 'Debug' will be effectless when disabled
    Debug:Enable(true)
    Debug:SetupLines(10,4)
    
    -- memorize the other entities
    -- (instead you could just attach a lua script to this entities too)
    self.path = Game:GetPath("DemoPath")
    Vision.Assert(self.path~=nil)
    
    self.character = Game:GetEntity("DemoEntity")
    Vision.Assert(self.character~=nil)
    
    if Application:IsInEditor() and Application:GetEditorMode()~=Vision.EDITOR_PLAY then
        Debug:PrintLine("Please use 'Play the Game' mode!")
        self:SetThinkFunctionStatus(false)
    else
        Debug:PrintLine("Use your mouse and press 'SPACE' or 'O'")
        
        --setup the camera
        local cam = Game:GetCamera()
        cam:SetPosition(0,-3750,2800)
        cam:AttachToEntity(self, cam:GetPosition())
        cam:LookAt(self:GetPosition())
    end

end

function OnThink(self)
    local pos = self:GetPosition()
   
    -- toggle debug rendering on and off
    if Input:IsKeyPressed(Vision.KEY_O) then
        local status = not Debug:IsEnabled()
        Debug:Enable(status)
    end
    
    -- draw a wallmark on the floor (direction 0,0,-1)
    if Input:IsKeyPressed(Vision.KEY_SPACE) then
        local dir = Vision.hkvVec3(0,0,-1)
        -- you can also use BLEND_OPAQUE, BLEND_ADDITIVE or BLEND_MULTIPLY as blending mode
        Debug.Draw:Wallmark(pos,dir, "Textures/vision.dds", Vision.BLEND_ALPHA, 100, 90)
        -- note: the already created wallmarks will remain even if debugging is disabled
    end

    -- some samples of the draw interface:
    local color = Vision.V_RGBA_GREEN
    
	Debug.Draw:Line( Vision.hkvVec3(-1000,1000,0), Vision.hkvVec3(1000,-1000,0), color)
    Debug.Draw:Line( Vision.hkvVec3(-1000,-1000,0), Vision.hkvVec3(1000,1000,0), color)

    color = Vision.V_RGBA_RED
    Debug.Draw:Box( Vision.hkvVec3(-1000,1000,0), 50, color)
    Debug.Draw:Box( Vision.hkvVec3(1000,-1000,0), 50, color)
    
    --draw a path
    color = Vision.V_RGBA_BLUE
    Debug.Draw:Path(self.path, color)
    
    -- draw bone and oriented bounding boxes
    color = Vision.V_RGBA_YELLOW
    Debug.Draw:BoneBoundingBox(self.character, "skeleton1:Head", color)
    Debug.Draw:OrientedBoundingBox(self.character, color)
    

    -- output text at a specific location
    if self.character ~= nil then
        local warriorPos = self.character:GetPosition()
        Debug:PrintAt(warriorPos, "I'm floating at " .. tostring(warriorPos))
    end
    
    --draw aabbox
    Debug.Draw:BoundingBox(self)   
    
    -- or you could also manipulate the bounding box before drawing:
    --[[
    local box = self:GetBoundingBox()
    box.m_vMin = box.m_vMin * 3
    box.m_vMax = box.m_vMax * 3
    Debug.Draw:BoundingBox(box)
    ]]--
    
    -- or get the corners
    --[[
    local corners = self:GetBoundingBox():GetCorners()
    for i=1,#corners do
        Debug.Draw:Box(corners[i], 30, Vision.V_RGBA_PURPLE)
    end
    ]]--
    
    -- change the cursor object's position according to the mouse position
    local deltaX, deltaY = Input:GetMouseDelta()
    
    if Application:IsInEditor() then
      self:IncPosition(deltaX*40, -deltaY*40, 0) --depends on the edito setup
    else
      self:IncPosition(deltaX*800, -deltaY*800, 0)
    end
    
    -- do some additional debug output
    local x,y = Input:GetMousePosition()
    Debug:PrintAt(pos, "Mouse X: "..x.." Y: "..y)
end

