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:
- 5:8bd09c675f28
- Parent:
- 1:3916f272663e
--- a/CrossHairs/CrossHairs.cpp Sun May 05 20:46:26 2019 +0000 +++ b/CrossHairs/CrossHairs.cpp Wed May 08 19:41:10 2019 +0000 @@ -23,9 +23,11 @@ void CrossHairs::init(int speed) { - + //set the cross hairs x and y to centre of display _x = WIDTH/2 - (7/2); _y = HEIGHT/2 - (7/2); + + //set the cross hairs max speed in pixels per frame _speed = speed; @@ -39,20 +41,20 @@ } -void CrossHairs::update(float angle,float mag, int fps) +void CrossHairs::update(float angle,float mag) { - //Correcting JoyStick to match screen angles + //Correcting JoyStick angle to match screen angles angle = angle - 90.0f; //Conversion To Radians double angleRads = (angle/360.0f)*2.0f*3.14f; - - + //incriment x and y based on an angle and magnitude _x+= _speed*mag*cos(angleRads); _y += _speed*mag*sin(angleRads); - //check if cross hairs are outside screen + //check if cross hairs are outside screen boundary + //if they are outside the boundary set the problem coordinate to the boundary int halfCrossHairs = 3; if (_x < -halfCrossHairs) { _x = -halfCrossHairs; @@ -65,9 +67,6 @@ _y = 48-halfCrossHairs; } - - //_x = WIDTH/2 + 10.0*mag*cos(angleRads); - //_y = HEIGHT/2 + 10.0*mag*sin(angleRads); }