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.
Dependencies: mbed
Rasturizer/Rasturizer.cpp@10:07a23afd5088, 2019-03-19 (annotated)
- Committer:
- el17cd
- Date:
- Tue Mar 19 12:12:52 2019 +0000
- Revision:
- 10:07a23afd5088
- Parent:
- 9:5915fc800824
- Child:
- 11:2cd6341136ca
painters algorithm working (without rotation) implemented concept cube runner
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| el17cd | 1:044238f7bdda | 1 | #include "mbed.h" |
| el17cd | 1:044238f7bdda | 2 | #include "Rasturizer.h" |
| el17cd | 2:a5bc7b3779f7 | 3 | |
| el17cd | 4:759a5c34e239 | 4 | N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); |
| el17cd | 3:2e31dfcb712a | 5 | |
| el17cd | 3:2e31dfcb712a | 6 | |
| el17cd | 4:759a5c34e239 | 7 | Rasturizer::Rasturizer(){ |
| el17cd | 3:2e31dfcb712a | 8 | lcd.init(); |
| el17cd | 4:759a5c34e239 | 9 | } |
| el17cd | 1:044238f7bdda | 10 | |
| el17cd | 4:759a5c34e239 | 11 | void Rasturizer::drawFace(Face face){ |
| el17cd | 7:15543cb10a14 | 12 | double points[4][3]; |
| el17cd | 4:759a5c34e239 | 13 | for(int vertex = 0; vertex < 4; vertex++){ |
| el17cd | 4:759a5c34e239 | 14 | for(int axis = 0; axis < 3; axis++){ |
| el17cd | 4:759a5c34e239 | 15 | points[vertex][axis] = face.getVertexValue(vertex, axis); |
| el17cd | 4:759a5c34e239 | 16 | } |
| el17cd | 4:759a5c34e239 | 17 | } |
| el17cd | 6:75031d14fc0d | 18 | |
| el17cd | 9:5915fc800824 | 19 | if (points[0][2] > 20 || points[1][2] > 20 || points[2][2] > 20|| points[3][2] > 20){ |
| el17cd | 10:07a23afd5088 | 20 | |
| el17cd | 7:15543cb10a14 | 21 | int diffX1 = points[0][0]-points[1][0]; |
| el17cd | 7:15543cb10a14 | 22 | int diffY1 = points[0][1]-points[1][1]; |
| el17cd | 7:15543cb10a14 | 23 | int diffX2 = points[2][0]-points[3][0]; |
| el17cd | 9:5915fc800824 | 24 | int diffY2 = points[2][1]-points[3][1]; |
| el17cd | 8:a667bc5050c1 | 25 | |
| el17cd | 9:5915fc800824 | 26 | double step = (double)diffY2/(double)diffX2; |
| el17cd | 9:5915fc800824 | 27 | double stepSmall1 = (double)diffX1/(double)diffX2; |
| el17cd | 9:5915fc800824 | 28 | double stepSmall2 = (double)diffY1/(double)diffX2; |
| el17cd | 9:5915fc800824 | 29 | |
| el17cd | 9:5915fc800824 | 30 | for(int s = 0; s<= abs(diffX2)-1; s++){ |
| el17cd | 9:5915fc800824 | 31 | lcd.drawLine(rint((points[0][0]-stepSmall1*s)*(40/points[0][2]))+42, rint((points[0][1]-stepSmall2*s)*(40/points[0][2]))+21,rint((points[3][0]+s)*(40/points[3][2]))+42, rint((points[3][1]+step*s)*(40/points[3][2]))+21, 0); |
| el17cd | 9:5915fc800824 | 32 | lcd.drawLine(rint((points[0][0]-stepSmall1*s-1)*(40/points[0][2])+42), rint((points[0][1]-stepSmall2*s)*(40/points[0][2])+21),rint((points[3][0]+s+1)*(40/points[3][2]))+42, rint((points[3][1]+step*s)*(40/points[3][2]))+21, 0); |
| el17cd | 7:15543cb10a14 | 33 | } |
| el17cd | 1:044238f7bdda | 34 | |
| el17cd | 7:15543cb10a14 | 35 | for (int i = 0; i < 3; i++){ |
| el17cd | 6:75031d14fc0d | 36 | |
| el17cd | 7:15543cb10a14 | 37 | lcd.drawLine(rint(points[i][0]*(40/points[i][2]))+42, |
| el17cd | 7:15543cb10a14 | 38 | rint(points[i][1]*(40/points[i][2]))+21, |
| el17cd | 7:15543cb10a14 | 39 | rint(points[i+1][0]*(40/points[i+1][2]))+42, |
| el17cd | 7:15543cb10a14 | 40 | rint(points[i+1][1]*(40/points[i+1][2]))+21, |
| el17cd | 7:15543cb10a14 | 41 | 1); |
| el17cd | 7:15543cb10a14 | 42 | |
| el17cd | 1:044238f7bdda | 43 | } |
| el17cd | 7:15543cb10a14 | 44 | lcd.drawLine(rint(points[0][0]*(40/points[0][2]))+42, |
| el17cd | 7:15543cb10a14 | 45 | rint(points[0][1]*(40/points[0][2]))+21, |
| el17cd | 7:15543cb10a14 | 46 | rint(points[3][0]*(40/points[3][2]))+42, |
| el17cd | 7:15543cb10a14 | 47 | rint(points[3][1]*(40/points[3][2]))+21, |
| el17cd | 7:15543cb10a14 | 48 | 1); |
| el17cd | 1:044238f7bdda | 49 | } |
| el17cd | 4:759a5c34e239 | 50 | } |
| el17cd | 9:5915fc800824 | 51 | |
| el17cd | 4:759a5c34e239 | 52 | void Rasturizer::clear(){ |
| el17cd | 4:759a5c34e239 | 53 | lcd.clear(); |
| el17cd | 4:759a5c34e239 | 54 | } |
| el17cd | 4:759a5c34e239 | 55 | |
| el17cd | 4:759a5c34e239 | 56 | void Rasturizer::refresh(){ |
| el17cd | 4:759a5c34e239 | 57 | lcd.refresh(); |
| el17cd | 1:044238f7bdda | 58 | } |