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