A library to manipulate 2D arrays, and output them to an LED Dot Matrix Display. The display must be wired up using a shift register combined with a nor latch.
Locations.h@0:1deae5ffe9ed, 2012-02-13 (annotated)
- Committer:
- EricWieser
- Date:
- Mon Feb 13 22:19:58 2012 +0000
- Revision:
- 0:1deae5ffe9ed
- Child:
- 1:44819562ea31
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
EricWieser | 0:1deae5ffe9ed | 1 | #ifndef LOCATIONS_H |
EricWieser | 0:1deae5ffe9ed | 2 | #define LOCATIONS_H |
EricWieser | 0:1deae5ffe9ed | 3 | class FloatLocation; |
EricWieser | 0:1deae5ffe9ed | 4 | class IntLocation { |
EricWieser | 0:1deae5ffe9ed | 5 | public: |
EricWieser | 0:1deae5ffe9ed | 6 | IntLocation(int x = 0, int y = 0) : x(x), y(y) { } |
EricWieser | 0:1deae5ffe9ed | 7 | int x, y; |
EricWieser | 0:1deae5ffe9ed | 8 | operator FloatLocation(); |
EricWieser | 0:1deae5ffe9ed | 9 | bool operator==(IntLocation l) { return l.x == x && l.y == y; } |
EricWieser | 0:1deae5ffe9ed | 10 | IntLocation operator+(IntLocation l) { return IntLocation(l.x + x, l.y + y); } |
EricWieser | 0:1deae5ffe9ed | 11 | }; |
EricWieser | 0:1deae5ffe9ed | 12 | |
EricWieser | 0:1deae5ffe9ed | 13 | class FloatLocation { |
EricWieser | 0:1deae5ffe9ed | 14 | public: |
EricWieser | 0:1deae5ffe9ed | 15 | FloatLocation(float x = 0, float y = 0) : x(x), y(y) { } |
EricWieser | 0:1deae5ffe9ed | 16 | float x, y; |
EricWieser | 0:1deae5ffe9ed | 17 | operator IntLocation() { |
EricWieser | 0:1deae5ffe9ed | 18 | return IntLocation((int) (x + 0.5), (int) (y + 0.5)); |
EricWieser | 0:1deae5ffe9ed | 19 | } |
EricWieser | 0:1deae5ffe9ed | 20 | FloatLocation lerp(FloatLocation to, float alpha) { |
EricWieser | 0:1deae5ffe9ed | 21 | return FloatLocation( |
EricWieser | 0:1deae5ffe9ed | 22 | x*(1 - alpha) + to.x*alpha, |
EricWieser | 0:1deae5ffe9ed | 23 | y*(1 - alpha) + to.y*alpha |
EricWieser | 0:1deae5ffe9ed | 24 | ); |
EricWieser | 0:1deae5ffe9ed | 25 | } |
EricWieser | 0:1deae5ffe9ed | 26 | bool operator==(FloatLocation l) { return l.x == x && l.y == y; } |
EricWieser | 0:1deae5ffe9ed | 27 | }; |
EricWieser | 0:1deae5ffe9ed | 28 | IntLocation::operator FloatLocation() { |
EricWieser | 0:1deae5ffe9ed | 29 | return FloatLocation(x, y); |
EricWieser | 0:1deae5ffe9ed | 30 | } |
EricWieser | 0:1deae5ffe9ed | 31 | #endif |