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
- Committer:
- el17cd
- Date:
- 2019-02-26
- Revision:
- 8:a667bc5050c1
- Parent:
- 7:15543cb10a14
- Child:
- 9:5915fc800824
File content as of revision 8:a667bc5050c1:
/*
ELEC2645 Embedded Systems Project
School of Electronic & Electrical Engineering
University of Leeds
Name: Christopher Doel
Username: el17cd
Student ID Number: 201146223
Date: 22/02/19
*/
#include "mbed.h"
#include <vector>
#ifndef FACE_H
#define FACE_H
#include "Face.h"
#endif
#include "Rasturizer.h"
#include "Cube.h"
#include "Gamepad.h"
Serial pc(USBTX, USBRX); // tx, rx
Ticker ticker;
Gamepad gamepad;
std::vector<Cube> cubeVector;
void spawnCubes()
{
cubeVector.clear();
for (int i = 0; i<20;i++){
Cube cube(rand()%80-40,rand()%80-40,i*40,5);
cubeVector.push_back(cube);
}
}
int main()
{
gamepad.init();
Rasturizer renderer;
ticker.attach(&spawnCubes,10);
for (int i = 0; i<20;i++){
Cube cube(rand()%80-40,rand()%80-40,i*40,5);
cubeVector.push_back(cube);
}
int i = 0;
while(1) {
renderer.clear();
Vector2D coord = gamepad.get_coord();
bool right = false;
bool left = false;
bool up = false;
bool down = false;
//pc.printf("%f",
if(gamepad.check_event(Gamepad::R_PRESSED) == true){
right = true;
}
else if( gamepad.check_event(Gamepad::L_PRESSED) == true){
left = true;
}
else if(gamepad.check_event(Gamepad::Y_PRESSED) == true){
up = true;
}
else if( gamepad.check_event(Gamepad::A_PRESSED) == true){
down = true;
}
for (int c = 0; c< cubeVector.size(); c++)
{
for (int i = 0; i < 6; i++){
renderer.drawFace(cubeVector[c].getFace(i));
}
cubeVector[c].translate(0,0,-3);//-coord.x*2,0,-coord.y*2);
cubeVector[c].rotateY(coord.x/10);
cubeVector[c].rotateX(-coord.y/10);
/*
if(right == true){
cubeVector[c].rotateY(0.2);
}
else if(left == true){
cubeVector[c].rotateY(-0.2);
}
else if(up == true){
cubeVector[c].rotateX(0.2);
}
else if(down == true){
cubeVector[c].rotateX(-0.2);
}*/
}
renderer.refresh(); // refresh the LCD so the pixels appear
wait_ms(1000/30); // this gives a refresh rate of 10 frames per second
//i++;
}
}