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@8:a667bc5050c1, 2019-02-26 (annotated)
- Committer:
- el17cd
- Date:
- Tue Feb 26 09:35:03 2019 +0000
- Revision:
- 8:a667bc5050c1
- Parent:
- 7:15543cb10a14
- Child:
- 9:5915fc800824
added prototype asteroid idea;
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 | Serial pc(USBTX, USBRX); // tx, rx |
| el17cd | 8:a667bc5050c1 | 22 | Ticker ticker; |
| el17cd | 8:a667bc5050c1 | 23 | Gamepad gamepad; |
| el17cd | 8:a667bc5050c1 | 24 | std::vector<Cube> cubeVector; |
| el17cd | 0:efb5eec6b8ea | 25 | |
| el17cd | 8:a667bc5050c1 | 26 | void spawnCubes() |
| el17cd | 8:a667bc5050c1 | 27 | { |
| el17cd | 8:a667bc5050c1 | 28 | cubeVector.clear(); |
| el17cd | 8:a667bc5050c1 | 29 | for (int i = 0; i<20;i++){ |
| el17cd | 8:a667bc5050c1 | 30 | Cube cube(rand()%80-40,rand()%80-40,i*40,5); |
| el17cd | 8:a667bc5050c1 | 31 | cubeVector.push_back(cube); |
| el17cd | 8:a667bc5050c1 | 32 | } |
| el17cd | 8:a667bc5050c1 | 33 | } |
| el17cd | 8:a667bc5050c1 | 34 | |
| el17cd | 0:efb5eec6b8ea | 35 | int main() |
| el17cd | 0:efb5eec6b8ea | 36 | { |
| el17cd | 6:75031d14fc0d | 37 | |
| el17cd | 6:75031d14fc0d | 38 | gamepad.init(); |
| el17cd | 4:759a5c34e239 | 39 | Rasturizer renderer; |
| el17cd | 8:a667bc5050c1 | 40 | ticker.attach(&spawnCubes,10); |
| el17cd | 8:a667bc5050c1 | 41 | |
| el17cd | 8:a667bc5050c1 | 42 | for (int i = 0; i<20;i++){ |
| el17cd | 8:a667bc5050c1 | 43 | Cube cube(rand()%80-40,rand()%80-40,i*40,5); |
| el17cd | 8:a667bc5050c1 | 44 | cubeVector.push_back(cube); |
| el17cd | 8:a667bc5050c1 | 45 | } |
| el17cd | 7:15543cb10a14 | 46 | |
| el17cd | 4:759a5c34e239 | 47 | int i = 0; |
| el17cd | 1:044238f7bdda | 48 | while(1) { |
| el17cd | 4:759a5c34e239 | 49 | renderer.clear(); |
| el17cd | 8:a667bc5050c1 | 50 | Vector2D coord = gamepad.get_coord(); |
| el17cd | 8:a667bc5050c1 | 51 | bool right = false; |
| el17cd | 8:a667bc5050c1 | 52 | bool left = false; |
| el17cd | 8:a667bc5050c1 | 53 | bool up = false; |
| el17cd | 8:a667bc5050c1 | 54 | bool down = false; |
| el17cd | 8:a667bc5050c1 | 55 | |
| el17cd | 8:a667bc5050c1 | 56 | //pc.printf("%f", |
| el17cd | 8:a667bc5050c1 | 57 | |
| el17cd | 8:a667bc5050c1 | 58 | if(gamepad.check_event(Gamepad::R_PRESSED) == true){ |
| el17cd | 8:a667bc5050c1 | 59 | right = true; |
| el17cd | 6:75031d14fc0d | 60 | } |
| el17cd | 8:a667bc5050c1 | 61 | else if( gamepad.check_event(Gamepad::L_PRESSED) == true){ |
| el17cd | 8:a667bc5050c1 | 62 | left = true; |
| el17cd | 6:75031d14fc0d | 63 | } |
| el17cd | 8:a667bc5050c1 | 64 | else if(gamepad.check_event(Gamepad::Y_PRESSED) == true){ |
| el17cd | 8:a667bc5050c1 | 65 | up = true; |
| el17cd | 7:15543cb10a14 | 66 | } |
| el17cd | 8:a667bc5050c1 | 67 | else if( gamepad.check_event(Gamepad::A_PRESSED) == true){ |
| el17cd | 8:a667bc5050c1 | 68 | down = true; |
| el17cd | 7:15543cb10a14 | 69 | } |
| el17cd | 7:15543cb10a14 | 70 | |
| el17cd | 6:75031d14fc0d | 71 | |
| el17cd | 8:a667bc5050c1 | 72 | for (int c = 0; c< cubeVector.size(); c++) |
| el17cd | 8:a667bc5050c1 | 73 | { |
| el17cd | 8:a667bc5050c1 | 74 | for (int i = 0; i < 6; i++){ |
| el17cd | 8:a667bc5050c1 | 75 | renderer.drawFace(cubeVector[c].getFace(i)); |
| el17cd | 8:a667bc5050c1 | 76 | } |
| el17cd | 8:a667bc5050c1 | 77 | cubeVector[c].translate(0,0,-3);//-coord.x*2,0,-coord.y*2); |
| el17cd | 8:a667bc5050c1 | 78 | cubeVector[c].rotateY(coord.x/10); |
| el17cd | 8:a667bc5050c1 | 79 | cubeVector[c].rotateX(-coord.y/10); |
| el17cd | 8:a667bc5050c1 | 80 | /* |
| el17cd | 8:a667bc5050c1 | 81 | if(right == true){ |
| el17cd | 8:a667bc5050c1 | 82 | cubeVector[c].rotateY(0.2); |
| el17cd | 8:a667bc5050c1 | 83 | } |
| el17cd | 8:a667bc5050c1 | 84 | else if(left == true){ |
| el17cd | 8:a667bc5050c1 | 85 | cubeVector[c].rotateY(-0.2); |
| el17cd | 8:a667bc5050c1 | 86 | } |
| el17cd | 8:a667bc5050c1 | 87 | else if(up == true){ |
| el17cd | 8:a667bc5050c1 | 88 | cubeVector[c].rotateX(0.2); |
| el17cd | 8:a667bc5050c1 | 89 | } |
| el17cd | 8:a667bc5050c1 | 90 | else if(down == true){ |
| el17cd | 8:a667bc5050c1 | 91 | cubeVector[c].rotateX(-0.2); |
| el17cd | 8:a667bc5050c1 | 92 | }*/ |
| el17cd | 8:a667bc5050c1 | 93 | } |
| el17cd | 6:75031d14fc0d | 94 | |
| el17cd | 4:759a5c34e239 | 95 | renderer.refresh(); // refresh the LCD so the pixels appear |
| el17cd | 8:a667bc5050c1 | 96 | wait_ms(1000/30); // this gives a refresh rate of 10 frames per second |
| el17cd | 6:75031d14fc0d | 97 | //i++; |
| el17cd | 0:efb5eec6b8ea | 98 | } |
| el17cd | 8:a667bc5050c1 | 99 | } |