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
main.cpp@12:b69657862610, 2019-03-24 (annotated)
- Committer:
- el17cd
- Date:
- Sun Mar 24 16:59:48 2019 +0000
- Revision:
- 12:b69657862610
- Parent:
- 11:2cd6341136ca
- Child:
- 13:f4de03202477
Fill algorithm now works in 3 dimensions
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| el17cd | 0:efb5eec6b8ea | 1 | /* |
| el17cd | 0:efb5eec6b8ea | 2 | ELEC2645 Embedded Systems Project |
| el17cd | 0:efb5eec6b8ea | 3 | School of Electronic & Electrical Engineering |
| el17cd | 0:efb5eec6b8ea | 4 | University of Leeds |
| el17cd | 0:efb5eec6b8ea | 5 | Name: Christopher Doel |
| el17cd | 0:efb5eec6b8ea | 6 | Username: el17cd |
| el17cd | 0:efb5eec6b8ea | 7 | Student ID Number: 201146223 |
| el17cd | 0:efb5eec6b8ea | 8 | Date: 22/02/19 |
| el17cd | 0:efb5eec6b8ea | 9 | */ |
| el17cd | 0:efb5eec6b8ea | 10 | |
| el17cd | 0:efb5eec6b8ea | 11 | #include "mbed.h" |
| el17cd | 1:044238f7bdda | 12 | #include <vector> |
| el17cd | 4:759a5c34e239 | 13 | #ifndef FACE_H |
| el17cd | 4:759a5c34e239 | 14 | #define FACE_H |
| el17cd | 3:2e31dfcb712a | 15 | #include "Face.h" |
| el17cd | 4:759a5c34e239 | 16 | #endif |
| el17cd | 4:759a5c34e239 | 17 | #include "Rasturizer.h" |
| el17cd | 4:759a5c34e239 | 18 | #include "Cube.h" |
| el17cd | 6:75031d14fc0d | 19 | #include "Gamepad.h" |
| el17cd | 3:2e31dfcb712a | 20 | |
| el17cd | 8:a667bc5050c1 | 21 | Ticker ticker; |
| el17cd | 8:a667bc5050c1 | 22 | Gamepad gamepad; |
| el17cd | 9:5915fc800824 | 23 | std::vector<Cube> cubeVector; |
| el17cd | 9:5915fc800824 | 24 | std::vector<Face> faceVector; |
| el17cd | 0:efb5eec6b8ea | 25 | |
| el17cd | 8:a667bc5050c1 | 26 | |
| el17cd | 0:efb5eec6b8ea | 27 | int main() |
| el17cd | 0:efb5eec6b8ea | 28 | { |
| el17cd | 12:b69657862610 | 29 | int score = 0; |
| el17cd | 6:75031d14fc0d | 30 | gamepad.init(); |
| el17cd | 4:759a5c34e239 | 31 | Rasturizer renderer; |
| el17cd | 12:b69657862610 | 32 | for(int i = 0; i < 2; i++){ |
| el17cd | 10:07a23afd5088 | 33 | Cube cube(rand()%80-40,0,30+ i*20,5); |
| el17cd | 8:a667bc5050c1 | 34 | cubeVector.push_back(cube); |
| el17cd | 8:a667bc5050c1 | 35 | } |
| el17cd | 1:044238f7bdda | 36 | while(1) { |
| el17cd | 12:b69657862610 | 37 | score++; |
| el17cd | 12:b69657862610 | 38 | Vector2D coord = gamepad.get_coord(); |
| el17cd | 4:759a5c34e239 | 39 | renderer.clear(); |
| el17cd | 12:b69657862610 | 40 | renderer.drawHorizon(coord.x/15); |
| el17cd | 9:5915fc800824 | 41 | bool rotate1 = false; |
| el17cd | 9:5915fc800824 | 42 | if(gamepad.check_event(Gamepad::B_PRESSED) == true){ |
| el17cd | 9:5915fc800824 | 43 | rotate1 = true; |
| el17cd | 6:75031d14fc0d | 44 | } |
| el17cd | 9:5915fc800824 | 45 | bool rotate2 = false; |
| el17cd | 9:5915fc800824 | 46 | if(gamepad.check_event(Gamepad::X_PRESSED) == true){ |
| el17cd | 9:5915fc800824 | 47 | rotate2 = true; |
| el17cd | 7:15543cb10a14 | 48 | } |
| el17cd | 10:07a23afd5088 | 49 | |
| el17cd | 8:a667bc5050c1 | 50 | for (int c = 0; c< cubeVector.size(); c++) |
| el17cd | 8:a667bc5050c1 | 51 | { |
| el17cd | 9:5915fc800824 | 52 | if(rotate1){ |
| el17cd | 11:2cd6341136ca | 53 | cubeVector[c].rotateZ(0.2); |
| el17cd | 9:5915fc800824 | 54 | } |
| el17cd | 9:5915fc800824 | 55 | if(rotate2){ |
| el17cd | 11:2cd6341136ca | 56 | cubeVector[c].rotateZ(-0.2); |
| el17cd | 9:5915fc800824 | 57 | } |
| el17cd | 8:a667bc5050c1 | 58 | for (int i = 0; i < 6; i++){ |
| el17cd | 9:5915fc800824 | 59 | faceVector.push_back(cubeVector[c].getFace(i)); |
| el17cd | 10:07a23afd5088 | 60 | } |
| el17cd | 12:b69657862610 | 61 | cubeVector[c].translate(-coord.x*2,0,coord.y*2); |
| el17cd | 11:2cd6341136ca | 62 | |
| el17cd | 10:07a23afd5088 | 63 | if (cubeVector[c].despawn()){ |
| el17cd | 10:07a23afd5088 | 64 | cubeVector.erase(cubeVector.begin() + c); |
| el17cd | 12:b69657862610 | 65 | Cube cube(rand()%160-80,0,90,5); |
| el17cd | 10:07a23afd5088 | 66 | cubeVector.push_back(cube); |
| el17cd | 8:a667bc5050c1 | 67 | } |
| el17cd | 11:2cd6341136ca | 68 | if (cubeVector[c].tooClose()){ |
| el17cd | 12:b69657862610 | 69 | score = 0; |
| el17cd | 11:2cd6341136ca | 70 | } |
| el17cd | 9:5915fc800824 | 71 | } |
| el17cd | 10:07a23afd5088 | 72 | |
| el17cd | 10:07a23afd5088 | 73 | |
| el17cd | 10:07a23afd5088 | 74 | |
| el17cd | 10:07a23afd5088 | 75 | for (int f = 0; f< faceVector.size(); f++){ |
| el17cd | 10:07a23afd5088 | 76 | for (int f2 = 0; f2< faceVector.size(); f2++){ |
| el17cd | 10:07a23afd5088 | 77 | if(faceVector[f2].getAvgZ() < faceVector[f2+1].getAvgZ()){ |
| el17cd | 10:07a23afd5088 | 78 | Face temp = faceVector[f2+1]; |
| el17cd | 10:07a23afd5088 | 79 | faceVector[f2+1] = faceVector[f2]; |
| el17cd | 10:07a23afd5088 | 80 | faceVector[f2] = temp; |
| el17cd | 9:5915fc800824 | 81 | } |
| el17cd | 8:a667bc5050c1 | 82 | } |
| el17cd | 8:a667bc5050c1 | 83 | } |
| el17cd | 10:07a23afd5088 | 84 | |
| el17cd | 9:5915fc800824 | 85 | for (int f = 0; f< faceVector.size() ; f++){ |
| el17cd | 10:07a23afd5088 | 86 | //pc.printf("%f\n", faceVector[f].getAvgZ()); |
| el17cd | 12:b69657862610 | 87 | renderer.drawFace(faceVector[f], coord.x/15); |
| el17cd | 12:b69657862610 | 88 | //wait_ms(1000/1); |
| el17cd | 12:b69657862610 | 89 | |
| el17cd | 9:5915fc800824 | 90 | } |
| el17cd | 12:b69657862610 | 91 | //char buf[10]; |
| el17cd | 12:b69657862610 | 92 | //sprintf(buf, "%d", score); |
| el17cd | 12:b69657862610 | 93 | //renderer.print(buf); |
| el17cd | 12:b69657862610 | 94 | renderer.refresh(); |
| el17cd | 10:07a23afd5088 | 95 | faceVector.clear(); |
| el17cd | 10:07a23afd5088 | 96 | // refresh the LCD so the pixels appear |
| el17cd | 10:07a23afd5088 | 97 | // this gives a refresh rate of 10 frames per second |
| el17cd | 12:b69657862610 | 98 | |
| el17cd | 10:07a23afd5088 | 99 | wait_ms(1000/30); |
| el17cd | 0:efb5eec6b8ea | 100 | } |
| el17cd | 8:a667bc5050c1 | 101 | } |