Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: View.cpp
- Revision:
- 2:891b3618be4f
- Parent:
- 1:bb1507f0bb64
- Child:
- 3:b89ead557d59
--- a/View.cpp Fri May 01 09:22:50 2015 +0000 +++ b/View.cpp Fri May 01 10:12:55 2015 +0000 @@ -6,6 +6,7 @@ #include "Point.h" #include "EuclidPoint.h" #include <math.h> +#include "Block.h" //write to arm pins DigitalOut pushRegister(p24); @@ -80,9 +81,14 @@ int arrSlice = pointer.getArraySlice(); char c = pointer.getIdentifyingChar(); int distance = pointer.getPositionDistance(); - slice_data[arrSlice][distance] |= c; + addValue(arrSlice, distance, c); } +void View :: addValue(int arrSlice, int distance, char c){ + if (distance >= 0 && distance < 16 && arrSlice < 360 && arrSlice > 0){ + slice_data[arrSlice][distance] |= c; + } +} void View :: addEucPoint(EuclidPoint euc){ int x = euc.x; @@ -92,50 +98,36 @@ char c = pointer.getIdentifyingChar(); int distance = pointer.getPositionDistance(); - + addValue(arrSlice, distance, c); slice_data[arrSlice][distance] |= c; int divider = 1 + ((distance)/ 4); int reach = rint((double)3 / divider); for (int i = 0 ; i < reach; i ++){ - slice_data [(arrSlice + i)%360][distance] |= c; - slice_data [(arrSlice - i)%360][distance] |= c; + addValue((arrSlice + i)%360, distance, c); + addValue((arrSlice - i)%360, distance, c); } - - - - /* - int changeDeg = arrSlice; - double deg = (double) changeDeg / 57.295; - - while ( ((sin (deg) * (distance + 1)) - y == 0 && (int) (cos (deg) * (distance + 1)) - x == 0)){ - slice_data[change][distance] |= c; - changeDeg ++; - double deg = (double) changeDeg / 57.295; +} +void View :: drawSquare (int x, int y, int z, int size){ + for(int i = 0; i < size; i++){ + addEucPoint(EuclidPoint(x + i, y , z )); + addEucPoint(EuclidPoint(x, y + i , z )); + addEucPoint(EuclidPoint(x + size , y + i , z )); + addEucPoint(EuclidPoint(x + i, y + size , z )); } - - - - changeDeg = arrSlice; - deg = (double) changeDeg / 57.295; - - while ( (int) (sin (deg) * (distance + 1)) - y == 0 && (int) (cos (deg) * (distance + 1)) - x == 0){ - slice_data[change][distance] |= c; - changeDeg --; - double deg = (double) changeDeg / 57.295; +} +void View :: drawLine (int x, int y, int z, int size){ + for(int i = 0; i < size; i++){ + addEucPoint(EuclidPoint(x, y , z + i)); } - while ( tan(arrSlice / 57.295) == ((double) y / x) || (int) tan(arrSlice / 57.295) == (int) ((double) -y / x)){ - slice_data[change][distance] |= c; - change ++; - } - change = arrSlice; - //while ((int) (sin(change / 57.295) * distance) == x && (int)(cos (change / 57.295) * distance)== y){ - while ( (int) tan(arrSlice / 57.295) == (int) ((double) y / x) || (int) tan(arrSlice / 57.295) == (int) ((double) -y / x)){ - slice_data[change][distance] |= c; - change --; - } - */ - +} +void View :: addBlock(Block block){ + drawSquare(block.x, block.y, block.z, block.size); + drawSquare(block.x, block.y, block.z + block.height, block.size ); + drawLine(block.x, block.y, block.z, block.height); + drawLine(block.x + block.size, block.y, block.z, block.height); + drawLine(block.x, block.y + block.size, block.z, block.height); + drawLine(block.x + block.size, block.y + block.size, block.z, block.height); }