/* 
   Project: coevolutionary GP moto driving
   Dana Vrajitoru
   general.h
   
   Some functions that don't fit anywhere else.  
*/

#include "general.h"
#include <cmath>

// Add the speed to the angle and make sure that they are within the
// range 0 to 360.
void update_angle(GLfloat &angle, GLfloat &speed)
{
  angle += speed;
  while (angle < 0)
    angle += 360;
  while (angle >= 360)
    angle -= 360;
}

// Set the coordinates of a point with given values, 0 by default.
void set_point3f(Point3f &point, 
		 GLfloat x, GLfloat y, GLfloat z)
{
  point[0] = x;
  point[1] = y;
  point[2] = z;
}

// Rotate by a Point3f.
void rotate_point(const Point3f &v)
{
  glRotatef(v[0], 1, 0, 0);
  glRotatef(v[1], 0, 1, 0);
  glRotatef(v[2], 0, 0, 1);
}

// Transforming an angle from degrees to radians and the other way
// around.
float d2r(float angle)
{
  return M_PI * angle / 180.0;
}

float r2d(float angle)
{
  return 180.0 * angle / M_PI;
}
