/*
   CMSC 427 - Term Project Candidate
   ---------------------------------

   Beth Weinstein - bweinste@wam.umd.edu
   Ben Stewart - stewartb@wam.umd.edu
   Nawfel Tricha - Topaz@endorproductions.com

   Minimal OpenGL project using Microsoft Visual C++.
   This project is a premilinary candidate for the term 
   project required by CMSC 427.

   ABSTRACT:
      In this project, we will develop several fast 
      rendering and collision routines which would 
      require C/C++ speed and accuracy and then 
      implement a VisualJ++ interface.

   MODULE:
      Fire fly particle module.
*/


#include "global.h"

/*
   NT:
   Listen to DSP:
*/
void GinnyListen(edict_t *self, struct winampVisModule *this_mod)
{
   register float kick = dsp.kick;

   self->origin[2] = -100 + kick * 20;
   self->rgba[0] = cam.RGB_filter[0];
   self->rgba[1] = cam.RGB_filter[1];
   self->rgba[2] = cam.RGB_filter[2];
   // Bounce the head:
   self->body->son[0]->son[0]->son[2]->angle[PITCH] = 20 * kick;
   self->body->son[0]->son[0]->son[2]->angle[ROLL] = -10 * kick;
   

/*
   if (dsp.tick & 1)
      {
      // Synchronize left arm:
      self->body->son[0]->son[0]->son[3]->angle[PITCH] = -10 + 20 * kick;
      // Synchronize right arm:
      self->body->son[0]->son[0]->son[4]->angle[PITCH] = 10 - 20 * kick;
      }
   else
      {
      // Synchronize left arm:
      self->body->son[0]->son[0]->son[3]->angle[PITCH] = 10 - 20 * kick;
      // Synchronize right arm:
      self->body->son[0]->son[0]->son[4]->angle[PITCH] = -10 + 20 * kick;
      }
*/
}

/*
   NT:
   Render Ginny model:
*/
void GinnyRender(edict_t *self)
{
   glShadeModel(GL_FLAT);
	glDisable(GL_POLYGON_SMOOTH);   
   glBlendFunc(GL_SRC_ALPHA, GL_DST_ALPHA);
   glPushMatrix();
   glLoadIdentity();
   glTranslatef(0, 0, self->origin[2]);
   glRotatef(-90, 1, 0, 0);
   glDisable(GL_TEXTURE_2D);
   RenderPart(self, self->body);
   glEnable(GL_TEXTURE_2D);
   glPopMatrix();
   glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
   glShadeModel(GL_SMOOTH);
	glEnable(GL_POLYGON_SMOOTH);   
}

/*
   NT:
   Spawn and initialize ginny model:
*/
#define GINNY_MODEL "c:/DiscoStu/gfx/ginny.lux"
edict_t *GinnySpawn()
{
   edict_t *ent;
   ent = EdictSpawn();
   if (!LuxorRead(GINNY_MODEL, ent))
      {
      EngineError ("SpawnGinny: Cannot load file %s!", GINNY_MODEL);
      return ent;
      }
   // State of entity:
   ent->state = ENT_ST_USED;

   ent->origin[0] = 0;
   ent->origin[1] = 7;
   ent->origin[2] = -100;
   ent->rgba[0] = 1;
   ent->rgba[3] = .1f;
   //ent->avelocity[YAW] = 1;
   ent->render = GinnyRender;
   ent->listen = GinnyListen;
   ent->scale = .01f;
   return ent;
}