/* polytope.h: This file is based on the original file form the I_COLLIDE
         library. Data structure for Polytope and Status are modified to
         meet our needs.   Modified by Peng Zhang in Nov.12, 1995            */



/*****************************************************************************\
  polytope.h
  --
  Description : Some types and constants for the nbody simulation

\*****************************************************************************/

/* Protection from multiple includes. */
#ifndef INCLUDED_NBODY_POLYTOPE_H
#define INCLUDED_NBODY_POLYTOPE_H


/*------------------ Includes Needed for Definitions Below ------------------*/

#include <quat.h>
#include "matrix.h"
#include <dist.h>
#include <collision_types.h>

/*-------------------------------- Constants --------------------------------*/

#define DEFAULT_FRAMES          1000
#define DEFAULT_LIBRARY        "poly.dat"
#define DEFAULT_SIM_POLY       "sim.dat"
#define DEFAULT_TICK            0.10    
#define DEFAULT_GRAVITY         0.49
#define DEFAULT_CUBE_BOUND      10.0
#define DEFAULT_MAX_POLYTOPE    40
#define DEFAULT_USE_BOX         0
#define DEFAULT_CORRECTION      1

/*--------------------------------- Macros ----------------------------------*/


/*---------------------------------- Types ----------------------------------*/

/*
   nbody's polytope structure
*/
typedef struct Polytope
{
  int           id;                      /* id number from collision library */

  int           colliding;        /* id of polytope currently colliding with */
  int           old_colliding;    /* id of polytope previoiusly colliding with */

  double        object_center[3]; /* center of polytope in object coordinates */
  double        max_radius;       /* max distance from "center" to a vertex */
  double        density;          /* object density(gm/cm**3)               */
  double        friction;         /* coefficient of friction                */
  double        restit;           /* coefficent of restitution              */
  double        volumn;           /* object volumn(cm**3)                   */
  
  double        trans_vel[3];       /* translation velocity of object */
  double        trans_tot[3];       /* total amount of translation thus far */

  q_type        tot_quat;           /* current orientation */
  q_type        delta_quat;         /* incremental change to orientation */

  col_Mat4          tot;          /* current polytope transformation */

  col_Vect3     mass_center;  /* center of mass of polytope in object corrd  */
  col_Mat3      inertia;      /* moment of inertia of the polytope in        */
                              /* object coordinates                          */

  int           move;         /* flag to indicate if the polytope is fixed   */
                              /* of moveable. 1 for movable, 0 for fixed     */

} Polytope;  

/*
   simulation parameters, etc.
*/
typedef struct Status
{
  int         num_frames;           /* number of frames in simulation */
  int         num_lib_polytopes;    /* objects in library */
  int         num_polytopes;        /* instanced objects */
  double      gravity;              /* acceleration of gravity */
  double      tick;                 /* time elaps for each frame  */
  double      correction;           /* correction factor to compensate       */
  int         use_cuboid;           /* boolean - use cuboid or dynamic boxes */
  int         seed;                 /* random number seed to make reproducable
				       simulations */

  col_Report   *all_collisions;
  col_DistReport *all_dist;
  int         num_collisions;
} Status;

#define ALLOCATE(ptr, type, num)                        \
{                                                       \
    (ptr) = (type *) calloc((num), sizeof(type));       \
    if ((ptr) == NULL)                                  \
    {                                                   \
        printf("Could not allocate memory.\n");         \
        exit(1);                                        \
    }                                                   \
}

/*---------------------------- Function Prototypes --------------------------*/


/*---------------------------Globals (externed)------------------------------*/



/* Protection from multiple includes. */
#endif /* INCLUDED_NBODY_POLYTOPE_H */



/*****************************************************************************\
\*****************************************************************************/

