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
Diff: CrossHairs/CrossHairs.cpp
- Revision:
- 1:3916f272663e
- Child:
- 5:8bd09c675f28
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CrossHairs/CrossHairs.cpp Sun Apr 21 19:02:21 2019 +0000 @@ -0,0 +1,85 @@ +#include "CrossHairs.h" + + +int crossHairsSprite[7][7] = { + { 0,0,1,1,1,0,0 }, + { 0,1,0,0,0,1,0 }, + { 1,0,0,1,0,0,1 }, + { 1,0,1,1,1,0,1 }, + { 1,0,0,1,0,0,1 }, + { 0,1,0,0,0,1,0 }, + { 0,0,1,1,1,0,0 }, +}; + +CrossHairs::CrossHairs() +{ + +} + +CrossHairs::~CrossHairs() +{ + +} + +void CrossHairs::init(int speed) +{ + + _x = WIDTH/2 - (7/2); + _y = HEIGHT/2 - (7/2); + _speed = speed; + + + +} + +void CrossHairs::draw(N5110 &lcd) +{ + // x origin, y origin, rows, cols, sprite + lcd.drawSprite(_x,_y,7,7,(int *)crossHairsSprite); + +} + +void CrossHairs::update(float angle,float mag, int fps) +{ + //Correcting JoyStick to match screen angles + angle = angle - 90.0f; + + //Conversion To Radians + double angleRads = (angle/360.0f)*2.0f*3.14f; + + + + _x+= _speed*mag*cos(angleRads); + _y += _speed*mag*sin(angleRads); + + //check if cross hairs are outside screen + int halfCrossHairs = 3; + if (_x < -halfCrossHairs) { + _x = -halfCrossHairs; + } else if (_x > 84-halfCrossHairs) { + _x = 84-halfCrossHairs; + } + if (_y < -halfCrossHairs) { + _y = -halfCrossHairs; + } else if (_y > 48-halfCrossHairs) { + _y = 48-halfCrossHairs; + } + + + //_x = WIDTH/2 + 10.0*mag*cos(angleRads); + //_y = HEIGHT/2 + 10.0*mag*sin(angleRads); +} + + + +Vector2D CrossHairs::get_pos() +{ + Vector2D p = {_x,_y}; + return p; +} + +void CrossHairs::set_pos(Vector2D p) +{ + _x = p.x; + _y = p.y; +} \ No newline at end of file