/***************************************************************\
| |\  /|                                                We Put  |
| | >< Hypercosm            hc_vector3.js               3d      |
| |/  \|                                                To Work |
|***************************************************************|
|                                                               |
|        This file defines a simple three dimensional vector    |
|        data type and a few basic vector operations.           |
|                                                               |
|***************************************************************|
|                Copyright (c) 2007 Hypercosm, LLC.             |
\***************************************************************/


//
// "class" constructor
//


function HCVector3(x, y, z) {
  this.x = x;
  this.y = y;
  this.z = z;
  return this;
}    // HCVector3


//
// "class" methods
//


HCVector3.prototype.add = function(vector2) {
  this.x = this.x + vector2.x;
  this.y = this.y + vector2.y;
  this.z = this.z + vector2.z;
}    // addo


HCVector3.prototype.subtract = function(vector2) {
  this.x = this.x - vector2.x;
  this.y = this.y - vector2.y;
  this.z = this.z - vector2.z;
}    // subtract


HCVector3.prototype.multiplyBy = function(vector2) {
  this.x = this.x * vector2.x;
  this.y = this.y * vector2.y;
  this.z = this.z * vector2.z;
}    // multiplyBy


HCVector3.prototype.divideBy = function(vector2) {
  this.x = this.x / vector2.x;
  this.y = this.y / vector2.y;
  this.z = this.z / vector2.z;
}    // divideBy


HCVector3.prototype.scaleBy = function(scalar) {
  this.x = this.x * scalar;
  this.y = this.y * scalar;
  this.z = this.z * scalar;
}    // scaleBy


//
// "class" function methods
//


HCVector3.prototype.plus = function(vector2) {
  var x = this.x + vector2.x;
  var y = this.y + vector2.y;
  var z = this.z + vector2.z;
  return new HCVector3(x, y, z);
}    // plus


HCVector3.prototype.minus = function(vector2) {
  var x = this.x - vector2.x;
  var y = this.y - vector2.y;
  var z = this.z - vector2.z;
  return new HCVector3(x, y, z);
}    // minus


HCVector3.prototype.times = function(vector2) {
  var x = this.x * vector2.x;
  var y = this.y * vector2.y;
  var z = this.z * vector2.z;
  return new HCVector3(x, y, z);
}    // times


HCVector3.prototype.dividedBy = function(vector2) {
  var x = this.x / vector2.x;
  var y = this.y / vector2.y;
  var z = this.z / vector2.z;
  return new HCVector3(x, y, z);
}    // dividedBy


HCVector3.prototype.scaledBy = function(scalar) {
  var x = this.x * scalar;
  var y = this.y * scalar;
  var z = this.z * scalar;
  return new HCVector3(x, y, z);
}    // scaledBy


//
// vector operators
// 


HCVector3.prototype.dotProduct = function(vector2) {
  return (this.x * vector2.x) + (this.y * vector2.y) + (this.z * vector2.z);
}    // dotProduct


HCVector3.prototype.crossProduct = function(vector2) {
  var x = (this.y * vector2.z) - (this.z * vector2.y);
  var y = (this.z * vector2.x) - (this.x * vector2.z);
  var z = (this.x * vector2.y) - (this.y * vector2.x);
  return new HCVector3(x, y, z);
}    // crossProduct


