ELEC2645 (2018/19) / Mbed 2 deprecated el17cd

Dependencies:   mbed

Revision:
10:07a23afd5088
Parent:
8:a667bc5050c1
Child:
11:2cd6341136ca
--- a/Cube/Cube.cpp	Tue Mar 19 10:27:37 2019 +0000
+++ b/Cube/Cube.cpp	Tue Mar 19 12:12:52 2019 +0000
@@ -3,6 +3,9 @@
 #include "math.h"
 
 Cube::Cube(double x, double y, double z, double size){
+     xPos = x;
+     yPos = y;
+     zPos = z;
      double v[8][3] = {{x-size, y+size, z-size},
     {x-size, y+size, z+size},
     {x+size, y+size, z+size},
@@ -36,6 +39,12 @@
 }
 
 void Cube::rotateY(double angle){
+    double x = xPos;
+    double z = zPos;
+        
+    xPos = x*cos(angle)-z*sin(angle);
+    zPos = x*sin(angle)+z*cos(angle);
+    
     for( int i = 0; i<12; i++){
         double x = verticies[i][0];
         double z = verticies[i][2];
@@ -59,6 +68,12 @@
 }
 
 void Cube::rotateX(double angle){
+    double y = yPos;
+    double z = zPos;
+        
+    xPos = y*cos(angle)-z*sin(angle);
+    zPos = z*cos(angle)+y*sin(angle);
+    
     for( int i = 0; i<12; i++){
         double y = verticies[i][1];
         double z = verticies[i][2];
@@ -84,6 +99,11 @@
 
 
 void Cube::translate(double x, double y, double z){
+    
+    xPos += x;
+    yPos += y;
+    zPos += z;
+    
     for( int i = 0; i<12; i++){
         double hyp = sqrt(pow(verticies[i][0],2) + pow(verticies[i][1], 2));
         verticies[i][0] += x;
@@ -102,4 +122,11 @@
     faces[3].setVerticies(f3Points);
     faces[4].setVerticies(f4Points);
     faces[5].setVerticies(f5Points);
+}
+
+bool Cube::despawn(){
+    if(zPos < -10){
+        return true;
+    }
+    return false;
 }
\ No newline at end of file