//
// move.cc for graviball in
//
// Made by
// Login   <@epita.fr>
//
// Started on  Tue Nov 21 01:58:30 2006
// Last update Thu Nov 23 23:12:10 2006 
//

#include <math.h>
#include "move.hh"
#include "../factory/vertex.h"

void	move_dummy (struct s_block&, struct s_move&)
{
}

void	move_diagonal (struct s_block& block, struct s_move& move)
{
  float step;

  if (gl_vertex.time - move.startTime >= move.args[1])
  {
    move.startTime = gl_vertex.time;
    move.reverse = !move.reverse;
  }
  step = move.args[0] * (gl_vertex.time - move.startTime) / move.args[1];
  block.curOrigin.x = block.curOrigin.y = step;
  if (move.reverse)
  {
    block.curOrigin.x = move.args[0] - block.curOrigin.x;
    block.curOrigin.y = move.args[0] - block.curOrigin.y;
  }
  block.curOrigin.x += block.origin.x;
  block.curOrigin.y += block.origin.y;
}

void	move_circle (struct s_block& block, struct s_move& move)
{
  float step;

  step = 2 * 3.14159f * (gl_vertex.time - move.startTime)
    / move.args[1];
  block.curOrigin.x = block.origin.x + cos (step) + move.args[0];
  block.curOrigin.y = block.origin.y + sin (step) + move.args[0];
}

void	move_horizontal (struct s_block& block, struct s_move& move)
{
  if (gl_vertex.time - move.startTime >= move.args[1])
  {
    move.startTime = gl_vertex.time;
    move.reverse = !move.reverse;
  }
  block.curOrigin.x = move.args[0] * (gl_vertex.time - move.startTime)
    / move.args[1];
  if (move.reverse)
    block.curOrigin.x = move.args[0] - block.curOrigin.x;
  block.curOrigin.x += block.origin.x;
}

void	move_vertical (struct s_block& block, struct s_move& move)
{
  if (gl_vertex.time - move.startTime >= move.args[1])
  {
    move.startTime = gl_vertex.time;
    move.reverse = !move.reverse;
  }
  block.curOrigin.y = move.args[0] * (gl_vertex.time - move.startTime)
    / move.args[1];
  if (move.reverse)
    block.curOrigin.y = move.args[0] - block.curOrigin.y;
  block.curOrigin.y += block.origin.y;
}
