![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Example for the LPC4088 QSB Base Board
GlobeDemo.cpp@1:6131a78e7e97, 2014-04-09 (annotated)
- Committer:
- embeddedartists
- Date:
- Wed Apr 09 09:46:04 2014 +0000
- Revision:
- 1:6131a78e7e97
- Parent:
- 0:7dd43900b657
Updated to latest version of EALib
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
embeddedartists | 0:7dd43900b657 | 1 | /****************************************************************************** |
embeddedartists | 0:7dd43900b657 | 2 | * Includes |
embeddedartists | 0:7dd43900b657 | 3 | *****************************************************************************/ |
embeddedartists | 0:7dd43900b657 | 4 | |
embeddedartists | 0:7dd43900b657 | 5 | #include "mbed.h" |
embeddedartists | 0:7dd43900b657 | 6 | |
embeddedartists | 0:7dd43900b657 | 7 | #include "LcdController.h" |
embeddedartists | 0:7dd43900b657 | 8 | #include "EaLcdBoard.h" |
embeddedartists | 0:7dd43900b657 | 9 | #include "GlobeDemo.h" |
embeddedartists | 0:7dd43900b657 | 10 | |
embeddedartists | 0:7dd43900b657 | 11 | #include <math.h> |
embeddedartists | 0:7dd43900b657 | 12 | |
embeddedartists | 0:7dd43900b657 | 13 | //#include "wchar.h" |
embeddedartists | 0:7dd43900b657 | 14 | |
embeddedartists | 0:7dd43900b657 | 15 | /****************************************************************************** |
embeddedartists | 0:7dd43900b657 | 16 | * Typedefs and defines |
embeddedartists | 0:7dd43900b657 | 17 | *****************************************************************************/ |
embeddedartists | 0:7dd43900b657 | 18 | |
embeddedartists | 0:7dd43900b657 | 19 | #define NUM_OF_DOTS 50 |
embeddedartists | 0:7dd43900b657 | 20 | |
embeddedartists | 0:7dd43900b657 | 21 | /****************************************************************************** |
embeddedartists | 0:7dd43900b657 | 22 | * Local variables |
embeddedartists | 0:7dd43900b657 | 23 | *****************************************************************************/ |
embeddedartists | 0:7dd43900b657 | 24 | |
embeddedartists | 0:7dd43900b657 | 25 | |
embeddedartists | 0:7dd43900b657 | 26 | /****************************************************************************** |
embeddedartists | 0:7dd43900b657 | 27 | * External variables |
embeddedartists | 0:7dd43900b657 | 28 | *****************************************************************************/ |
embeddedartists | 0:7dd43900b657 | 29 | extern EaLcdBoard lcdBoard; |
embeddedartists | 0:7dd43900b657 | 30 | extern bool abortTest; |
embeddedartists | 0:7dd43900b657 | 31 | |
embeddedartists | 0:7dd43900b657 | 32 | /****************************************************************************** |
embeddedartists | 0:7dd43900b657 | 33 | * Local functions |
embeddedartists | 0:7dd43900b657 | 34 | *****************************************************************************/ |
embeddedartists | 0:7dd43900b657 | 35 | |
embeddedartists | 0:7dd43900b657 | 36 | // Vertex structure |
embeddedartists | 0:7dd43900b657 | 37 | typedef struct |
embeddedartists | 0:7dd43900b657 | 38 | { |
embeddedartists | 0:7dd43900b657 | 39 | #ifdef USE_FLOAT |
embeddedartists | 0:7dd43900b657 | 40 | float x, y, z; |
embeddedartists | 0:7dd43900b657 | 41 | #else |
embeddedartists | 0:7dd43900b657 | 42 | long x, y, z; |
embeddedartists | 0:7dd43900b657 | 43 | #endif |
embeddedartists | 0:7dd43900b657 | 44 | }tVertex; |
embeddedartists | 0:7dd43900b657 | 45 | |
embeddedartists | 0:7dd43900b657 | 46 | // Transformed vertices |
embeddedartists | 0:7dd43900b657 | 47 | tVertex *gRVtx; |
embeddedartists | 0:7dd43900b657 | 48 | |
embeddedartists | 0:7dd43900b657 | 49 | #ifdef USE_FLOAT |
embeddedartists | 0:7dd43900b657 | 50 | // Original vertices |
embeddedartists | 0:7dd43900b657 | 51 | static tVertex *gVtx; |
embeddedartists | 0:7dd43900b657 | 52 | #else |
embeddedartists | 0:7dd43900b657 | 53 | static const tVertex gVtx[NUM_OF_DOTS] = { |
embeddedartists | 0:7dd43900b657 | 54 | {-21585, 17597, -17265}, |
embeddedartists | 0:7dd43900b657 | 55 | {28493, -7790, 14183}, |
embeddedartists | 0:7dd43900b657 | 56 | {13031, 27845, 11338}, |
embeddedartists | 0:7dd43900b657 | 57 | {10822, 29162, -10304}, |
embeddedartists | 0:7dd43900b657 | 58 | {19517, -25865, -4876}, |
embeddedartists | 0:7dd43900b657 | 59 | {1283, 30949, -10687}, |
embeddedartists | 0:7dd43900b657 | 60 | {-23097, 12297, 19723}, |
embeddedartists | 0:7dd43900b657 | 61 | {-17162, 1188, 27888}, |
embeddedartists | 0:7dd43900b657 | 62 | {-29007, -1547, 15163}, |
embeddedartists | 0:7dd43900b657 | 63 | {-8182, -31729, -197}, |
embeddedartists | 0:7dd43900b657 | 64 | {11599, -28575, -11073}, |
embeddedartists | 0:7dd43900b657 | 65 | {25963, 12182, 15850}, |
embeddedartists | 0:7dd43900b657 | 66 | {106, 10547, -31023}, |
embeddedartists | 0:7dd43900b657 | 67 | {-24312, 3053, -21755}, |
embeddedartists | 0:7dd43900b657 | 68 | {9966, -18803, -24916}, |
embeddedartists | 0:7dd43900b657 | 69 | {17598, -6037, -26973}, |
embeddedartists | 0:7dd43900b657 | 70 | {23321, 17149, -15353}, |
embeddedartists | 0:7dd43900b657 | 71 | {-3265, 8867, -31376}, |
embeddedartists | 0:7dd43900b657 | 72 | {-23639, 13701, 18087}, |
embeddedartists | 0:7dd43900b657 | 73 | {-2433, -22123, -24049}, |
embeddedartists | 0:7dd43900b657 | 74 | {21284, -11349, -22179}, |
embeddedartists | 0:7dd43900b657 | 75 | {-21407, 24683, -2486}, |
embeddedartists | 0:7dd43900b657 | 76 | {-32011, -4336, 5495}, |
embeddedartists | 0:7dd43900b657 | 77 | {-20191, 22605, 12450}, |
embeddedartists | 0:7dd43900b657 | 78 | {14752, -23540, 17376}, |
embeddedartists | 0:7dd43900b657 | 79 | {-8961, -17292, -26351}, |
embeddedartists | 0:7dd43900b657 | 80 | {-18078, 13561, -23727}, |
embeddedartists | 0:7dd43900b657 | 81 | {10730, -23639, 19994}, |
embeddedartists | 0:7dd43900b657 | 82 | {-18718, 17555, 20376}, |
embeddedartists | 0:7dd43900b657 | 83 | {13626, -22837, 19144}, |
embeddedartists | 0:7dd43900b657 | 84 | {-24695, -19036, -10073}, |
embeddedartists | 0:7dd43900b657 | 85 | {11935, 22275, 20859}, |
embeddedartists | 0:7dd43900b657 | 86 | {-2182, -28801, -15474}, |
embeddedartists | 0:7dd43900b657 | 87 | {21428, -21867, -11678}, |
embeddedartists | 0:7dd43900b657 | 88 | {-19601, 21558, -14991}, |
embeddedartists | 0:7dd43900b657 | 89 | {24512, 10876, -18830}, |
embeddedartists | 0:7dd43900b657 | 90 | {12385, 27881, 11956}, |
embeddedartists | 0:7dd43900b657 | 91 | {26982, 15618, -10088}, |
embeddedartists | 0:7dd43900b657 | 92 | {-16954, 19591, 20061}, |
embeddedartists | 0:7dd43900b657 | 93 | {-6027, 22699, -22850}, |
embeddedartists | 0:7dd43900b657 | 94 | {5453, 28825, -14598}, |
embeddedartists | 0:7dd43900b657 | 95 | {-20155, -16252, -20083}, |
embeddedartists | 0:7dd43900b657 | 96 | {-15962, 11757, -26089}, |
embeddedartists | 0:7dd43900b657 | 97 | {-29175, -11289, -9750}, |
embeddedartists | 0:7dd43900b657 | 98 | {-15370, 604, -28933}, |
embeddedartists | 0:7dd43900b657 | 99 | {26009, 19868, -1575}, |
embeddedartists | 0:7dd43900b657 | 100 | {24722, -17277, -12806}, |
embeddedartists | 0:7dd43900b657 | 101 | {-4527, 25836, -19639}, |
embeddedartists | 0:7dd43900b657 | 102 | {-22224, 10442, 21697}, |
embeddedartists | 0:7dd43900b657 | 103 | {-10388, 24393, -19255}}; |
embeddedartists | 0:7dd43900b657 | 104 | #endif |
embeddedartists | 0:7dd43900b657 | 105 | |
embeddedartists | 0:7dd43900b657 | 106 | unsigned short GlobeDemo::isqrt(unsigned long a) const { |
embeddedartists | 0:7dd43900b657 | 107 | unsigned long temp; |
embeddedartists | 0:7dd43900b657 | 108 | long e; |
embeddedartists | 0:7dd43900b657 | 109 | unsigned long x = 0; |
embeddedartists | 0:7dd43900b657 | 110 | if((a & 0xffff0000) != 0) |
embeddedartists | 0:7dd43900b657 | 111 | x = 444 + a / 26743; |
embeddedartists | 0:7dd43900b657 | 112 | else if((a & 0xff00) != 0) |
embeddedartists | 0:7dd43900b657 | 113 | x = 21 + a / 200; |
embeddedartists | 0:7dd43900b657 | 114 | else |
embeddedartists | 0:7dd43900b657 | 115 | x = 1 + a / 12; |
embeddedartists | 0:7dd43900b657 | 116 | do{ |
embeddedartists | 0:7dd43900b657 | 117 | temp = a / x; |
embeddedartists | 0:7dd43900b657 | 118 | e = (x - temp) / 2; |
embeddedartists | 0:7dd43900b657 | 119 | x = (x + temp) / 2; |
embeddedartists | 0:7dd43900b657 | 120 | } |
embeddedartists | 0:7dd43900b657 | 121 | while(e != 0); |
embeddedartists | 0:7dd43900b657 | 122 | return (unsigned short)x; |
embeddedartists | 0:7dd43900b657 | 123 | } |
embeddedartists | 0:7dd43900b657 | 124 | |
embeddedartists | 0:7dd43900b657 | 125 | short GlobeDemo::_sin(short y) const { |
embeddedartists | 0:7dd43900b657 | 126 | static short s1 = 0x6487; |
embeddedartists | 0:7dd43900b657 | 127 | static short s3 = 0x2951; |
embeddedartists | 0:7dd43900b657 | 128 | static short s5 = 0x4f6; |
embeddedartists | 0:7dd43900b657 | 129 | long z, prod, sum; |
embeddedartists | 0:7dd43900b657 | 130 | |
embeddedartists | 0:7dd43900b657 | 131 | z = ((long)y * y) >> 12; |
embeddedartists | 0:7dd43900b657 | 132 | prod = (z * s5) >> 16; |
embeddedartists | 0:7dd43900b657 | 133 | sum = s3 - prod; |
embeddedartists | 0:7dd43900b657 | 134 | prod = (z * sum) >> 16; |
embeddedartists | 0:7dd43900b657 | 135 | sum = s1 - prod; |
embeddedartists | 0:7dd43900b657 | 136 | |
embeddedartists | 0:7dd43900b657 | 137 | // for better accuracy, round here |
embeddedartists | 0:7dd43900b657 | 138 | return (short)((y * sum) >> 13); |
embeddedartists | 0:7dd43900b657 | 139 | } |
embeddedartists | 0:7dd43900b657 | 140 | |
embeddedartists | 0:7dd43900b657 | 141 | short GlobeDemo::_cos(short y) const { |
embeddedartists | 0:7dd43900b657 | 142 | static short c0 = 0x7fff; |
embeddedartists | 0:7dd43900b657 | 143 | static short c2 = 0x4eea; |
embeddedartists | 0:7dd43900b657 | 144 | static short c4 = 0x0fc4; |
embeddedartists | 0:7dd43900b657 | 145 | long z, prod, sum; |
embeddedartists | 0:7dd43900b657 | 146 | z = ((long)y * y) >> 12; |
embeddedartists | 0:7dd43900b657 | 147 | prod = (z * c4) >> 16; |
embeddedartists | 0:7dd43900b657 | 148 | sum = c2 - prod; |
embeddedartists | 0:7dd43900b657 | 149 | |
embeddedartists | 0:7dd43900b657 | 150 | // for better accuracy, round here |
embeddedartists | 0:7dd43900b657 | 151 | prod = (z * sum) >> 15; |
embeddedartists | 0:7dd43900b657 | 152 | return (short)(c0 - prod); |
embeddedartists | 0:7dd43900b657 | 153 | } |
embeddedartists | 0:7dd43900b657 | 154 | |
embeddedartists | 0:7dd43900b657 | 155 | short GlobeDemo::isine(short x) const { |
embeddedartists | 0:7dd43900b657 | 156 | unsigned short n = (((unsigned short)x + 0x2000) >> 14) & 0x3; |
embeddedartists | 0:7dd43900b657 | 157 | x -= n * 0x4000; |
embeddedartists | 0:7dd43900b657 | 158 | switch(n){ |
embeddedartists | 0:7dd43900b657 | 159 | case 0: |
embeddedartists | 0:7dd43900b657 | 160 | return _sin(x); |
embeddedartists | 0:7dd43900b657 | 161 | case 1: |
embeddedartists | 0:7dd43900b657 | 162 | return _cos(x); |
embeddedartists | 0:7dd43900b657 | 163 | case 2: |
embeddedartists | 0:7dd43900b657 | 164 | return - _sin(x); |
embeddedartists | 0:7dd43900b657 | 165 | case 3: |
embeddedartists | 0:7dd43900b657 | 166 | return - _cos(x); |
embeddedartists | 0:7dd43900b657 | 167 | } |
embeddedartists | 0:7dd43900b657 | 168 | return 0; |
embeddedartists | 0:7dd43900b657 | 169 | } |
embeddedartists | 0:7dd43900b657 | 170 | |
embeddedartists | 0:7dd43900b657 | 171 | |
embeddedartists | 0:7dd43900b657 | 172 | short GlobeDemo::icosine(short x) const { |
embeddedartists | 0:7dd43900b657 | 173 | return isine(x + 0x4000); |
embeddedartists | 0:7dd43900b657 | 174 | } |
embeddedartists | 0:7dd43900b657 | 175 | |
embeddedartists | 0:7dd43900b657 | 176 | void GlobeDemo::initialize() |
embeddedartists | 0:7dd43900b657 | 177 | { |
embeddedartists | 0:7dd43900b657 | 178 | // gVtx = (tVertex*)malloc(sizeof(tVertex) * NUM_OF_DOTS); |
embeddedartists | 0:7dd43900b657 | 179 | gRVtx = (tVertex*)malloc(sizeof(tVertex) * NUM_OF_DOTS); |
embeddedartists | 0:7dd43900b657 | 180 | |
embeddedartists | 0:7dd43900b657 | 181 | #ifdef USE_FLOAT |
embeddedartists | 0:7dd43900b657 | 182 | int i; |
embeddedartists | 0:7dd43900b657 | 183 | for (i = 0; i < NUM_OF_DOTS; i++) |
embeddedartists | 0:7dd43900b657 | 184 | { |
embeddedartists | 0:7dd43900b657 | 185 | gVtx[i].x = (rand() % 32768) - 16384.0f; |
embeddedartists | 0:7dd43900b657 | 186 | gVtx[i].y = (rand() % 32768) - 16384.0f; |
embeddedartists | 0:7dd43900b657 | 187 | gVtx[i].z = (rand() % 32768) - 16384.0f; |
embeddedartists | 0:7dd43900b657 | 188 | float len = (float)sqrt(gVtx[i].x * gVtx[i].x + |
embeddedartists | 0:7dd43900b657 | 189 | gVtx[i].y * gVtx[i].y + |
embeddedartists | 0:7dd43900b657 | 190 | gVtx[i].z * gVtx[i].z); |
embeddedartists | 0:7dd43900b657 | 191 | if (len != 0) |
embeddedartists | 0:7dd43900b657 | 192 | { |
embeddedartists | 0:7dd43900b657 | 193 | gVtx[i].x /= len; |
embeddedartists | 0:7dd43900b657 | 194 | gVtx[i].y /= len; |
embeddedartists | 0:7dd43900b657 | 195 | gVtx[i].z /= len; |
embeddedartists | 0:7dd43900b657 | 196 | } |
embeddedartists | 0:7dd43900b657 | 197 | } |
embeddedartists | 0:7dd43900b657 | 198 | #endif |
embeddedartists | 0:7dd43900b657 | 199 | } |
embeddedartists | 0:7dd43900b657 | 200 | |
embeddedartists | 0:7dd43900b657 | 201 | #ifdef USE_FLOAT |
embeddedartists | 0:7dd43900b657 | 202 | void GlobeDemo::rotate_z(float angle) |
embeddedartists | 0:7dd43900b657 | 203 | { |
embeddedartists | 0:7dd43900b657 | 204 | float ca = (float)cos(angle); |
embeddedartists | 0:7dd43900b657 | 205 | float sa = (float)sin(angle); |
embeddedartists | 0:7dd43900b657 | 206 | int i; |
embeddedartists | 0:7dd43900b657 | 207 | for (i = 0; i < NUM_OF_DOTS; i++) |
embeddedartists | 0:7dd43900b657 | 208 | { |
embeddedartists | 0:7dd43900b657 | 209 | float x = gRVtx[i].x * ca - gRVtx[i].y * sa; |
embeddedartists | 0:7dd43900b657 | 210 | float y = gRVtx[i].x * sa + gRVtx[i].y * ca; |
embeddedartists | 0:7dd43900b657 | 211 | gRVtx[i].x = x; |
embeddedartists | 0:7dd43900b657 | 212 | gRVtx[i].y = y; |
embeddedartists | 0:7dd43900b657 | 213 | } |
embeddedartists | 0:7dd43900b657 | 214 | } |
embeddedartists | 0:7dd43900b657 | 215 | |
embeddedartists | 0:7dd43900b657 | 216 | void GlobeDemo::rotate_y(float angle) |
embeddedartists | 0:7dd43900b657 | 217 | { |
embeddedartists | 0:7dd43900b657 | 218 | float ca = (float)cos(angle); |
embeddedartists | 0:7dd43900b657 | 219 | float sa = (float)sin(angle); |
embeddedartists | 0:7dd43900b657 | 220 | int i |
embeddedartists | 0:7dd43900b657 | 221 | for (i = 0; i < NUM_OF_DOTS; i++) |
embeddedartists | 0:7dd43900b657 | 222 | { |
embeddedartists | 0:7dd43900b657 | 223 | float z = gRVtx[i].z * ca - gRVtx[i].x * sa; |
embeddedartists | 0:7dd43900b657 | 224 | float x = gRVtx[i].z * sa + gRVtx[i].x * ca; |
embeddedartists | 0:7dd43900b657 | 225 | gRVtx[i].z = z; |
embeddedartists | 0:7dd43900b657 | 226 | gRVtx[i].x = x; |
embeddedartists | 0:7dd43900b657 | 227 | } |
embeddedartists | 0:7dd43900b657 | 228 | } |
embeddedartists | 0:7dd43900b657 | 229 | #else |
embeddedartists | 0:7dd43900b657 | 230 | void GlobeDemo::rotate_z(uint32_t angle) |
embeddedartists | 0:7dd43900b657 | 231 | { |
embeddedartists | 0:7dd43900b657 | 232 | uint32_t i; |
embeddedartists | 0:7dd43900b657 | 233 | long x,y,ca,sa; |
embeddedartists | 0:7dd43900b657 | 234 | |
embeddedartists | 0:7dd43900b657 | 235 | ca = icosine(angle); |
embeddedartists | 0:7dd43900b657 | 236 | sa = isine(angle); |
embeddedartists | 0:7dd43900b657 | 237 | for (i = 0; i < NUM_OF_DOTS; i++) |
embeddedartists | 0:7dd43900b657 | 238 | { |
embeddedartists | 0:7dd43900b657 | 239 | x = (gRVtx[i].x * ca - gRVtx[i].y * sa) / 0x7fff; |
embeddedartists | 0:7dd43900b657 | 240 | y = (gRVtx[i].x * sa + gRVtx[i].y * ca) / 0x7fff; |
embeddedartists | 0:7dd43900b657 | 241 | gRVtx[i].x = x; |
embeddedartists | 0:7dd43900b657 | 242 | gRVtx[i].y = y; |
embeddedartists | 0:7dd43900b657 | 243 | } |
embeddedartists | 0:7dd43900b657 | 244 | } |
embeddedartists | 0:7dd43900b657 | 245 | |
embeddedartists | 0:7dd43900b657 | 246 | void GlobeDemo::rotate_y(uint32_t angle) |
embeddedartists | 0:7dd43900b657 | 247 | { |
embeddedartists | 0:7dd43900b657 | 248 | uint32_t i; |
embeddedartists | 0:7dd43900b657 | 249 | long x,z,ca,sa; |
embeddedartists | 0:7dd43900b657 | 250 | |
embeddedartists | 0:7dd43900b657 | 251 | ca = icosine(angle); |
embeddedartists | 0:7dd43900b657 | 252 | sa = isine(angle); |
embeddedartists | 0:7dd43900b657 | 253 | for (i = 0; i < NUM_OF_DOTS; i++) |
embeddedartists | 0:7dd43900b657 | 254 | { |
embeddedartists | 0:7dd43900b657 | 255 | z = (gRVtx[i].z * ca - gRVtx[i].x * sa) / 0x7fff; |
embeddedartists | 0:7dd43900b657 | 256 | x = (gRVtx[i].z * sa + gRVtx[i].x * ca) / 0x7fff; |
embeddedartists | 0:7dd43900b657 | 257 | gRVtx[i].z = z; |
embeddedartists | 0:7dd43900b657 | 258 | gRVtx[i].x = x; |
embeddedartists | 0:7dd43900b657 | 259 | } |
embeddedartists | 0:7dd43900b657 | 260 | } |
embeddedartists | 0:7dd43900b657 | 261 | #endif |
embeddedartists | 0:7dd43900b657 | 262 | |
embeddedartists | 0:7dd43900b657 | 263 | #if 0 |
embeddedartists | 0:7dd43900b657 | 264 | void GlobeDemo::rotate_x(float angle) |
embeddedartists | 0:7dd43900b657 | 265 | { |
embeddedartists | 0:7dd43900b657 | 266 | float ca = (float)cos(angle); |
embeddedartists | 0:7dd43900b657 | 267 | float sa = (float)sin(angle); |
embeddedartists | 0:7dd43900b657 | 268 | int i; |
embeddedartists | 0:7dd43900b657 | 269 | for (i = 0; i < NUM_OF_DOTS; i++) |
embeddedartists | 0:7dd43900b657 | 270 | { |
embeddedartists | 0:7dd43900b657 | 271 | float y = gRVtx[i].y * ca - gRVtx[i].z * sa; |
embeddedartists | 0:7dd43900b657 | 272 | float z = gRVtx[i].y * sa + gRVtx[i].z * ca; |
embeddedartists | 0:7dd43900b657 | 273 | gRVtx[i].y = y; |
embeddedartists | 0:7dd43900b657 | 274 | gRVtx[i].z = z; |
embeddedartists | 0:7dd43900b657 | 275 | } |
embeddedartists | 0:7dd43900b657 | 276 | } |
embeddedartists | 0:7dd43900b657 | 277 | #endif |
embeddedartists | 0:7dd43900b657 | 278 | |
embeddedartists | 0:7dd43900b657 | 279 | void GlobeDemo::render(uint32_t idx) |
embeddedartists | 0:7dd43900b657 | 280 | { |
embeddedartists | 0:7dd43900b657 | 281 | uint32_t i; |
embeddedartists | 0:7dd43900b657 | 282 | #ifdef USE_FLOAT |
embeddedartists | 0:7dd43900b657 | 283 | float rotz; |
embeddedartists | 0:7dd43900b657 | 284 | float roty; |
embeddedartists | 0:7dd43900b657 | 285 | #else |
embeddedartists | 0:7dd43900b657 | 286 | uint32_t rotz; |
embeddedartists | 0:7dd43900b657 | 287 | uint32_t roty; |
embeddedartists | 0:7dd43900b657 | 288 | #endif |
embeddedartists | 0:7dd43900b657 | 289 | |
embeddedartists | 0:7dd43900b657 | 290 | static uint8_t cnt=0; |
embeddedartists | 0:7dd43900b657 | 291 | |
embeddedartists | 0:7dd43900b657 | 292 | if (cnt == 0) |
embeddedartists | 0:7dd43900b657 | 293 | { |
embeddedartists | 0:7dd43900b657 | 294 | cnt = 1; |
embeddedartists | 0:7dd43900b657 | 295 | pFrmBuf = pFrmBuf1; |
embeddedartists | 0:7dd43900b657 | 296 | } |
embeddedartists | 0:7dd43900b657 | 297 | else if (cnt == 1) |
embeddedartists | 0:7dd43900b657 | 298 | { |
embeddedartists | 0:7dd43900b657 | 299 | cnt = 2; |
embeddedartists | 0:7dd43900b657 | 300 | pFrmBuf = pFrmBuf2; |
embeddedartists | 0:7dd43900b657 | 301 | } |
embeddedartists | 0:7dd43900b657 | 302 | else |
embeddedartists | 0:7dd43900b657 | 303 | { |
embeddedartists | 0:7dd43900b657 | 304 | cnt = 0; |
embeddedartists | 0:7dd43900b657 | 305 | pFrmBuf = pFrmBuf3; |
embeddedartists | 0:7dd43900b657 | 306 | } |
embeddedartists | 0:7dd43900b657 | 307 | |
embeddedartists | 0:7dd43900b657 | 308 | graphics.setFrameBuffer(pFrmBuf); |
embeddedartists | 0:7dd43900b657 | 309 | |
embeddedartists | 0:7dd43900b657 | 310 | // rendering here |
embeddedartists | 0:7dd43900b657 | 311 | memset((void*)(pFrmBuf), BACKGROUND_COLOR, this->windowX * this->windowY * 2); |
embeddedartists | 0:7dd43900b657 | 312 | |
embeddedartists | 0:7dd43900b657 | 313 | // lcd_fillcircle(myLcdHnd, WIDTH / 2, HEIGHT / 2, HEIGHT / 4, LARGE_CIRCLE_COLOR); |
embeddedartists | 0:7dd43900b657 | 314 | graphics.put_circle(this->windowX / 2, this->windowY / 2, LARGE_CIRCLE_COLOR, this->windowY / 4, 1); |
embeddedartists | 0:7dd43900b657 | 315 | |
embeddedartists | 0:7dd43900b657 | 316 | memcpy(gRVtx, gVtx, sizeof(tVertex) * NUM_OF_DOTS); |
embeddedartists | 0:7dd43900b657 | 317 | |
embeddedartists | 0:7dd43900b657 | 318 | #ifdef USE_FLOAT |
embeddedartists | 0:7dd43900b657 | 319 | rotz = idx /*tick*/ * 0.0005f; |
embeddedartists | 0:7dd43900b657 | 320 | roty = idx /*tick*/ * 0.0020f; |
embeddedartists | 0:7dd43900b657 | 321 | #else |
embeddedartists | 0:7dd43900b657 | 322 | rotz = idx /*tick*/ * 50*5; |
embeddedartists | 0:7dd43900b657 | 323 | roty = idx /*tick*/ * 200*5; |
embeddedartists | 0:7dd43900b657 | 324 | #endif |
embeddedartists | 0:7dd43900b657 | 325 | rotate_y(roty); |
embeddedartists | 0:7dd43900b657 | 326 | rotate_z(rotz); |
embeddedartists | 0:7dd43900b657 | 327 | |
embeddedartists | 0:7dd43900b657 | 328 | for (i = 0; i < NUM_OF_DOTS; i++) |
embeddedartists | 0:7dd43900b657 | 329 | { |
embeddedartists | 0:7dd43900b657 | 330 | uint16_t c = SMALL_CIRCLE_FRONT_COLOR; |
embeddedartists | 0:7dd43900b657 | 331 | |
embeddedartists | 0:7dd43900b657 | 332 | if (gRVtx[i].z < 0) |
embeddedartists | 0:7dd43900b657 | 333 | c = SMALL_CIRCLE_BACK_COLOR; |
embeddedartists | 0:7dd43900b657 | 334 | #if 0 |
embeddedartists | 0:7dd43900b657 | 335 | lcd_point(myLcdHnd, |
embeddedartists | 0:7dd43900b657 | 336 | (int)((gRVtx[i].x * (HEIGHT / 4)) / 0x7fff + WIDTH / 2), |
embeddedartists | 0:7dd43900b657 | 337 | (int)((gRVtx[i].y * (HEIGHT / 4)) / 0x7fff + HEIGHT / 2), |
embeddedartists | 0:7dd43900b657 | 338 | c); |
embeddedartists | 0:7dd43900b657 | 339 | #else |
embeddedartists | 0:7dd43900b657 | 340 | // lcd_fillcircle(myLcdHnd, |
embeddedartists | 0:7dd43900b657 | 341 | // (int)((gRVtx[i].x * (HEIGHT / 4)) / 0x7fff + WIDTH / 2), |
embeddedartists | 0:7dd43900b657 | 342 | // (int)((gRVtx[i].y * (HEIGHT / 4)) / 0x7fff + HEIGHT / 2), |
embeddedartists | 0:7dd43900b657 | 343 | // 2, |
embeddedartists | 0:7dd43900b657 | 344 | // c); |
embeddedartists | 0:7dd43900b657 | 345 | graphics.put_circle((int)((gRVtx[i].x * (this->windowY / 4)) / 0x7fff + this->windowX / 2), (int)((gRVtx[i].y * (this->windowY / 4)) / 0x7fff + this->windowY / 2), c, 2, 1); |
embeddedartists | 0:7dd43900b657 | 346 | |
embeddedartists | 0:7dd43900b657 | 347 | #endif |
embeddedartists | 0:7dd43900b657 | 348 | } |
embeddedartists | 0:7dd43900b657 | 349 | #ifdef USE_FLOAT |
embeddedartists | 0:7dd43900b657 | 350 | lcd_fillcircle(myLcdHnd, |
embeddedartists | 0:7dd43900b657 | 351 | (int)((WIDTH / 3) * cos(rotz) + WIDTH / 2), |
embeddedartists | 0:7dd43900b657 | 352 | (int)((WIDTH / 3) * sin(rotz) + HEIGHT / 2), |
embeddedartists | 0:7dd43900b657 | 353 | 6, |
embeddedartists | 0:7dd43900b657 | 354 | SMALL_CIRCLE_FRONT_COLOR); |
embeddedartists | 0:7dd43900b657 | 355 | #else |
embeddedartists | 0:7dd43900b657 | 356 | // lcd_fillcircle(myLcdHnd, |
embeddedartists | 0:7dd43900b657 | 357 | // (int)(((HEIGHT / 3) * icosine(rotz))/0x7fff + WIDTH / 2), |
embeddedartists | 0:7dd43900b657 | 358 | // (int)(((HEIGHT / 3) * isine(rotz)) /0x7fff + HEIGHT / 2), |
embeddedartists | 0:7dd43900b657 | 359 | // 7, |
embeddedartists | 0:7dd43900b657 | 360 | // SMALL_CIRCLE_FRONT_COLOR); |
embeddedartists | 0:7dd43900b657 | 361 | graphics.put_circle((int)(((this->windowY / 3) * icosine(rotz))/0x7fff + this->windowX / 2), (int)(((this->windowY / 3) * isine(rotz)) /0x7fff + this->windowY / 2), SMALL_CIRCLE_FRONT_COLOR, 7, 1); |
embeddedartists | 0:7dd43900b657 | 362 | #endif |
embeddedartists | 0:7dd43900b657 | 363 | } |
embeddedartists | 0:7dd43900b657 | 364 | |
embeddedartists | 0:7dd43900b657 | 365 | |
embeddedartists | 0:7dd43900b657 | 366 | /****************************************************************************** |
embeddedartists | 0:7dd43900b657 | 367 | * Public functions |
embeddedartists | 0:7dd43900b657 | 368 | *****************************************************************************/ |
embeddedartists | 0:7dd43900b657 | 369 | GlobeDemo::GlobeDemo(uint8_t *pFrameBuf, uint16_t dispWidth, uint16_t dispHeight) |
embeddedartists | 0:7dd43900b657 | 370 | : graphics((uint16_t *)pFrameBuf, dispWidth, dispHeight) { |
embeddedartists | 0:7dd43900b657 | 371 | |
embeddedartists | 0:7dd43900b657 | 372 | this->windowX = dispWidth; |
embeddedartists | 0:7dd43900b657 | 373 | this->windowY = dispHeight; |
embeddedartists | 0:7dd43900b657 | 374 | this->pFrmBuf = (uint16_t *)pFrameBuf; |
embeddedartists | 0:7dd43900b657 | 375 | this->pFrmBuf1 = (uint16_t *)pFrameBuf; |
embeddedartists | 0:7dd43900b657 | 376 | this->pFrmBuf2 = (uint16_t *)((uint32_t)pFrameBuf + dispWidth*dispHeight*2); |
embeddedartists | 0:7dd43900b657 | 377 | this->pFrmBuf3 = (uint16_t *)((uint32_t)pFrameBuf + dispWidth*dispHeight*4); |
embeddedartists | 0:7dd43900b657 | 378 | |
embeddedartists | 0:7dd43900b657 | 379 | initialize(); |
embeddedartists | 0:7dd43900b657 | 380 | } |
embeddedartists | 0:7dd43900b657 | 381 | |
embeddedartists | 0:7dd43900b657 | 382 | void GlobeDemo::run(uint32_t loops, uint32_t delayMs) { |
embeddedartists | 0:7dd43900b657 | 383 | |
embeddedartists | 0:7dd43900b657 | 384 | printf("GlobeDemo, %d loops, %dms delay\n", loops, delayMs); |
embeddedartists | 0:7dd43900b657 | 385 | |
embeddedartists | 0:7dd43900b657 | 386 | for(int32_t n=0;n<loops;n++) { |
embeddedartists | 0:7dd43900b657 | 387 | |
embeddedartists | 0:7dd43900b657 | 388 | //render globe |
embeddedartists | 0:7dd43900b657 | 389 | render(n); |
embeddedartists | 0:7dd43900b657 | 390 | |
embeddedartists | 0:7dd43900b657 | 391 | //update framebuffer |
embeddedartists | 0:7dd43900b657 | 392 | lcdBoard.setFrameBuffer((uint32_t)this->pFrmBuf); |
embeddedartists | 0:7dd43900b657 | 393 | |
embeddedartists | 0:7dd43900b657 | 394 | if (abortTest) { |
embeddedartists | 0:7dd43900b657 | 395 | break; |
embeddedartists | 0:7dd43900b657 | 396 | } |
embeddedartists | 0:7dd43900b657 | 397 | |
embeddedartists | 0:7dd43900b657 | 398 | wait_ms(delayMs); |
embeddedartists | 0:7dd43900b657 | 399 | } |
embeddedartists | 0:7dd43900b657 | 400 | free(gRVtx); |
embeddedartists | 0:7dd43900b657 | 401 | } |
embeddedartists | 0:7dd43900b657 | 402 |