-- light source script

-- called when the script is attached to the light source
function OnCreate(self)
  -- object variable
  self.myvar = true;

  -- set the position of the light source in world space
  local pos = Vision.hkvVec3(50, -300, 60)
  Debug:PrintLine("Setting light source position: "..tostring(pos))
  self:SetPosition(pos)

  -- linear interpolation of colors
  local col1 = Vision.VColorRef(255,255,0,255)
  local col2 = Vision.VColorRef(255,0,255,255)
  local col3 = Vision.VColorRef()
  col3:Lerp(col1, col2, 0.5)
  Debug:PrintLine("Color Lerp: "..tostring(col3))
  
  -- set the color of the light source
  Debug:PrintLine("Setting light source color: ("..col3.r..", "..col3.g..", "..col3.b..", "..col3.a..")")
  self:SetColor(col3)

  -- call some functions on the light source
  self:SetMultiplier(2)
  self:SetRadius(500)
  
end

-- method
function OnThink(self)

  -- call these functions once only
  if (self.myvar == true) then
    Debug:PrintLine("Light Source: Testing object local variable. This should only print once");
    self.myvar = false;
    
    -- examine the light source's bounding box
    local bboxLight = self:GetBoundingBox()
    Debug:PrintLine("Bounding box of the light source: "..tostring(bboxLight))
    Debug:PrintLine("Max extent of the bounding box: "..bboxLight:GetMaxExtent())
    local bbox = Vision.hkvAlignedBBox(Vision.hkvVec3(1000,1000,1000), Vision.hkvVec3(1200,1200,1200))
    
    -- pending feature
    -- Debug:PrintLine("Min distance to other bounding box: "..bboxLight:GetMinDist(bbox))
    
    -- find an object (can be either an entity or a light source)
    -- note: this must be done here since we don't know whether the entity already exists in the OnCreate function
    local entity = Game:GetObject("the one")
    if (entity ~= nil) then
      -- attach the light source as a child to entity "the one"
      self:AttachToParent(entity)
    end
  end
  
  --self:Trigger()
end

