ELEC2645 (2018/19) / Mbed 2 deprecated el17cd

Dependencies:   mbed

Revision:
33:02c5048b3b3f
Parent:
31:e681177037ef
Child:
39:41dcf1604fdf
diff -r 9c250eda7f3f -r 02c5048b3b3f Renderer/Renderer.cpp
--- a/Renderer/Renderer.cpp	Fri Apr 05 15:43:27 2019 +0000
+++ b/Renderer/Renderer.cpp	Mon Apr 29 14:31:44 2019 +0000
@@ -1,7 +1,7 @@
 #include "Renderer.h"
+
 N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
 
-
 Renderer::Renderer() {
     for(int i = 0; i < 6; i++){ //set the selection cubes faces to visible
         selectionCube.getFace(i).setVisible(true);
@@ -13,6 +13,7 @@
     fov = 50; //set the field of view to 50
 }
 
+
 float Renderer::xTo2D(float x, float z) { //Project 3D x coordinate to 2D perspective
     return x * (fov/z) + 42;
 }
@@ -54,10 +55,14 @@
 void Renderer::rasterizeFace(float (&points)[4][3], Face *face) { //Fill in the face using white lines
     int diffX1, diffY1, diffX2, diffY2;
     float stepBottomY, stepTopX, stepTopY;
-    diffX1 = xTo2D(points[0][0], points[0][2])-xTo2D(points[1][0], points[1][2]); //Calculate difference between top horizontal edge x coordnates
-    diffY1 = yTo2D(points[0][1], points[0][2])-yTo2D(points[1][1], points[1][2]); //Calculate difference between right vertical edge y coordinates
-    diffX2 = xTo2D(points[2][0], points[2][2])-xTo2D(points[3][0], points[3][2]); //Calculate difference between bottom horizontal edge x coordinates
-    diffY2 = yTo2D(points[2][1], points[2][2])-yTo2D(points[3][1], points[3][2]); //Calculate difference between left horizontal edge y coordinates
+    diffX1 = xTo2D(points[0][0], points[0][2])-xTo2D(points[1][0],
+    points[1][2]); //Calculate difference between top horizontal edge x coordnates
+    diffY1 = yTo2D(points[0][1], points[0][2])-yTo2D(points[1][1],
+    points[1][2]); //Calculate difference between right vertical edge y coordinates
+    diffX2 = xTo2D(points[2][0], points[2][2])-xTo2D(points[3][0],
+    points[3][2]); //Calculate difference between bottom horizontal edge x coordinates
+    diffY2 = yTo2D(points[2][1], points[2][2])-yTo2D(points[3][1],
+    points[3][2]); //Calculate difference between left horizontal edge y coordinates
     if(diffX2 != 0 && face->getVisible()) {
         stepBottomY = (float)diffY2/(float)diffX2; //increment multiplier for Y axis on bottom edge of face
         stepTopX = (float)diffX1/(float)diffX2; //increment multiplier for X axis on top edge of face
@@ -120,13 +125,18 @@
 }
 
 bool Renderer::checkOnScreen(float (&points)[4][3]) { //Check whether any part of the face is on screen
-    if (points[0][2] < 6 || points[1][2] < 6 || points[2][2] < 6 || points[3][2] < 6) { //not on screen if behind perspective
+    if (points[0][2] < 6 || points[1][2] < 6 || points[2][2] < 6 ||
+    points[3][2] < 6) { //not on screen if behind perspective
         return false;
     }
-    else if ((xTo2D(points[0][0], points[0][2]) < 0 ||  xTo2D(points[0][0], points[0][2]) > 84) //check if any 2D projection verticies are within screen boundaries
-    && (xTo2D(points[1][0], points[1][2]) < 0 ||  xTo2D(points[1][0], points[1][2]) > 84)
-    && (xTo2D(points[2][0], points[2][2]) < 0 ||  xTo2D(points[2][0], points[2][2]) > 84)
-    && (xTo2D(points[3][0], points[3][2]) < 0 ||  xTo2D(points[3][0], points[3][2]) > 84)){
+    else if ((xTo2D(points[0][0], points[0][2]) < 0 ||  xTo2D(points[0][0],
+    points[0][2]) > 84) //check if any 2D projection verticies are within screen boundaries
+    && (xTo2D(points[1][0], points[1][2]) < 0 ||  xTo2D(points[1][0],
+    points[1][2]) > 84)
+    && (xTo2D(points[2][0], points[2][2]) < 0 ||  xTo2D(points[2][0],
+    points[2][2]) > 84)
+    && (xTo2D(points[3][0], points[3][2]) < 0 ||  xTo2D(points[3][0],
+    points[3][2]) > 84)){
         return false;
     }
     return true;