#ifdef _WINDOWS
#ifndef WINDOWS
#define WINDOWS
#endif
#endif

#include "ac_plugin.h"

//////////////////////////////////////////////////////////////
// This is our plugin's main function.
static void first_plugin()
{
   // Get a list of all selected vertices in the current document
   List *vlist = ac_selection_get_vertices_all();
   // If this list is NULL, then nothing was selected.  We can exit the plugin.
   if( vlist == NULL )
   {
      message_dialog( "first_plugin : nothing was selected" );
      return;
   }
   // Let's keep up with the number of vertices we change
   int num_verts_scaled = 0;
   // Iterate through the vertices
   for( List *pv = vlist; pv != NULL; pv = pv->next )
   {
      // Cast the current list item as a Vertex
      Vertex *currentVertex = ( Vertex * )( pv->data );
      // Scale the vertex by 50%
      currentVertex->x = currentVertex->x * 0.5f;
      currentVertex->y = currentVertex->y * 0.5f;
      currentVertex->z = currentVertex->z * 0.5f;
      // Increment our counter
      num_verts_scaled = num_verts_scaled + 1;
   }
   // We're done with the List --- we need to clean it up.
   // Some Lists returned from AC3D need to be cleaned up, some do not.
   // This one needs it.
   list_free( &vlist );
   // Recalculate the selected normals
   selected_calc_normals();
   // Recalculate the AC3D selection box.
   find_bounding_box();
   // Redraw all of the AC3D views to reflect any changes.
   redraw_all();
   // Update the User Interface
   display_status();
   // Show the user what we did
   display_message( "first_plugin : scaled %d vertices toward {0,0,0}", num_verts_scaled );
}
//////////////////////////////////////////////////////////////
// The plugin init function
AC3D_PLUGIN_FUNC int AC3DPluginInit( AC3DPluginInitData *d )
{
   static bool firstTime = true;
   if( firstTime )
   {
      // Add our command to AC3D.
      ac_add_command( "my_first_plugin", first_plugin );
      // Add a new menu item for our plugin under the "Tools" menu.
      // This will show up as "First plugin" under the Tools menu,
      // and will call the function we defined above.
      ac_add_tools_menu_item( "First plugin",
                              "ac3d my_first_plugin",
                              "My first plugin" );
      firstTime = false;
   }
   return 0;
}
//////////////////////////////////////////////////////////////
AC3D_PLUGIN_FUNC int AC3DPluginExit()
{
   return 0;
}
//////////////////////////////////////////////////////////////
AC3D_PLUGIN_FUNC char *AC3DPluginAbout()
{
   return( "First plugin - version 1.1 - Me" );
}
//////////////////////////////////////////////////////////////
AC3D_PLUGIN_FUNC char *AC3DPluginInfo()
{
   return( "This is my first plugin." );
}
