/*
 * (C) Copyright Chris B. Kaynor 2006
 * All Rights Reserved.
 *
 * CONTACT: chris@kaynor.net
*/

#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <assert.h>
#include <ctime> 
#include <string.h>

#ifdef __linux__
	#include <GL/glut.h>
	#include <GL/glext.h>
	#include <png.h>
	#include <pngconf.h>
	#include <zlib.h>
	#include <zconf.h>
#else
	#include "glut.h"
	#include "glext.h"
	#include "png.h"
	#include "pngconf.h"
	#include "zlib.h"
	#include "zconf.h"
#endif

#include "vector.h"
#include "data.h"

cbk_vector::cbk_vector(GLfloat value1, GLfloat value2, GLfloat value3)
{
	c_value1 = value1;
	c_value2 = value2;
	c_value3 = value3;
}

cbk_vector::cbk_vector(GLfloat *values)
{
	c_value1 = values[0];
	c_value2 = values[1];
	c_value3 = values[2];
}

cbk_vector::cbk_vector(void)
{
	c_value1 = 0;
	c_value2 = 0;
	c_value3 = 0;
}

GLfloat cbk_vector::GetValue(unsigned int ValueID)
{
	if (ValueID == 1) {
		return c_value1;
	}
	if (ValueID == 2) {
		return c_value2;
	}
	if (ValueID == 3) {
		return c_value3;
	}

	return 0.0f;
}

cbk_vector cbk_vector::SetValue(unsigned int ValueID, GLfloat Value)
{
	if (ValueID == 1) {
		c_value1 = Value;
	}
	if (ValueID == 2) {
		c_value2 = Value;
	}
	if (ValueID == 3) {
		c_value3 = Value;
	}

	cbk_vector tempVector(c_value1, c_value2, c_value3);
	return tempVector;
}

cbk_vector cbk_vector::SetValue(GLfloat Value1, GLfloat Value2, GLfloat Value3)
{
	c_value1 = Value1;
	c_value2 = Value2;
	c_value3 = Value3;
	
	cbk_vector tempVector(c_value1, c_value2, c_value3);
	return tempVector;
}

cbk_vector cbk_vector::SetValue(cbk_vector Value)
{
	c_value1 = Value.GetValue(1);
	c_value2 = Value.GetValue(2);
	c_value3 = Value.GetValue(3);
	
	cbk_vector tempVector(c_value1, c_value2, c_value3);
	return tempVector;
}

GLfloat cbk_vector::operator~()
{
	return (c_value1 * c_value1) + (c_value2 * c_value2) + (c_value3 * c_value3);
}

cbk_vector cbk_vector::operator+(cbk_vector Input)
{
	cbk_vector tempVector(Input.GetValue(1) + c_value1, Input.GetValue(2) + c_value2, Input.GetValue(3) + c_value3);
	return tempVector;
}

cbk_vector cbk_vector::operator-(cbk_vector Input)
{
	cbk_vector tempVector(Input.GetValue(1) - c_value1, Input.GetValue(2) - c_value2, Input.GetValue(3) - c_value3);
	return tempVector;
}

cbk_vector cbk_vector::operator*(GLfloat Input)
{
	cbk_vector tempVector(c_value1 * Input, c_value2 * Input, c_value3 * Input);
	return tempVector;
}

GLfloat cbk_vector::operator*(cbk_vector Input)
{
	return ((c_value1 * Input.GetValue(1)) + (c_value2 * Input.GetValue(2)) + (c_value3 * Input.GetValue(3)));
}

cbk_vector cbk_vector::operator/(GLfloat Input)
{
	cbk_vector tempVector(c_value1 / Input, c_value2 / Input, c_value3 / Input);
	return tempVector;
}

void cbk_vector::operator*=(GLfloat Input)
{
	c_value1 *= Input;
	c_value2 *= Input;
	c_value3 *= Input;
}

void cbk_vector::operator/=(GLfloat Input)
{
	c_value1 /= Input;
	c_value2 /= Input;
	c_value3 /= Input;
}

void cbk_vector::operator+=(cbk_vector Input)
{
	c_value1 += Input.GetValue(1);
	c_value2 += Input.GetValue(2);
	c_value3 += Input.GetValue(3);
}

void cbk_vector::operator-=(cbk_vector Input)
{
	c_value1 -= Input.GetValue(1);
	c_value2 -= Input.GetValue(2);
	c_value3 -= Input.GetValue(3);
}

GLfloat cbk_vector::GetMagitude()
{
	return sqrt(operator~());
}
