

#include  <math.h>
#include  "3d.h"


void Init3d      (point3d_t *this) { 
  this->x = 0;
  this->y = 0;
  this->z = 0;
}

void Scale3d     (point3d_t *this, point3d_t that) { 
  this->x *= that.x;
  this->y *= that.y;
  this->z *= that.z;
}

void Rotate3d    (point3d_t *this, point3d_t that) { 

  point3d_t temp;
  
  // x rotation
   temp.y  = (this->y * cos(that.x)) - (this->z * sin(that.x));
   this->z = (this->y * sin(that.x)) + (this->z * cos(that.x));
   this->y = temp.y;
    
  // y rotation
   temp.z = (this->z * cos(that.y)) - (this->x * sin(that.y));
   this->x = (this->z * sin(that.y)) + (this->x * cos(that.y));
   this->z = temp.z;
     
  // z rotation
   temp.x = (this->x * cos(that.z)) - (this->y * sin(that.z));
   this->y = (this->x * sin(that.z)) + (this->y * cos(that.z));
   this->x = temp.x;
}

void Translate3d (point3d_t *this, point3d_t that) { 
  this->x += that.x;
  this->y += that.y;
  this->z += that.z;
}
