------ All content © 2008 DigiPen (USA) Corporation, all rights reserved. ------
-- Author: Justin Whitney
-- Updated: 09/30/2008, jmw

dofile( "../../Assets/Scripts/key_name_mappings.lua" )
dofile( "../../Assets/Scripts/util_math.lua" )

local myData = Entity:Data()

Global:ToggleDebug()
Global:SetCameraTargetObject( Entity:GetMyPointer() )

while( 1 ) 
do
  coroutine.yield()

  Entity:SHR_Refresh( myData, true, true, true, true )
  
  --rotation
  local ROTATE_SPEED = 2
  
  if( Global:IsPressed( key_names_to_values( "Numpad 4" ) ) ) then
    myData.rot.x = myData.rot.x + ROTATE_SPEED
  end
  
  if( Global:IsPressed( key_names_to_values( "Numpad 6" ) ) ) then
    myData.rot.x = myData.rot.x - ROTATE_SPEED
  end
  
  if( Global:IsPressed( key_names_to_values( "Numpad 7" ) ) ) then
    myData.rot.y = myData.rot.y + ROTATE_SPEED
  end
  
  if( Global:IsPressed( key_names_to_values( "Numpad 9" ) ) ) then
    myData.rot.y = myData.rot.y - ROTATE_SPEED
  end
  
  if( Global:IsPressed( key_names_to_values( "Numpad 1" ) ) ) then
    myData.rot.z = myData.rot.z + ROTATE_SPEED
  end
  
  if( Global:IsPressed( key_names_to_values( "Numpad 3" ) ) ) then
    myData.rot.z = myData.rot.z - ROTATE_SPEED
  end
  
  Entity:SHR_sRotation(myData.rot.x, myData.rot.y, myData.rot.z)
  
  --velocity
  local ACCELERATION = 20
  local ax, ay, az = 0,0,0

  if( Global:IsPressed( key_names_to_values( "Arrow Right" ) ) ) then
    ax = ACCELERATION
  end
  
  if( Global:IsPressed( key_names_to_values( "Arrow Left" ) ) ) then
    ax = -ACCELERATION
  end
  
  if( Global:IsPressed( key_names_to_values( "Arrow Up" ) ) ) then
    ay = ACCELERATION
  end
  
  if( Global:IsPressed( key_names_to_values( "Arrow Down" ) ) ) then
    ay = -ACCELERATION
  end
  
  if( Global:IsPressed( key_names_to_values( "Numpad 8" ) ) ) then
    az = ACCELERATION
  end
  
  if( Global:IsPressed( key_names_to_values( "Numpad 2" ) ) ) then
    az = -ACCELERATION
  end
  
  Entity:PHY_AddAccelOnce(ax,ay,az)
  
end