/* 
   Project: coevolutionary GP moto driving
   Dana Vrajitoru
   driver_behave.cc
   
   The class that handles behavior for the driver.
  
**/

#include "driver_behave.h"

// Constructor: nothing to be done for now.
Driver_behave::Driver_behave(float size)
  :Driver_animate(size)
{
  set_frames();
}

//Destructor: nothing to do for now.
Driver_behave::~Driver_behave()
{;}

// Set the total number of frames to start an animation.
void Driver_behave::set_frames(int frames_number)
{
  current_frame = 0;
  all_frames = frames_number;
}

// Save the current position, rotation and angles.
void Driver_behave::snapshot(int i)
{
  for (int j=0; j<vector_numbers; j++)
    for (int k=0; k<3; k++)
      shots[i][j][k] = vectors[j][k];
}

// Interpolate between snapshots
void Driver_behave::interpolate_shot(int start, int end)
{
  if (all_frames && current_frame <= all_frames) {
    float alpha = float(current_frame) / all_frames;
    
    for (int i=0; i<vector_numbers; i++)
      for (int k=0; k<3; k++)
	vectors[i][k] = ((1-alpha) * shots[start][i][k] + 
			 alpha * shots[end][i][k]);
  }
}

// Put the driver on a motorcycle. All we know is the size of the
// motorcycle.
void Driver_behave::move_on_moto(float length, float width, float height)
{
  reset_angles();
  set_rotation(0, 90, 0);
  set_position(-0.08*length, 0.64*height-legs_size, 0);
  bend_knees(90);
  rotate_thighs_up(-35);
  rotate_thighs_out(15);
  rotate_arms_up(25);
  bend_forearms(40);
  rotate_arms_out(50);
}

// Builds the display lists.
void Driver_behave::draw()
{
  Driver_animate:: draw();
}

// Calls the display lists with appropriate transformations.
void Driver_behave::display()
{
  if (all_frames) {
    interpolate_shot();
    current_frame++;
  }
  Driver_animate:: display();
}
