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@4:759a5c34e239, 2019-02-22 (annotated)
- Committer:
- el17cd
- Date:
- Fri Feb 22 19:05:28 2019 +0000
- Revision:
- 4:759a5c34e239
- Parent:
- 3:2e31dfcb712a
- Child:
- 6:75031d14fc0d
Cube Class implemented, when instantiated it created 12 vertices and 6 faces
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 | 4:759a5c34e239 | 12 | float 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 | 1:044238f7bdda | 18 | int diffX1 = points[0][0]-points[1][0]; |
| el17cd | 1:044238f7bdda | 19 | int diffY1 = points[0][1]-points[1][1]; |
| el17cd | 1:044238f7bdda | 20 | int diffX2 = points[2][0]-points[3][0]; |
| el17cd | 1:044238f7bdda | 21 | int diffY2 = points[2][1]-points[3][1]; |
| el17cd | 1:044238f7bdda | 22 | |
| el17cd | 1:044238f7bdda | 23 | if (abs(diffX1) > abs(diffX2)){ |
| el17cd | 1:044238f7bdda | 24 | |
| el17cd | 1:044238f7bdda | 25 | float step = (float)diffY1/(float)diffX1; |
| el17cd | 1:044238f7bdda | 26 | float stepSmall1 = (float)diffX2/(float)diffX1; |
| el17cd | 1:044238f7bdda | 27 | float stepSmall2 = (float)diffY2/(float)diffX1; |
| el17cd | 1:044238f7bdda | 28 | lcd.printString("top",0,0); |
| el17cd | 1:044238f7bdda | 29 | for(int s = 0; s<= abs(diffX1)-1; s++){ |
| el17cd | 1:044238f7bdda | 30 | lcd.drawLine(points[0][0]+s, rint(points[0][1]+step*s), rint(points[3][0]-stepSmall1*s), rint(points[3][1]-stepSmall2*s), 0); |
| el17cd | 1:044238f7bdda | 31 | lcd.drawLine(points[0][0]+s+1, rint(points[0][1]+step*s), rint(points[3][0]-stepSmall1*s-1), rint(points[3][1]-stepSmall2*s), 0); |
| el17cd | 1:044238f7bdda | 32 | } |
| el17cd | 1:044238f7bdda | 33 | } |
| el17cd | 1:044238f7bdda | 34 | else{ |
| el17cd | 1:044238f7bdda | 35 | lcd.printString("bottom",0,0); |
| el17cd | 1:044238f7bdda | 36 | float step = (float)diffY2/(float)diffX2; |
| el17cd | 1:044238f7bdda | 37 | float stepSmall1 = (float)diffX1/(float)diffX2; |
| el17cd | 1:044238f7bdda | 38 | float stepSmall2 = (float)diffY1/(float)diffX2; |
| el17cd | 1:044238f7bdda | 39 | |
| el17cd | 1:044238f7bdda | 40 | for(int s = 0; s<= abs(diffX2)-1; s++){ |
| el17cd | 1:044238f7bdda | 41 | lcd.drawLine(points[0][0]-stepSmall1*s, rint(points[0][1]-stepSmall2*s),rint(points[3][0]+s), rint(points[3][1]+step*s), 0); |
| el17cd | 1:044238f7bdda | 42 | lcd.drawLine(points[0][0]-stepSmall1*s-1, rint(points[0][1]-stepSmall2*s),rint(points[3][0]+s+1), rint(points[3][1]+step*s), 0); |
| el17cd | 1:044238f7bdda | 43 | } |
| el17cd | 1:044238f7bdda | 44 | } |
| el17cd | 1:044238f7bdda | 45 | for (int i = 0; i < 3; i++){ |
| el17cd | 1:044238f7bdda | 46 | lcd.drawLine(points[i][0], |
| el17cd | 1:044238f7bdda | 47 | points[i][1], |
| el17cd | 1:044238f7bdda | 48 | points[i+1][0], |
| el17cd | 1:044238f7bdda | 49 | points[i+1][1], |
| el17cd | 1:044238f7bdda | 50 | 1); |
| el17cd | 1:044238f7bdda | 51 | } |
| el17cd | 1:044238f7bdda | 52 | lcd.drawLine(points[0][0], |
| el17cd | 1:044238f7bdda | 53 | points[0][1], |
| el17cd | 1:044238f7bdda | 54 | points[3][0], |
| el17cd | 1:044238f7bdda | 55 | points[3][1], |
| el17cd | 1:044238f7bdda | 56 | 1); |
| el17cd | 4:759a5c34e239 | 57 | } |
| el17cd | 4:759a5c34e239 | 58 | void Rasturizer::clear(){ |
| el17cd | 4:759a5c34e239 | 59 | lcd.clear(); |
| el17cd | 4:759a5c34e239 | 60 | } |
| el17cd | 4:759a5c34e239 | 61 | |
| el17cd | 4:759a5c34e239 | 62 | void Rasturizer::refresh(){ |
| el17cd | 4:759a5c34e239 | 63 | lcd.refresh(); |
| el17cd | 1:044238f7bdda | 64 | } |