/*****************************************************************************
 * $LastChangedDate: 2011-03-15 14:18:37 -0400 (Tue, 15 Mar 2011) $
 * @file
 * @author  Jim E. Brooks  http://www.palomino3d.org
 * @brief   Interface of C functions for Lua scripts.
 * @remarks @remarks module.txt documents how to export new C++ classes to Lua.
 *
 * ----------------------------
 * -- THIS IS AUTO-GENERATED --
 * ----------------------------
 *
 *//*
 * LEGAL:   COPYRIGHT (C) 2008 JIM E. BROOKS
 *          THIS SOURCE CODE IS RELEASED UNDER THE TERMS
 *          OF THE GNU GENERAL PUBLIC LICENSE VERSION 2 (GPL 2).
 *****************************************************************************/

#include "base/module.hh"
using namespace base;
#include "view/module.hh"
#include "view/view.hh"
#include "view/viewpoint_chase.hh"
using namespace view;
#include "object/module.hh"
using namespace object;
#include "lua_bind/module.hh"
#include "lua_bind/bind.hh"

namespace lua {


namespace bind {

#define BIND_CLASS_NAME      "ChaseViewpoint"
#define BIND_METATABLE_NAME  LUABIND_METATABLE_STRING(BIND_CLASS_NAME)

//==============================================================================
// C functions called by Lua that access C++ objects.
//==============================================================================
// Need a function to check typesig because of macro/template limitations.
#if ! DOXYGEN
INTERN void
CheckTypesigChaseViewpoint( shptr<ChaseViewpoint> obj )
{
    CHECK_TYPESIG(obj,TYPESIG_CHASE_VIEWPOINT);
}
#endif // ! DOXYGEN

/*****************************************************************************
 * Lua's garbage collector indirectly invokes this C++ destructor.
 *****************************************************************************/
INTERN int 
ChaseViewpoint_Destroy( lua_State* L ) 
{ 
   try { 

        return DESTROY_USERDATA_SHPTR<ChaseViewpoint>( L, CheckTypesigChaseViewpoint );
    
   } CATCH_LUA_EXCEPTION 
   return 0; 
} 

/*****************************************************************************
 * ChaseViewpoint:Move( inc ) / inc is in world space.
 *****************************************************************************/
INTERN int 
ChaseViewpoint_Move( lua_State* L ) 
{ 
   try { 

        const fp inc = POP_FP( L );
        shptr<ChaseViewpoint> chaseViewpoint = POP_USERDATA_AS_SHPTR<ChaseViewpoint>( L );
        CHECK_TYPESIG(chaseViewpoint,TYPESIG_CHASE_VIEWPOINT);
        chaseViewpoint->Move( inc );
    
   } CATCH_LUA_EXCEPTION 
   return 0; 
} 

/*****************************************************************************
 * Viewpoint:New()
 *****************************************************************************/
INTERN int 
ChaseViewpoint_New( lua_State* L ) 
{ 
   try { 

        shptr<ChaseViewpoint> viewpoint = new ChaseViewpoint;
        return NEW_USERDATA_SHPTR<ChaseViewpoint>( L, viewpoint, BIND_METATABLE_NAME );
    
   } CATCH_LUA_EXCEPTION 
   return 0; 
} 

/*****************************************************************************
 * ChaseViewpoint:Reset()
 *****************************************************************************/
INTERN int 
ChaseViewpoint_Reset( lua_State* L ) 
{ 
   try { 

        shptr<ChaseViewpoint> chaseViewpoint = POP_USERDATA_AS_SHPTR<ChaseViewpoint>( L );
        CHECK_TYPESIG(chaseViewpoint,TYPESIG_CHASE_VIEWPOINT);
        chaseViewpoint->Reset();
    
   } CATCH_LUA_EXCEPTION 
   return 0; 
} 

/*****************************************************************************
 * ChaseViewpoint:Rotate( axis, radian )
 *****************************************************************************/
INTERN int 
ChaseViewpoint_Rotate( lua_State* L ) 
{ 
   try { 

        const Radian rad( POP_FP( L ) );
        const uint axis( POP_INT( L ) );
        shptr<ChaseViewpoint> chaseViewpoint = POP_USERDATA_AS_SHPTR<ChaseViewpoint>( L );
        CHECK_TYPESIG(chaseViewpoint,TYPESIG_CHASE_VIEWPOINT);
        chaseViewpoint->Rotate( axis, rad );
    
   } CATCH_LUA_EXCEPTION 
   return 0; 
} 

/*****************************************************************************
 * ChaseViewpoint:Save()
 *****************************************************************************/
INTERN int 
ChaseViewpoint_Save( lua_State* L ) 
{ 
   try { 

        shptr<ChaseViewpoint> chaseViewpoint = POP_USERDATA_AS_SHPTR<ChaseViewpoint>( L );
        CHECK_TYPESIG(chaseViewpoint,TYPESIG_CHASE_VIEWPOINT);
        chaseViewpoint->Save();
    
   } CATCH_LUA_EXCEPTION 
   return 0; 
} 

/*****************************************************************************
 * ChaseViewpoint:SetDistance( x,y,z|Vec3 )
 *****************************************************************************/
INTERN int 
ChaseViewpoint_SetDistance( lua_State* L ) 
{ 
   try { 

        const Vector3 distance = POP_VECTOR3<Vector3>( L );
        shptr<ChaseViewpoint> chaseViewpoint = POP_USERDATA_AS_SHPTR<ChaseViewpoint>( L );
        CHECK_TYPESIG(chaseViewpoint,TYPESIG_CHASE_VIEWPOINT);
        chaseViewpoint->SetDistance( distance );
    
   } CATCH_LUA_EXCEPTION 
   return 0; 
} 

/*****************************************************************************
 * ChaseViewpoint:SetTarget( Object )
 *****************************************************************************/
INTERN int 
ChaseViewpoint_SetTarget( lua_State* L ) 
{ 
   try { 

        // Example of Lua passing an Object-derivative (usually Aircraft)
        // which C++ then casts to a base class.
        shptr<Object> target = POP_USERDATA_AS_SHPTR<Object>( L );
        CHECK_TYPESIG(target,TYPESIG_OBJECT);

        shptr<ChaseViewpoint> chaseViewpoint = POP_USERDATA_AS_SHPTR<ChaseViewpoint>( L );
        CHECK_TYPESIG(chaseViewpoint,TYPESIG_CHASE_VIEWPOINT);

        chaseViewpoint->SetTarget( target );
    
   } CATCH_LUA_EXCEPTION 
   return 0; 
} 

//==============================================================================
// Register binding with Lua. 
//==============================================================================

#if ! DOXYGEN 

INTERN const struct luaL_reg sMethodTable[] =
{
  { "New", ChaseViewpoint_New },
  { "__gc", ChaseViewpoint_Destroy },
  { "Move", ChaseViewpoint_Move },
  { "Reset", ChaseViewpoint_Reset },
  { "Rotate", ChaseViewpoint_Rotate },
  { "Save", ChaseViewpoint_Save },
  { "SetDistance", ChaseViewpoint_SetDistance },
  { "SetTarget", ChaseViewpoint_SetTarget },
  { NULL, NULL }
};

void
RegisterChaseViewpoint( lua_State* L )
{
    REGISTER_BINDING( L,
                      BIND_METATABLE_NAME,
                      BIND_CLASS_NAME,
                      sMethodTable );
}

#endif // ! DOXYGEN 

} // namespace bind 

} // namespace lua 
