EmbeddedArtists AB
/
app_lcdboard_demo_cube
Example for the LPC4088 QSB Base Board
CubeDemo.cpp@3:15f457b3bdbd, 2014-04-09 (annotated)
- Committer:
- embeddedartists
- Date:
- Wed Apr 09 09:44:58 2014 +0000
- Revision:
- 3:15f457b3bdbd
- Parent:
- 0:a771927a62fd
Updated to latest version of EALib
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
embeddedartists | 0:a771927a62fd | 1 | /****************************************************************************** |
embeddedartists | 0:a771927a62fd | 2 | * Includes |
embeddedartists | 0:a771927a62fd | 3 | *****************************************************************************/ |
embeddedartists | 0:a771927a62fd | 4 | |
embeddedartists | 0:a771927a62fd | 5 | #include "mbed.h" |
embeddedartists | 0:a771927a62fd | 6 | |
embeddedartists | 0:a771927a62fd | 7 | #include "LcdController.h" |
embeddedartists | 0:a771927a62fd | 8 | #include "EaLcdBoard.h" |
embeddedartists | 0:a771927a62fd | 9 | #include "CubeDemo.h" |
embeddedartists | 0:a771927a62fd | 10 | |
embeddedartists | 0:a771927a62fd | 11 | #include "Image.h" |
embeddedartists | 0:a771927a62fd | 12 | |
embeddedartists | 0:a771927a62fd | 13 | //#include "wchar.h" |
embeddedartists | 0:a771927a62fd | 14 | #include <math.h> |
embeddedartists | 0:a771927a62fd | 15 | |
embeddedartists | 0:a771927a62fd | 16 | |
embeddedartists | 0:a771927a62fd | 17 | extern const unsigned char cube_image1[]; |
embeddedartists | 0:a771927a62fd | 18 | extern int cube_image1_sz; |
embeddedartists | 0:a771927a62fd | 19 | extern const unsigned char cube_image2[]; |
embeddedartists | 0:a771927a62fd | 20 | extern int cube_image2_sz; |
embeddedartists | 0:a771927a62fd | 21 | |
embeddedartists | 0:a771927a62fd | 22 | |
embeddedartists | 0:a771927a62fd | 23 | /****************************************************************************** |
embeddedartists | 0:a771927a62fd | 24 | * Typedefs and defines |
embeddedartists | 0:a771927a62fd | 25 | *****************************************************************************/ |
embeddedartists | 0:a771927a62fd | 26 | |
embeddedartists | 0:a771927a62fd | 27 | /****************************************************************************** |
embeddedartists | 0:a771927a62fd | 28 | * Local variables |
embeddedartists | 0:a771927a62fd | 29 | *****************************************************************************/ |
embeddedartists | 0:a771927a62fd | 30 | |
embeddedartists | 0:a771927a62fd | 31 | |
embeddedartists | 0:a771927a62fd | 32 | /****************************************************************************** |
embeddedartists | 0:a771927a62fd | 33 | * External variables |
embeddedartists | 0:a771927a62fd | 34 | *****************************************************************************/ |
embeddedartists | 0:a771927a62fd | 35 | extern EaLcdBoard lcdBoard; |
embeddedartists | 0:a771927a62fd | 36 | extern bool abortTest; |
embeddedartists | 0:a771927a62fd | 37 | |
embeddedartists | 0:a771927a62fd | 38 | /****************************************************************************** |
embeddedartists | 0:a771927a62fd | 39 | * Local functions |
embeddedartists | 0:a771927a62fd | 40 | *****************************************************************************/ |
embeddedartists | 0:a771927a62fd | 41 | |
embeddedartists | 0:a771927a62fd | 42 | |
embeddedartists | 0:a771927a62fd | 43 | |
embeddedartists | 0:a771927a62fd | 44 | |
embeddedartists | 0:a771927a62fd | 45 | /* (c) 2008 by Denis Markovic |
embeddedartists | 0:a771927a62fd | 46 | I give hereby permission to Anders Rosvall of Embedded Artists to use this function in his ARM7 board |
embeddedartists | 0:a771927a62fd | 47 | demo program, as long as I'm not hold responsible for bugs in the code and I take not responsibility |
embeddedartists | 0:a771927a62fd | 48 | for any damage used by that code :-) */ |
embeddedartists | 0:a771927a62fd | 49 | |
embeddedartists | 0:a771927a62fd | 50 | #define TRIANG_PROJ_SFT 16 |
embeddedartists | 0:a771927a62fd | 51 | |
embeddedartists | 0:a771927a62fd | 52 | static unsigned short DivTab[] = |
embeddedartists | 0:a771927a62fd | 53 | {0xffff, 0x7fff, 0x5554, 0x3fff, 0x3332, 0x2aa9, 0x2491, |
embeddedartists | 0:a771927a62fd | 54 | 0x1fff, 0x1c70, 0x1998, 0x1744, 0x1554, 0x13b0, 0x1248, 0x1110, |
embeddedartists | 0:a771927a62fd | 55 | 0x0fff, 0x0f0e, 0x0e37, 0x0d78, 0x0ccb, 0x0c2f, 0x0ba1, 0x0b20, |
embeddedartists | 0:a771927a62fd | 56 | 0x0aa9, 0x0a3c, 0x09d7, 0x097a, 0x0923, 0x08d2, 0x0887, 0x0841, |
embeddedartists | 0:a771927a62fd | 57 | 0x07ff, 0x07c0, 0x0786, 0x074f, 0x071b, 0x06ea, 0x06bb, 0x068f, |
embeddedartists | 0:a771927a62fd | 58 | 0x0665, 0x063d, 0x0617, 0x05f3, 0x05d0, 0x05af, 0x058f, 0x0571, |
embeddedartists | 0:a771927a62fd | 59 | 0x0554, 0x0538, 0x051d, 0x0504, 0x04eb, 0x04d3, 0x04bc, 0x04a6, |
embeddedartists | 0:a771927a62fd | 60 | 0x0491, 0x047c, 0x0468, 0x0455, 0x0443, 0x0431, 0x0420, 0x040f, |
embeddedartists | 0:a771927a62fd | 61 | 0x03ff, 0x03ef, 0x03df, 0x03d1, 0x03c2, 0x03b4, 0x03a7, 0x039a, |
embeddedartists | 0:a771927a62fd | 62 | 0x038d, 0x0380, 0x0374, 0x0368, 0x035d, 0x0352, 0x0347, 0x033c, |
embeddedartists | 0:a771927a62fd | 63 | 0x0332, 0x0328, 0x031e, 0x0314, 0x030b, 0x0302, 0x02f9, 0x02f0, |
embeddedartists | 0:a771927a62fd | 64 | 0x02e7, 0x02df, 0x02d7, 0x02cf, 0x02c7, 0x02bf, 0x02b8, 0x02b0, |
embeddedartists | 0:a771927a62fd | 65 | 0x02a9, 0x02a2, 0x029b, 0x0294, 0x028e, 0x0287, 0x0281, 0x027b, |
embeddedartists | 0:a771927a62fd | 66 | 0x0275, 0x026f, 0x0269, 0x0263, 0x025d, 0x0258, 0x0252, 0x024d, |
embeddedartists | 0:a771927a62fd | 67 | 0x0248, 0x0242, 0x023d, 0x0238, 0x0233, 0x022f, 0x022a, 0x0225, |
embeddedartists | 0:a771927a62fd | 68 | 0x0221, 0x021c, 0x0218, 0x0213, 0x020f, 0x020b, 0x0207, 0x0203, |
embeddedartists | 0:a771927a62fd | 69 | 0x01ff, 0x01fb, 0x01f7, 0x01f3, 0x01ef, 0x01eb, 0x01e8, 0x01e4, |
embeddedartists | 0:a771927a62fd | 70 | 0x01e0, 0x01dd, 0x01d9, 0x01d6, 0x01d3, 0x01cf, 0x01cc, 0x01c9, |
embeddedartists | 0:a771927a62fd | 71 | 0x01c6, 0x01c2, 0x01bf, 0x01bc, 0x01b9, 0x01b6, 0x01b3, 0x01b1, |
embeddedartists | 0:a771927a62fd | 72 | 0x01ae, 0x01ab, 0x01a8, 0x01a5, 0x01a3, 0x01a0, 0x019d, 0x019b, |
embeddedartists | 0:a771927a62fd | 73 | 0x0198, 0x0196, 0x0193, 0x0191, 0x018e, 0x018c, 0x0189, 0x0187, |
embeddedartists | 0:a771927a62fd | 74 | 0x0185, 0x0182, 0x0180, 0x017e, 0x017c, 0x0179, 0x0177, 0x0175, |
embeddedartists | 0:a771927a62fd | 75 | 0x0173, 0x0171, 0x016f, 0x016d, 0x016b, 0x0169, 0x0167, 0x0165, |
embeddedartists | 0:a771927a62fd | 76 | 0x0163, 0x0161, 0x015f, 0x015d, 0x015b, 0x0159, 0x0157, 0x0156, |
embeddedartists | 0:a771927a62fd | 77 | 0x0154, 0x0152, 0x0150, 0x014f, 0x014d, 0x014b, 0x0149, 0x0148, |
embeddedartists | 0:a771927a62fd | 78 | 0x0146, 0x0145, 0x0143, 0x0141, 0x0140, 0x013e, 0x013d, 0x013b, |
embeddedartists | 0:a771927a62fd | 79 | 0x013a, 0x0138, 0x0137, 0x0135, 0x0134, 0x0132, 0x0131, 0x012f, |
embeddedartists | 0:a771927a62fd | 80 | 0x012e, 0x012d, 0x012b, 0x012a, 0x0128, 0x0127, 0x0126, 0x0124, |
embeddedartists | 0:a771927a62fd | 81 | 0x0123, 0x0122, 0x0120, 0x011f, 0x011e, 0x011d, 0x011b, 0x011a, |
embeddedartists | 0:a771927a62fd | 82 | 0x0119, 0x0118, 0x0117, 0x0115, 0x0114, 0x0113, 0x0112, 0x0111, |
embeddedartists | 0:a771927a62fd | 83 | 0x0110, 0x010e, 0x010d, 0x010c, 0x010b, 0x010a, 0x0109, 0x0108, |
embeddedartists | 0:a771927a62fd | 84 | 0x0107, 0x0106, 0x0105, 0x0104, 0x0103, 0x0102, 0x0101, 0x0100, |
embeddedartists | 0:a771927a62fd | 85 | 0x00ff, 0x00fe, 0x00fd, 0x00fc, 0x00fb, 0x00fa, 0x00f9, 0x00f8, |
embeddedartists | 0:a771927a62fd | 86 | 0x00f7, 0x00f6, 0x00f5, 0x00f4, 0x00f3, 0x00f2, 0x00f1, 0x00f0, |
embeddedartists | 0:a771927a62fd | 87 | 0x00ef, 0x00ef, 0x00ee, 0x00ed, 0x00ec, 0x00eb, 0x00ea, 0x00e9, |
embeddedartists | 0:a771927a62fd | 88 | 0x00e9, 0x00e8, 0x00e7, 0x00e6, 0x00e5, 0x00e4, 0x00e4, 0x00e3, |
embeddedartists | 0:a771927a62fd | 89 | 0x00e2, 0x00e1, 0x00e0, 0x00e0, 0x00df, 0x00de, 0x00dd, 0x00dd, |
embeddedartists | 0:a771927a62fd | 90 | 0x00dc, 0x00db, 0x00da, 0x00da, 0x00d9, 0x00d8, 0x00d8, 0x00d7, |
embeddedartists | 0:a771927a62fd | 91 | 0x00d6, 0x00d5, 0x00d5, 0x00d4, 0x00d3, 0x00d3, 0x00d2, 0x00d1, |
embeddedartists | 0:a771927a62fd | 92 | 0x00d1, 0x00d0, 0x00cf, 0x00cf, 0x00ce, 0x00cd, 0x00cd, 0x00cc, |
embeddedartists | 0:a771927a62fd | 93 | 0x00cb, 0x00cb, 0x00ca, 0x00c9, 0x00c9, 0x00c8, 0x00c8, 0x00c7, |
embeddedartists | 0:a771927a62fd | 94 | 0x00c6, 0x00c6, 0x00c5, 0x00c4, 0x00c4, 0x00c3, 0x00c3, 0x00c2, |
embeddedartists | 0:a771927a62fd | 95 | 0x00c2, 0x00c1, 0x00c0, 0x00c0, 0x00bf, 0x00bf, 0x00be, 0x00be, |
embeddedartists | 0:a771927a62fd | 96 | 0x00bd, 0x00bc, 0x00bc, 0x00bb, 0x00bb, 0x00ba, 0x00ba, 0x00b9, |
embeddedartists | 0:a771927a62fd | 97 | 0x00b9, 0x00b8, 0x00b8, 0x00b7, 0x00b7, 0x00b6, 0x00b6, 0x00b5, |
embeddedartists | 0:a771927a62fd | 98 | 0x00b5, 0x00b4, 0x00b4, 0x00b3, 0x00b3, 0x00b2, 0x00b2, 0x00b1, |
embeddedartists | 0:a771927a62fd | 99 | 0x00b1, 0x00b0, 0x00b0, 0x00af, 0x00af, 0x00ae, 0x00ae, 0x00ad, |
embeddedartists | 0:a771927a62fd | 100 | 0x00ad, 0x00ac, 0x00ac, 0x00ab, 0x00ab, 0x00ab, 0x00aa, 0x00aa, |
embeddedartists | 0:a771927a62fd | 101 | 0x00a9, 0x00a9, 0x00a8, 0x00a8, 0x00a7, 0x00a7, 0x00a7, 0x00a6, |
embeddedartists | 0:a771927a62fd | 102 | 0x00a6, 0x00a5, 0x00a5, 0x00a4, 0x00a4, 0x00a4, 0x00a3, 0x00a3, |
embeddedartists | 0:a771927a62fd | 103 | 0x00a2, 0x00a2, 0x00a2, 0x00a1, 0x00a1, 0x00a0, 0x00a0, 0x00a0, |
embeddedartists | 0:a771927a62fd | 104 | 0x009f, 0x009f, 0x009e, 0x009e, 0x009e, 0x009d, 0x009d, 0x009c, |
embeddedartists | 0:a771927a62fd | 105 | 0x009c, 0x009c, 0x009b, 0x009b, 0x009b, 0x009a, 0x009a, 0x0099, |
embeddedartists | 0:a771927a62fd | 106 | 0x0099, 0x0099, 0x0098, 0x0098, 0x0098, 0x0097, 0x0097, 0x0097, |
embeddedartists | 0:a771927a62fd | 107 | 0x0096, 0x0096, 0x0096, 0x0095, 0x0095, 0x0094, 0x0094, 0x0094, |
embeddedartists | 0:a771927a62fd | 108 | 0x0093, 0x0093, 0x0093, 0x0092, 0x0092, 0x0092, 0x0091, 0x0091, |
embeddedartists | 0:a771927a62fd | 109 | 0x0091, 0x0090, 0x0090, 0x0090, 0x008f, 0x008f, 0x008f, 0x008f, |
embeddedartists | 0:a771927a62fd | 110 | 0x008e, 0x008e, 0x008e, 0x008d, 0x008d, 0x008d, 0x008c, 0x008c, |
embeddedartists | 0:a771927a62fd | 111 | 0x008c, 0x008b, 0x008b, 0x008b, 0x008b, 0x008a, 0x008a, 0x008a, |
embeddedartists | 0:a771927a62fd | 112 | 0x0089, 0x0089, 0x0089, 0x0088, 0x0088, 0x0088, 0x0088, 0x0087, |
embeddedartists | 0:a771927a62fd | 113 | 0x0087, 0x0087, 0x0086, 0x0086, 0x0086, 0x0086, 0x0085, 0x0085, |
embeddedartists | 0:a771927a62fd | 114 | 0x0085, 0x0085, 0x0084, 0x0084, 0x0084, 0x0083, 0x0083, 0x0083, |
embeddedartists | 0:a771927a62fd | 115 | 0x0083, 0x0082, 0x0082, 0x0082, 0x0082, 0x0081, 0x0081, 0x0081, |
embeddedartists | 0:a771927a62fd | 116 | 0x0081, 0x0080, 0x0080, 0x0080, 0x0080, 0x007f, 0x007f, 0x007f, |
embeddedartists | 0:a771927a62fd | 117 | }; |
embeddedartists | 0:a771927a62fd | 118 | |
embeddedartists | 0:a771927a62fd | 119 | /* (c) 2008 by Denis Markovic |
embeddedartists | 0:a771927a62fd | 120 | I give hereby permission to Anders Rosvall of Embedded Artists to use this function in his ARM7 board |
embeddedartists | 0:a771927a62fd | 121 | demo program, as long as I'm not hold responsible for bugs in the code and I take not responsibility |
embeddedartists | 0:a771927a62fd | 122 | for any damage used by that code :-) */ |
embeddedartists | 0:a771927a62fd | 123 | void CubeDemo::CpPixel16Fast(int xSrc, int ySrc, int x, int y, Surface_t *SrcRP_p, Surface_t *DstRP_p) |
embeddedartists | 0:a771927a62fd | 124 | { |
embeddedartists | 0:a771927a62fd | 125 | unsigned short *src_p, *dst_p; |
embeddedartists | 0:a771927a62fd | 126 | |
embeddedartists | 0:a771927a62fd | 127 | src_p = (unsigned short *) SrcRP_p->pixels; |
embeddedartists | 0:a771927a62fd | 128 | dst_p = (unsigned short *) DstRP_p->pixels; |
embeddedartists | 0:a771927a62fd | 129 | |
embeddedartists | 0:a771927a62fd | 130 | dst_p[y * DstRP_p->w + x] = src_p[ySrc * SrcRP_p->w + xSrc]; |
embeddedartists | 0:a771927a62fd | 131 | |
embeddedartists | 0:a771927a62fd | 132 | return; |
embeddedartists | 0:a771927a62fd | 133 | } |
embeddedartists | 0:a771927a62fd | 134 | |
embeddedartists | 0:a771927a62fd | 135 | /* (c) 2008 by Denis Markovic |
embeddedartists | 0:a771927a62fd | 136 | I give hereby permission to Anders Rosvall of Embedded Artists to use this function in his ARM7 board |
embeddedartists | 0:a771927a62fd | 137 | demo program, as long as I'm not hold responsible for bugs in the code and I take not responsibility |
embeddedartists | 0:a771927a62fd | 138 | for any damage used by that code :-) |
embeddedartists | 0:a771927a62fd | 139 | |
embeddedartists | 0:a771927a62fd | 140 | Input: SrcRP_p: pointer to type holding width and height and ptr to source pixel data |
embeddedartists | 0:a771927a62fd | 141 | DstRP_p: pointer to type holding width and height and ptr to destination pixel data (i.e. gfx memory to draw to) |
embeddedartists | 0:a771927a62fd | 142 | SrcCoords_p: pointer to array holding 3 source coordinates into triangle source accessed through SrcRP_p |
embeddedartists | 0:a771927a62fd | 143 | DstCoords_p: pointer to array holding 3 destination triangle coordinates in draw buffer which is accessed through DstRP_p |
embeddedartists | 0:a771927a62fd | 144 | |
embeddedartists | 0:a771927a62fd | 145 | Description: take triangle from source rectangular picture (raw data, 16 bit) and project it into a triangle |
embeddedartists | 0:a771927a62fd | 146 | in the destination picture (also 16 bit) |
embeddedartists | 0:a771927a62fd | 147 | */ |
embeddedartists | 0:a771927a62fd | 148 | void CubeDemo::TriangleProjectFast(Surface_t *SrcRP_p, Surface_t *DstRP_p, Coord2D_t *SrcCoords_p, Coord2D_t *DstCoords_p) |
embeddedartists | 0:a771927a62fd | 149 | { |
embeddedartists | 0:a771927a62fd | 150 | int TopCoord = 0, MiddleCoord = 1, BottomCoord = 2; |
embeddedartists | 0:a771927a62fd | 151 | int /*SrcStartX, SrcStartY,*/ x, y, Direction, i, j; |
embeddedartists | 0:a771927a62fd | 152 | long dxDstBig, dxDstSmall, dxSrcBig, dxSrcSmall, dySrcBig, dySrcSmall, DeltaY; |
embeddedartists | 0:a771927a62fd | 153 | int DivMultVal; |
embeddedartists | 0:a771927a62fd | 154 | |
embeddedartists | 0:a771927a62fd | 155 | /* 1. step: sort dst triangle points */ |
embeddedartists | 0:a771927a62fd | 156 | if(DstCoords_p[1].y < DstCoords_p[TopCoord].y) |
embeddedartists | 0:a771927a62fd | 157 | { |
embeddedartists | 0:a771927a62fd | 158 | TopCoord = 1; |
embeddedartists | 0:a771927a62fd | 159 | MiddleCoord = 0; |
embeddedartists | 0:a771927a62fd | 160 | } |
embeddedartists | 0:a771927a62fd | 161 | |
embeddedartists | 0:a771927a62fd | 162 | if(DstCoords_p[2].y < DstCoords_p[TopCoord].y) |
embeddedartists | 0:a771927a62fd | 163 | { |
embeddedartists | 0:a771927a62fd | 164 | TopCoord = 2; |
embeddedartists | 0:a771927a62fd | 165 | BottomCoord = 1; |
embeddedartists | 0:a771927a62fd | 166 | MiddleCoord = 0; |
embeddedartists | 0:a771927a62fd | 167 | } |
embeddedartists | 0:a771927a62fd | 168 | |
embeddedartists | 0:a771927a62fd | 169 | if(DstCoords_p[BottomCoord].y < DstCoords_p[MiddleCoord].y) |
embeddedartists | 0:a771927a62fd | 170 | { |
embeddedartists | 0:a771927a62fd | 171 | int tmp; |
embeddedartists | 0:a771927a62fd | 172 | tmp = MiddleCoord; |
embeddedartists | 0:a771927a62fd | 173 | MiddleCoord = BottomCoord; |
embeddedartists | 0:a771927a62fd | 174 | BottomCoord = tmp; |
embeddedartists | 0:a771927a62fd | 175 | } |
embeddedartists | 0:a771927a62fd | 176 | |
embeddedartists | 0:a771927a62fd | 177 | /* so now we have the 3 sorted dst triangle points in TopCoord, MiddleCoord and BottomCoord |
embeddedartists | 0:a771927a62fd | 178 | (can be done much more efficient with arithmetics instead of if or use pos/neg direction |
embeddedartists | 0:a771927a62fd | 179 | vectors later?) */ |
embeddedartists | 0:a771927a62fd | 180 | |
embeddedartists | 0:a771927a62fd | 181 | /* 2. step: find start and end points for this line in src and dst triangle for each |
embeddedartists | 0:a771927a62fd | 182 | line; start pt always on a line that originates from middle point; later replace |
embeddedartists | 0:a771927a62fd | 183 | all div by mult with 1/DeltaY, i.e. only one division, maybe even save 1/... in |
embeddedartists | 0:a771927a62fd | 184 | Tab as there are not so many possible DeltaY */ |
embeddedartists | 0:a771927a62fd | 185 | DeltaY = (long) DstCoords_p[BottomCoord].y - DstCoords_p[TopCoord].y + 1; |
embeddedartists | 0:a771927a62fd | 186 | |
embeddedartists | 0:a771927a62fd | 187 | DivMultVal = ((int) DivTab[DeltaY-1] + 1); |
embeddedartists | 0:a771927a62fd | 188 | |
embeddedartists | 0:a771927a62fd | 189 | dxDstBig = ((long) DstCoords_p[BottomCoord].x - DstCoords_p[TopCoord].x + 1) * DivMultVal; |
embeddedartists | 0:a771927a62fd | 190 | dySrcBig = ((long) SrcCoords_p[BottomCoord].y - SrcCoords_p[TopCoord].y + 1) * DivMultVal; |
embeddedartists | 0:a771927a62fd | 191 | dxSrcBig = ((long) SrcCoords_p[BottomCoord].x - SrcCoords_p[TopCoord].x + 1) * DivMultVal; |
embeddedartists | 0:a771927a62fd | 192 | |
embeddedartists | 0:a771927a62fd | 193 | DeltaY = (long) DstCoords_p[MiddleCoord].y - DstCoords_p[TopCoord].y + 1; |
embeddedartists | 0:a771927a62fd | 194 | |
embeddedartists | 0:a771927a62fd | 195 | DivMultVal = ((int) DivTab[DeltaY-1] + 1); |
embeddedartists | 0:a771927a62fd | 196 | |
embeddedartists | 0:a771927a62fd | 197 | dxDstSmall = ((long) DstCoords_p[MiddleCoord].x - DstCoords_p[TopCoord].x + 1) * DivMultVal; |
embeddedartists | 0:a771927a62fd | 198 | dySrcSmall = ((long) SrcCoords_p[MiddleCoord].y - SrcCoords_p[TopCoord].y + 1) * DivMultVal; |
embeddedartists | 0:a771927a62fd | 199 | dxSrcSmall = ((long) SrcCoords_p[MiddleCoord].x - SrcCoords_p[TopCoord].x + 1) * DivMultVal; |
embeddedartists | 0:a771927a62fd | 200 | |
embeddedartists | 0:a771927a62fd | 201 | Direction = 1; |
embeddedartists | 0:a771927a62fd | 202 | if(dxDstSmall > dxDstBig) |
embeddedartists | 0:a771927a62fd | 203 | Direction = -1; |
embeddedartists | 0:a771927a62fd | 204 | |
embeddedartists | 0:a771927a62fd | 205 | for(y = DstCoords_p[TopCoord].y, i=0; y <= DstCoords_p[MiddleCoord].y; y++, i++) |
embeddedartists | 0:a771927a62fd | 206 | { /* for each row/line */ |
embeddedartists | 0:a771927a62fd | 207 | long MoveSrcX, MoveSrcY, P1x, P2x, P1y, P2y, SrcDeltaSteps; |
embeddedartists | 0:a771927a62fd | 208 | |
embeddedartists | 0:a771927a62fd | 209 | //SrcStartX = SrcCoords_p[TopCoord].x; |
embeddedartists | 0:a771927a62fd | 210 | |
embeddedartists | 0:a771927a62fd | 211 | P1x = SrcCoords_p[TopCoord].x + ((i * dxSrcSmall)>>TRIANG_PROJ_SFT); |
embeddedartists | 0:a771927a62fd | 212 | P1y = SrcCoords_p[TopCoord].y + ((i * dySrcSmall)>>TRIANG_PROJ_SFT); |
embeddedartists | 0:a771927a62fd | 213 | P2x = SrcCoords_p[TopCoord].x + ((i * dxSrcBig)>>TRIANG_PROJ_SFT); |
embeddedartists | 0:a771927a62fd | 214 | P2y = SrcCoords_p[TopCoord].y + ((i * dySrcBig)>>TRIANG_PROJ_SFT); |
embeddedartists | 0:a771927a62fd | 215 | |
embeddedartists | 0:a771927a62fd | 216 | { |
embeddedartists | 0:a771927a62fd | 217 | int xx; |
embeddedartists | 0:a771927a62fd | 218 | |
embeddedartists | 0:a771927a62fd | 219 | x = DstCoords_p[TopCoord].x + ((i * dxDstSmall)>>TRIANG_PROJ_SFT); |
embeddedartists | 0:a771927a62fd | 220 | xx = DstCoords_p[TopCoord].x + ((i * dxDstBig) >>TRIANG_PROJ_SFT); |
embeddedartists | 0:a771927a62fd | 221 | |
embeddedartists | 0:a771927a62fd | 222 | SrcDeltaSteps = xx - x; |
embeddedartists | 0:a771927a62fd | 223 | if(SrcDeltaSteps < 0) |
embeddedartists | 0:a771927a62fd | 224 | SrcDeltaSteps = -SrcDeltaSteps; |
embeddedartists | 0:a771927a62fd | 225 | |
embeddedartists | 0:a771927a62fd | 226 | SrcDeltaSteps++; |
embeddedartists | 0:a771927a62fd | 227 | |
embeddedartists | 0:a771927a62fd | 228 | DivMultVal = ((int) DivTab[SrcDeltaSteps-1] + 1); |
embeddedartists | 0:a771927a62fd | 229 | |
embeddedartists | 0:a771927a62fd | 230 | MoveSrcX = (P2x - P1x) * DivMultVal; |
embeddedartists | 0:a771927a62fd | 231 | MoveSrcY = (P2y - P1y) * DivMultVal; |
embeddedartists | 0:a771927a62fd | 232 | |
embeddedartists | 0:a771927a62fd | 233 | x-= Direction; |
embeddedartists | 0:a771927a62fd | 234 | |
embeddedartists | 0:a771927a62fd | 235 | P1x <<= TRIANG_PROJ_SFT; |
embeddedartists | 0:a771927a62fd | 236 | P1y <<= TRIANG_PROJ_SFT; |
embeddedartists | 0:a771927a62fd | 237 | |
embeddedartists | 0:a771927a62fd | 238 | do |
embeddedartists | 0:a771927a62fd | 239 | { |
embeddedartists | 0:a771927a62fd | 240 | x+= Direction; |
embeddedartists | 0:a771927a62fd | 241 | |
embeddedartists | 0:a771927a62fd | 242 | CpPixel16Fast(P1x >>TRIANG_PROJ_SFT, P1y >>TRIANG_PROJ_SFT, x, y, SrcRP_p, DstRP_p); |
embeddedartists | 0:a771927a62fd | 243 | |
embeddedartists | 0:a771927a62fd | 244 | P1x += MoveSrcX; |
embeddedartists | 0:a771927a62fd | 245 | P1y += MoveSrcY; |
embeddedartists | 0:a771927a62fd | 246 | |
embeddedartists | 0:a771927a62fd | 247 | } while(x!=xx); |
embeddedartists | 0:a771927a62fd | 248 | } |
embeddedartists | 0:a771927a62fd | 249 | } |
embeddedartists | 0:a771927a62fd | 250 | |
embeddedartists | 0:a771927a62fd | 251 | /* second part of triangle from middle to bottom */ |
embeddedartists | 0:a771927a62fd | 252 | DeltaY = (long) DstCoords_p[BottomCoord].y - DstCoords_p[MiddleCoord].y+1; |
embeddedartists | 0:a771927a62fd | 253 | |
embeddedartists | 0:a771927a62fd | 254 | DivMultVal = ((int) DivTab[DeltaY-1] + 1); |
embeddedartists | 0:a771927a62fd | 255 | |
embeddedartists | 0:a771927a62fd | 256 | dxDstSmall = ((long) DstCoords_p[BottomCoord].x - DstCoords_p[MiddleCoord].x + 1) * DivMultVal; |
embeddedartists | 0:a771927a62fd | 257 | dySrcSmall = ((long) SrcCoords_p[BottomCoord].y - SrcCoords_p[MiddleCoord].y + 1) * DivMultVal; |
embeddedartists | 0:a771927a62fd | 258 | dxSrcSmall = ((long) SrcCoords_p[BottomCoord].x - SrcCoords_p[MiddleCoord].x + 1) * DivMultVal; |
embeddedartists | 0:a771927a62fd | 259 | |
embeddedartists | 0:a771927a62fd | 260 | y--; |
embeddedartists | 0:a771927a62fd | 261 | i--; |
embeddedartists | 0:a771927a62fd | 262 | |
embeddedartists | 0:a771927a62fd | 263 | for(j=0; y <= DstCoords_p[BottomCoord].y; y++, i++, j++) |
embeddedartists | 0:a771927a62fd | 264 | { /* for each row/line */ |
embeddedartists | 0:a771927a62fd | 265 | long MoveSrcX, MoveSrcY, P1x, P2x, P1y, P2y, SrcDeltaSteps; |
embeddedartists | 0:a771927a62fd | 266 | |
embeddedartists | 0:a771927a62fd | 267 | //SrcStartX = SrcCoords_p[MiddleCoord].x; |
embeddedartists | 0:a771927a62fd | 268 | |
embeddedartists | 0:a771927a62fd | 269 | P1x = SrcCoords_p[MiddleCoord].x + ((j * dxSrcSmall)>>TRIANG_PROJ_SFT); |
embeddedartists | 0:a771927a62fd | 270 | P1y = SrcCoords_p[MiddleCoord].y + ((j * dySrcSmall)>>TRIANG_PROJ_SFT); |
embeddedartists | 0:a771927a62fd | 271 | P2x = SrcCoords_p[TopCoord].x + ((i * dxSrcBig)>>TRIANG_PROJ_SFT); |
embeddedartists | 0:a771927a62fd | 272 | P2y = SrcCoords_p[TopCoord].y + ((i * dySrcBig)>>TRIANG_PROJ_SFT); |
embeddedartists | 0:a771927a62fd | 273 | |
embeddedartists | 0:a771927a62fd | 274 | { |
embeddedartists | 0:a771927a62fd | 275 | int xx; |
embeddedartists | 0:a771927a62fd | 276 | |
embeddedartists | 0:a771927a62fd | 277 | x = DstCoords_p[MiddleCoord].x + ((j * dxDstSmall)>>TRIANG_PROJ_SFT); |
embeddedartists | 0:a771927a62fd | 278 | xx = DstCoords_p[TopCoord].x + ((i * dxDstBig) >>TRIANG_PROJ_SFT); |
embeddedartists | 0:a771927a62fd | 279 | |
embeddedartists | 0:a771927a62fd | 280 | SrcDeltaSteps = xx - x; |
embeddedartists | 0:a771927a62fd | 281 | |
embeddedartists | 0:a771927a62fd | 282 | /* todo, fixme: direction should not have to be set here but if we do not |
embeddedartists | 0:a771927a62fd | 283 | do it here, sometimes calc fails, investigate (problem case: dst coords |
embeddedartists | 0:a771927a62fd | 284 | 250/299, 321/302, 472/308 and src coord 0/0, bike w-1, 0, bike w-1/bike h-1 */ |
embeddedartists | 0:a771927a62fd | 285 | if(SrcDeltaSteps < 0) |
embeddedartists | 0:a771927a62fd | 286 | { |
embeddedartists | 0:a771927a62fd | 287 | SrcDeltaSteps = -SrcDeltaSteps; |
embeddedartists | 0:a771927a62fd | 288 | Direction = -1; |
embeddedartists | 0:a771927a62fd | 289 | } |
embeddedartists | 0:a771927a62fd | 290 | else |
embeddedartists | 0:a771927a62fd | 291 | Direction = 1; |
embeddedartists | 0:a771927a62fd | 292 | |
embeddedartists | 0:a771927a62fd | 293 | SrcDeltaSteps++; |
embeddedartists | 0:a771927a62fd | 294 | |
embeddedartists | 0:a771927a62fd | 295 | DivMultVal = ((int) DivTab[SrcDeltaSteps-1] + 1); |
embeddedartists | 0:a771927a62fd | 296 | |
embeddedartists | 0:a771927a62fd | 297 | MoveSrcX = (P2x - P1x) * DivMultVal; |
embeddedartists | 0:a771927a62fd | 298 | MoveSrcY = (P2y - P1y) * DivMultVal; |
embeddedartists | 0:a771927a62fd | 299 | |
embeddedartists | 0:a771927a62fd | 300 | x-= Direction; |
embeddedartists | 0:a771927a62fd | 301 | |
embeddedartists | 0:a771927a62fd | 302 | P1x <<= TRIANG_PROJ_SFT; |
embeddedartists | 0:a771927a62fd | 303 | P1y <<= TRIANG_PROJ_SFT; |
embeddedartists | 0:a771927a62fd | 304 | |
embeddedartists | 0:a771927a62fd | 305 | do |
embeddedartists | 0:a771927a62fd | 306 | { |
embeddedartists | 0:a771927a62fd | 307 | x+= Direction; |
embeddedartists | 0:a771927a62fd | 308 | |
embeddedartists | 0:a771927a62fd | 309 | CpPixel16Fast(P1x >>TRIANG_PROJ_SFT, P1y >>TRIANG_PROJ_SFT, x, y, SrcRP_p, DstRP_p); |
embeddedartists | 0:a771927a62fd | 310 | |
embeddedartists | 0:a771927a62fd | 311 | P1x += MoveSrcX; |
embeddedartists | 0:a771927a62fd | 312 | P1y += MoveSrcY; |
embeddedartists | 0:a771927a62fd | 313 | |
embeddedartists | 0:a771927a62fd | 314 | } while(x!=xx); |
embeddedartists | 0:a771927a62fd | 315 | } |
embeddedartists | 0:a771927a62fd | 316 | } |
embeddedartists | 0:a771927a62fd | 317 | |
embeddedartists | 0:a771927a62fd | 318 | return; |
embeddedartists | 0:a771927a62fd | 319 | } |
embeddedartists | 0:a771927a62fd | 320 | |
embeddedartists | 0:a771927a62fd | 321 | |
embeddedartists | 0:a771927a62fd | 322 | short CubeDemo::_sin(short y) const { |
embeddedartists | 0:a771927a62fd | 323 | static short s1 = 0x6487; |
embeddedartists | 0:a771927a62fd | 324 | static short s3 = 0x2951; |
embeddedartists | 0:a771927a62fd | 325 | static short s5 = 0x4f6; |
embeddedartists | 0:a771927a62fd | 326 | long z, prod, sum; |
embeddedartists | 0:a771927a62fd | 327 | |
embeddedartists | 0:a771927a62fd | 328 | z = ((long)y * y) >> 12; |
embeddedartists | 0:a771927a62fd | 329 | prod = (z * s5) >> 16; |
embeddedartists | 0:a771927a62fd | 330 | sum = s3 - prod; |
embeddedartists | 0:a771927a62fd | 331 | prod = (z * sum) >> 16; |
embeddedartists | 0:a771927a62fd | 332 | sum = s1 - prod; |
embeddedartists | 0:a771927a62fd | 333 | |
embeddedartists | 0:a771927a62fd | 334 | // for better accuracy, round here |
embeddedartists | 0:a771927a62fd | 335 | return (short)((y * sum) >> 13); |
embeddedartists | 0:a771927a62fd | 336 | } |
embeddedartists | 0:a771927a62fd | 337 | |
embeddedartists | 0:a771927a62fd | 338 | short CubeDemo::_cos(short y) const { |
embeddedartists | 0:a771927a62fd | 339 | static short c0 = 0x7fff; |
embeddedartists | 0:a771927a62fd | 340 | static short c2 = 0x4eea; |
embeddedartists | 0:a771927a62fd | 341 | static short c4 = 0x0fc4; |
embeddedartists | 0:a771927a62fd | 342 | long z, prod, sum; |
embeddedartists | 0:a771927a62fd | 343 | z = ((long)y * y) >> 12; |
embeddedartists | 0:a771927a62fd | 344 | prod = (z * c4) >> 16; |
embeddedartists | 0:a771927a62fd | 345 | sum = c2 - prod; |
embeddedartists | 0:a771927a62fd | 346 | |
embeddedartists | 0:a771927a62fd | 347 | // for better accuracy, round here |
embeddedartists | 0:a771927a62fd | 348 | prod = (z * sum) >> 15; |
embeddedartists | 0:a771927a62fd | 349 | return (short)(c0 - prod); |
embeddedartists | 0:a771927a62fd | 350 | } |
embeddedartists | 0:a771927a62fd | 351 | |
embeddedartists | 0:a771927a62fd | 352 | short CubeDemo::isine(short x) const { |
embeddedartists | 0:a771927a62fd | 353 | unsigned short n = (((unsigned short)x + 0x2000) >> 14) & 0x3; |
embeddedartists | 0:a771927a62fd | 354 | x -= n * 0x4000; |
embeddedartists | 0:a771927a62fd | 355 | switch(n){ |
embeddedartists | 0:a771927a62fd | 356 | case 0: |
embeddedartists | 0:a771927a62fd | 357 | return _sin(x); |
embeddedartists | 0:a771927a62fd | 358 | case 1: |
embeddedartists | 0:a771927a62fd | 359 | return _cos(x); |
embeddedartists | 0:a771927a62fd | 360 | case 2: |
embeddedartists | 0:a771927a62fd | 361 | return - _sin(x); |
embeddedartists | 0:a771927a62fd | 362 | case 3: |
embeddedartists | 0:a771927a62fd | 363 | return - _cos(x); |
embeddedartists | 0:a771927a62fd | 364 | } |
embeddedartists | 0:a771927a62fd | 365 | return 0; |
embeddedartists | 0:a771927a62fd | 366 | } |
embeddedartists | 0:a771927a62fd | 367 | |
embeddedartists | 0:a771927a62fd | 368 | |
embeddedartists | 0:a771927a62fd | 369 | short CubeDemo::icosine(short x) const { |
embeddedartists | 0:a771927a62fd | 370 | return isine(x + 0x4000); |
embeddedartists | 0:a771927a62fd | 371 | } |
embeddedartists | 0:a771927a62fd | 372 | |
embeddedartists | 0:a771927a62fd | 373 | int32_t CubeDemo::sgn(int32_t val) const |
embeddedartists | 0:a771927a62fd | 374 | { |
embeddedartists | 0:a771927a62fd | 375 | if (val > 0) return 1; |
embeddedartists | 0:a771927a62fd | 376 | else if (val < 0) return -1; |
embeddedartists | 0:a771927a62fd | 377 | else return 0; |
embeddedartists | 0:a771927a62fd | 378 | } |
embeddedartists | 0:a771927a62fd | 379 | |
embeddedartists | 0:a771927a62fd | 380 | void CubeDemo::createCubeModel(uint32_t radius) |
embeddedartists | 0:a771927a62fd | 381 | { |
embeddedartists | 0:a771927a62fd | 382 | uint32_t i,j; |
embeddedartists | 0:a771927a62fd | 383 | uint32_t theta, dTheta; |
embeddedartists | 0:a771927a62fd | 384 | static uint8_t cubeConnect[24] = { |
embeddedartists | 0:a771927a62fd | 385 | 0, 1, 2, 3, |
embeddedartists | 0:a771927a62fd | 386 | 1, 5, 6, 2, |
embeddedartists | 0:a771927a62fd | 387 | 5, 4, 7, 6, |
embeddedartists | 0:a771927a62fd | 388 | 4, 0, 3, 7, |
embeddedartists | 0:a771927a62fd | 389 | 4, 5, 1, 0, |
embeddedartists | 0:a771927a62fd | 390 | 3, 2, 6, 7}; |
embeddedartists | 0:a771927a62fd | 391 | |
embeddedartists | 0:a771927a62fd | 392 | theta = 0x2000; //PI/4 |
embeddedartists | 0:a771927a62fd | 393 | dTheta = 0x4000; //PI/2 |
embeddedartists | 0:a771927a62fd | 394 | |
embeddedartists | 0:a771927a62fd | 395 | for(i=0; i<8; i++) |
embeddedartists | 0:a771927a62fd | 396 | { |
embeddedartists | 0:a771927a62fd | 397 | cubeModel[i].x = radius * sgn(icosine(theta)); |
embeddedartists | 0:a771927a62fd | 398 | cubeModel[i].y = radius * sgn(isine(theta)); |
embeddedartists | 0:a771927a62fd | 399 | cubeModel[i].z = radius - (2 * radius) * (i / 4); |
embeddedartists | 0:a771927a62fd | 400 | theta += dTheta; |
embeddedartists | 0:a771927a62fd | 401 | } |
embeddedartists | 0:a771927a62fd | 402 | |
embeddedartists | 0:a771927a62fd | 403 | j=0; |
embeddedartists | 0:a771927a62fd | 404 | for(i=0; i<6; i++) |
embeddedartists | 0:a771927a62fd | 405 | { |
embeddedartists | 0:a771927a62fd | 406 | cubePoly[j].p1 = cubeConnect[i*4 + 3]; |
embeddedartists | 0:a771927a62fd | 407 | cubePoly[j].p2 = cubeConnect[i*4 + 1]; |
embeddedartists | 0:a771927a62fd | 408 | cubePoly[j].p3 = cubeConnect[i*4 + 0]; |
embeddedartists | 0:a771927a62fd | 409 | j++; |
embeddedartists | 0:a771927a62fd | 410 | cubePoly[j].p1 = cubeConnect[i*4 + 3]; |
embeddedartists | 0:a771927a62fd | 411 | cubePoly[j].p2 = cubeConnect[i*4 + 2]; |
embeddedartists | 0:a771927a62fd | 412 | cubePoly[j].p3 = cubeConnect[i*4 + 1]; |
embeddedartists | 0:a771927a62fd | 413 | j++; |
embeddedartists | 0:a771927a62fd | 414 | } |
embeddedartists | 0:a771927a62fd | 415 | } |
embeddedartists | 0:a771927a62fd | 416 | |
embeddedartists | 0:a771927a62fd | 417 | void CubeDemo::rotateAndProject(uint16_t rotX, uint16_t rotY, uint16_t rotZ) |
embeddedartists | 0:a771927a62fd | 418 | { |
embeddedartists | 0:a771927a62fd | 419 | uint32_t i; |
embeddedartists | 0:a771927a62fd | 420 | long crx,srx,cry,sry,crz,srz; |
embeddedartists | 0:a771927a62fd | 421 | long x,y,z,tx,ty,tz; |
embeddedartists | 0:a771927a62fd | 422 | long distance; |
embeddedartists | 0:a771927a62fd | 423 | |
embeddedartists | 0:a771927a62fd | 424 | crx = icosine(rotX); |
embeddedartists | 0:a771927a62fd | 425 | srx = isine(rotX); |
embeddedartists | 0:a771927a62fd | 426 | cry = icosine(rotY); |
embeddedartists | 0:a771927a62fd | 427 | sry = isine(rotY); |
embeddedartists | 0:a771927a62fd | 428 | crz = icosine(rotZ); |
embeddedartists | 0:a771927a62fd | 429 | srz = isine(rotZ); |
embeddedartists | 0:a771927a62fd | 430 | |
embeddedartists | 0:a771927a62fd | 431 | for (i=0;i<8;i++) |
embeddedartists | 0:a771927a62fd | 432 | { |
embeddedartists | 0:a771927a62fd | 433 | //--> rotate around y-axis |
embeddedartists | 0:a771927a62fd | 434 | // var tempX = (this.x * Math.cos(rY)) - (this.z * Math.sin(rY)); |
embeddedartists | 0:a771927a62fd | 435 | // var tempZ = (this.x * Math.sin(rY)) + (this.z * Math.cos(rY)); |
embeddedartists | 0:a771927a62fd | 436 | |
embeddedartists | 0:a771927a62fd | 437 | //--> rotate around x-axis |
embeddedartists | 0:a771927a62fd | 438 | // this.dz = (tempZ * Math.cos(rX)) - (this.y * Math.sin(rX)); |
embeddedartists | 0:a771927a62fd | 439 | // var tempY = (tempZ * Math.sin(rX)) + (this.y * Math.cos(rX)); |
embeddedartists | 0:a771927a62fd | 440 | |
embeddedartists | 0:a771927a62fd | 441 | //--> rotate around z-axis |
embeddedartists | 0:a771927a62fd | 442 | // this.dx = (tempX * Math.cos(rZ)) + (tempY * Math.sin(rZ)); |
embeddedartists | 0:a771927a62fd | 443 | // this.dy = (tempY * Math.cos(rZ)) - (tempX * Math.sin(rZ)); |
embeddedartists | 0:a771927a62fd | 444 | |
embeddedartists | 0:a771927a62fd | 445 | |
embeddedartists | 0:a771927a62fd | 446 | x = cubeModel[i].x; |
embeddedartists | 0:a771927a62fd | 447 | y = cubeModel[i].y; |
embeddedartists | 0:a771927a62fd | 448 | z = cubeModel[i].z; |
embeddedartists | 0:a771927a62fd | 449 | |
embeddedartists | 0:a771927a62fd | 450 | //--> rotate around y-axis |
embeddedartists | 0:a771927a62fd | 451 | tx = (z*sry + x*cry) / 0x7fff; |
embeddedartists | 0:a771927a62fd | 452 | tz = (z*cry - x*sry) / 0x7fff; |
embeddedartists | 0:a771927a62fd | 453 | |
embeddedartists | 0:a771927a62fd | 454 | //--> rotate around x-axis |
embeddedartists | 0:a771927a62fd | 455 | cubeModel[i].zr = (y*srx + tz*crx) / 0x7fff; |
embeddedartists | 0:a771927a62fd | 456 | ty = (y*crx - tz*srx) / 0x7fff; |
embeddedartists | 0:a771927a62fd | 457 | |
embeddedartists | 0:a771927a62fd | 458 | //--> rotate around z-axis |
embeddedartists | 0:a771927a62fd | 459 | cubeModel[i].xr = (tx*crz - ty*srz) / 0x7fff; |
embeddedartists | 0:a771927a62fd | 460 | cubeModel[i].yr = (tx*srz + ty*crz) / 0x7fff; |
embeddedartists | 0:a771927a62fd | 461 | |
embeddedartists | 0:a771927a62fd | 462 | cubeModel[i].xr -= camX; |
embeddedartists | 0:a771927a62fd | 463 | cubeModel[i].yr -= camY; |
embeddedartists | 0:a771927a62fd | 464 | cubeModel[i].zr -= camZ; |
embeddedartists | 0:a771927a62fd | 465 | |
embeddedartists | 0:a771927a62fd | 466 | distance = LENS - cubeModel[i].zr; |
embeddedartists | 0:a771927a62fd | 467 | if (distance > 0) |
embeddedartists | 0:a771927a62fd | 468 | { |
embeddedartists | 0:a771927a62fd | 469 | cubeModel[i].scrx = X_OFFSET + (LENS * cubeModel[i].xr) / distance; |
embeddedartists | 0:a771927a62fd | 470 | cubeModel[i].scry = Y_OFFSET + (LENS * cubeModel[i].yr) / distance; |
embeddedartists | 0:a771927a62fd | 471 | } |
embeddedartists | 0:a771927a62fd | 472 | } |
embeddedartists | 0:a771927a62fd | 473 | } |
embeddedartists | 0:a771927a62fd | 474 | |
embeddedartists | 0:a771927a62fd | 475 | void CubeDemo::drawCubeZ(Surface_t *pSourcePicture, uint8_t shades) |
embeddedartists | 0:a771927a62fd | 476 | { |
embeddedartists | 0:a771927a62fd | 477 | uint32_t i; |
embeddedartists | 0:a771927a62fd | 478 | int32_t x1,x2,x3,y1,y2,y3,/*u1,u2,u3,v1,v2,v3,*/znormal; |
embeddedartists | 0:a771927a62fd | 479 | |
embeddedartists | 0:a771927a62fd | 480 | activeFrame.w = this->windowX; |
embeddedartists | 0:a771927a62fd | 481 | activeFrame.h = this->windowY; |
embeddedartists | 0:a771927a62fd | 482 | activeFrame.pixels = (uint16_t*)this->pFrmBuf; |
embeddedartists | 0:a771927a62fd | 483 | |
embeddedartists | 0:a771927a62fd | 484 | for(i=0; i<12; i++) |
embeddedartists | 0:a771927a62fd | 485 | { |
embeddedartists | 0:a771927a62fd | 486 | x1 = cubeModel[cubePoly[i].p1].scrx; //Get triangles from "projected" |
embeddedartists | 0:a771927a62fd | 487 | x2 = cubeModel[cubePoly[i].p2].scrx; //X and Y coords since Znormal |
embeddedartists | 0:a771927a62fd | 488 | x3 = cubeModel[cubePoly[i].p3].scrx; //Does not require a Z coord |
embeddedartists | 0:a771927a62fd | 489 | y1 = cubeModel[cubePoly[i].p1].scry; //V1= Point1 connected to V2 then |
embeddedartists | 0:a771927a62fd | 490 | y2 = cubeModel[cubePoly[i].p2].scry; //V2 to V3 and so on... |
embeddedartists | 0:a771927a62fd | 491 | y3 = cubeModel[cubePoly[i].p3].scry; |
embeddedartists | 0:a771927a62fd | 492 | |
embeddedartists | 0:a771927a62fd | 493 | znormal = (x2 - x1) * (y1 - y3) - (y2 - y1) * (x1 - x3); |
embeddedartists | 0:a771927a62fd | 494 | if (znormal > 0) |
embeddedartists | 0:a771927a62fd | 495 | { |
embeddedartists | 0:a771927a62fd | 496 | //no texture? |
embeddedartists | 0:a771927a62fd | 497 | if (pSourcePicture == NULL) |
embeddedartists | 0:a771927a62fd | 498 | { |
embeddedartists | 0:a771927a62fd | 499 | if (shades == 0) |
embeddedartists | 0:a771927a62fd | 500 | { |
embeddedartists | 0:a771927a62fd | 501 | if ((cubePoly[i].p1 == 0) && (cubePoly[i].p2 == 1)) |
embeddedartists | 0:a771927a62fd | 502 | graphics.put_line( cubeModel[cubePoly[i].p1].scrx, cubeModel[cubePoly[i].p1].scry, cubeModel[cubePoly[i].p2].scrx, cubeModel[cubePoly[i].p2].scry, RED); |
embeddedartists | 0:a771927a62fd | 503 | else |
embeddedartists | 0:a771927a62fd | 504 | graphics.put_line( cubeModel[cubePoly[i].p1].scrx, cubeModel[cubePoly[i].p1].scry, cubeModel[cubePoly[i].p2].scrx, cubeModel[cubePoly[i].p2].scry, SMALL_CIRCLE_FRONT_COLOR); |
embeddedartists | 0:a771927a62fd | 505 | graphics.put_line( cubeModel[cubePoly[i].p2].scrx, cubeModel[cubePoly[i].p2].scry, cubeModel[cubePoly[i].p3].scrx, cubeModel[cubePoly[i].p3].scry, SMALL_CIRCLE_FRONT_COLOR); |
embeddedartists | 0:a771927a62fd | 506 | graphics.put_line( cubeModel[cubePoly[i].p3].scrx, cubeModel[cubePoly[i].p3].scry, cubeModel[cubePoly[i].p1].scrx, cubeModel[cubePoly[i].p1].scry, SMALL_CIRCLE_FRONT_COLOR); |
embeddedartists | 0:a771927a62fd | 507 | } |
embeddedartists | 0:a771927a62fd | 508 | else |
embeddedartists | 0:a771927a62fd | 509 | { |
embeddedartists | 0:a771927a62fd | 510 | Coord2D_t SrcCoords[3], DstCoords[3]; |
embeddedartists | 0:a771927a62fd | 511 | Surface_t a; |
embeddedartists | 0:a771927a62fd | 512 | static uint16_t pix; |
embeddedartists | 0:a771927a62fd | 513 | |
embeddedartists | 0:a771927a62fd | 514 | a.w = this->windowX; |
embeddedartists | 0:a771927a62fd | 515 | a.h = this->windowY; |
embeddedartists | 0:a771927a62fd | 516 | a.pixels = &pix; |
embeddedartists | 0:a771927a62fd | 517 | if ((i&1) == 0) |
embeddedartists | 0:a771927a62fd | 518 | { |
embeddedartists | 0:a771927a62fd | 519 | if ((znormal / 400) > 31) |
embeddedartists | 0:a771927a62fd | 520 | pix = 0x1f << 11; |
embeddedartists | 0:a771927a62fd | 521 | else |
embeddedartists | 0:a771927a62fd | 522 | pix = (znormal / 400 & 0x1f) << 11; |
embeddedartists | 0:a771927a62fd | 523 | } |
embeddedartists | 0:a771927a62fd | 524 | SrcCoords[0].x = 0; |
embeddedartists | 0:a771927a62fd | 525 | SrcCoords[0].y = 0; |
embeddedartists | 0:a771927a62fd | 526 | SrcCoords[1].x = 0; |
embeddedartists | 0:a771927a62fd | 527 | SrcCoords[1].y = 0; |
embeddedartists | 0:a771927a62fd | 528 | SrcCoords[2].x = 0; |
embeddedartists | 0:a771927a62fd | 529 | SrcCoords[2].y = 0; |
embeddedartists | 0:a771927a62fd | 530 | DstCoords[0].x = cubeModel[cubePoly[i].p1].scrx; |
embeddedartists | 0:a771927a62fd | 531 | DstCoords[0].y = cubeModel[cubePoly[i].p1].scry; |
embeddedartists | 0:a771927a62fd | 532 | DstCoords[1].x = cubeModel[cubePoly[i].p2].scrx; |
embeddedartists | 0:a771927a62fd | 533 | DstCoords[1].y = cubeModel[cubePoly[i].p2].scry; |
embeddedartists | 0:a771927a62fd | 534 | DstCoords[2].x = cubeModel[cubePoly[i].p3].scrx; |
embeddedartists | 0:a771927a62fd | 535 | DstCoords[2].y = cubeModel[cubePoly[i].p3].scry; |
embeddedartists | 0:a771927a62fd | 536 | TriangleProjectFast(&a, &activeFrame, SrcCoords, DstCoords); |
embeddedartists | 0:a771927a62fd | 537 | } |
embeddedartists | 0:a771927a62fd | 538 | } |
embeddedartists | 0:a771927a62fd | 539 | |
embeddedartists | 0:a771927a62fd | 540 | //Render with texture |
embeddedartists | 0:a771927a62fd | 541 | else |
embeddedartists | 0:a771927a62fd | 542 | { |
embeddedartists | 0:a771927a62fd | 543 | Coord2D_t SrcCoords[3], DstCoords[3]; |
embeddedartists | 0:a771927a62fd | 544 | #if 1 |
embeddedartists | 0:a771927a62fd | 545 | /* |
embeddedartists | 0:a771927a62fd | 546 | * Image in the file |
embeddedartists | 0:a771927a62fd | 547 | * 0,0_______ _______ _______ |
embeddedartists | 0:a771927a62fd | 548 | * | | | *| |
embeddedartists | 0:a771927a62fd | 549 | * | | | | Image as it is used |
embeddedartists | 0:a771927a62fd | 550 | * |_______|_______|_______| _______ _______ _______ _______ |
embeddedartists | 0:a771927a62fd | 551 | * | | | | \ |* | | | | |
embeddedartists | 0:a771927a62fd | 552 | * | | | | \ | | top | | | |
embeddedartists | 0:a771927a62fd | 553 | * |_______|_______|_______| ====== |_______|_______|_______|_______| |
embeddedartists | 0:a771927a62fd | 554 | * | | | | / | | | | | |
embeddedartists | 0:a771927a62fd | 555 | * | | | | / | side1 | side2 | side3 | side4 | |
embeddedartists | 0:a771927a62fd | 556 | * |_______|_______|_______| |_______|_______|_______|_______| |
embeddedartists | 0:a771927a62fd | 557 | * | | | | | | | | | |
embeddedartists | 0:a771927a62fd | 558 | * | | | | | | bottom| | | |
embeddedartists | 0:a771927a62fd | 559 | * |_______|_______|_______| |_______|_______|_______|_______| |
embeddedartists | 0:a771927a62fd | 560 | * 150,200 |
embeddedartists | 0:a771927a62fd | 561 | * All coordinates below are in the left image above and with coordinates 0,0 in the |
embeddedartists | 0:a771927a62fd | 562 | * upper left corner and 150,200 in the lower right corner. |
embeddedartists | 0:a771927a62fd | 563 | * |
embeddedartists | 0:a771927a62fd | 564 | */ |
embeddedartists | 0:a771927a62fd | 565 | #define XYZ {49,0},{0,0},{0,50},{50,50} |
embeddedartists | 0:a771927a62fd | 566 | static Coord2D_t a[24] = {{49,50}, {0,50}, {0,99}, {49,99}, //bottom 6 |
embeddedartists | 0:a771927a62fd | 567 | {99,50}, {50,50}, {50,99}, {99,99}, //side2 2 |
embeddedartists | 0:a771927a62fd | 568 | {149,50},{100,50},{100,99},{149,99}, //top 5 |
embeddedartists | 0:a771927a62fd | 569 | {50,150},{99,150},{99,199},{50,199}, //side4 4 |
embeddedartists | 0:a771927a62fd | 570 | {99,49}, {99,0}, {50,0}, {50,49}, //side1 1 |
embeddedartists | 0:a771927a62fd | 571 | {99,100},{99,149},{50,149},{50,100}}; //side3 3 |
embeddedartists | 0:a771927a62fd | 572 | #elif 0 |
embeddedartists | 0:a771927a62fd | 573 | static Coord2D_t a[24] = {{49,50}, {0,50}, {0,99}, {49,99}, //bottom 6 |
embeddedartists | 0:a771927a62fd | 574 | {99,50}, {50,50}, {50,99}, {99,99}, //side2 2 |
embeddedartists | 0:a771927a62fd | 575 | {149,50},{100,50},{100,99},{149,99}, //top 5 |
embeddedartists | 0:a771927a62fd | 576 | {99,150},{50,150},{50,199},{99,199}, //side4 4 |
embeddedartists | 0:a771927a62fd | 577 | {99,49}, {99,0}, {50,0}, {50,49}, //side1 1 |
embeddedartists | 0:a771927a62fd | 578 | {99,149},{99,100},{50,100},{50,149}}; //side3 3 |
embeddedartists | 0:a771927a62fd | 579 | #else |
embeddedartists | 0:a771927a62fd | 580 | static Coord2D_t a[24] = {{49,50}, {0,50}, {0,99}, {49,99}, |
embeddedartists | 0:a771927a62fd | 581 | {99,50}, {50,50}, {50,99}, {99,99}, |
embeddedartists | 0:a771927a62fd | 582 | {149,50},{100,50},{100,99},{149,99}, |
embeddedartists | 0:a771927a62fd | 583 | {99,199},{50,199},{50,150},{99,150}, |
embeddedartists | 0:a771927a62fd | 584 | {50,0}, {99,0}, {99,49}, {50,49}, //top |
embeddedartists | 0:a771927a62fd | 585 | {50,100},{99,100},{99,149},{50,149}};//bottom |
embeddedartists | 0:a771927a62fd | 586 | #endif |
embeddedartists | 0:a771927a62fd | 587 | |
embeddedartists | 0:a771927a62fd | 588 | if (i&1) |
embeddedartists | 0:a771927a62fd | 589 | { |
embeddedartists | 0:a771927a62fd | 590 | SrcCoords[0].x = a[(i/2)*4+2].x; |
embeddedartists | 0:a771927a62fd | 591 | SrcCoords[0].y = a[(i/2)*4+2].y; |
embeddedartists | 0:a771927a62fd | 592 | SrcCoords[1].x = a[(i/2)*4+3].x; |
embeddedartists | 0:a771927a62fd | 593 | SrcCoords[1].y = a[(i/2)*4+3].y; |
embeddedartists | 0:a771927a62fd | 594 | SrcCoords[2].x = a[(i/2)*4+0].x; |
embeddedartists | 0:a771927a62fd | 595 | SrcCoords[2].y = a[(i/2)*4+0].y; |
embeddedartists | 0:a771927a62fd | 596 | DstCoords[0].x = cubeModel[cubePoly[i].p1].scrx; |
embeddedartists | 0:a771927a62fd | 597 | DstCoords[0].y = cubeModel[cubePoly[i].p1].scry; |
embeddedartists | 0:a771927a62fd | 598 | DstCoords[1].x = cubeModel[cubePoly[i].p2].scrx; |
embeddedartists | 0:a771927a62fd | 599 | DstCoords[1].y = cubeModel[cubePoly[i].p2].scry; |
embeddedartists | 0:a771927a62fd | 600 | DstCoords[2].x = cubeModel[cubePoly[i].p3].scrx; |
embeddedartists | 0:a771927a62fd | 601 | DstCoords[2].y = cubeModel[cubePoly[i].p3].scry; |
embeddedartists | 0:a771927a62fd | 602 | TriangleProjectFast(pSourcePicture, &activeFrame, SrcCoords, DstCoords); |
embeddedartists | 0:a771927a62fd | 603 | } |
embeddedartists | 0:a771927a62fd | 604 | else |
embeddedartists | 0:a771927a62fd | 605 | { |
embeddedartists | 0:a771927a62fd | 606 | SrcCoords[0].x = a[(i/2)*4+0].x; //0 |
embeddedartists | 0:a771927a62fd | 607 | SrcCoords[0].y = a[(i/2)*4+0].y; //0 |
embeddedartists | 0:a771927a62fd | 608 | SrcCoords[1].x = a[(i/2)*4+1].x; //31; |
embeddedartists | 0:a771927a62fd | 609 | SrcCoords[1].y = a[(i/2)*4+1].y; //0; |
embeddedartists | 0:a771927a62fd | 610 | SrcCoords[2].x = a[(i/2)*4+2].x; //31; |
embeddedartists | 0:a771927a62fd | 611 | SrcCoords[2].y = a[(i/2)*4+2].y; //31; |
embeddedartists | 0:a771927a62fd | 612 | DstCoords[0].x = cubeModel[cubePoly[i].p2].scrx; |
embeddedartists | 0:a771927a62fd | 613 | DstCoords[0].y = cubeModel[cubePoly[i].p2].scry; |
embeddedartists | 0:a771927a62fd | 614 | DstCoords[1].x = cubeModel[cubePoly[i].p3].scrx; |
embeddedartists | 0:a771927a62fd | 615 | DstCoords[1].y = cubeModel[cubePoly[i].p3].scry; |
embeddedartists | 0:a771927a62fd | 616 | DstCoords[2].x = cubeModel[cubePoly[i].p1].scrx; |
embeddedartists | 0:a771927a62fd | 617 | DstCoords[2].y = cubeModel[cubePoly[i].p1].scry; |
embeddedartists | 0:a771927a62fd | 618 | TriangleProjectFast(pSourcePicture, &activeFrame, SrcCoords, DstCoords); |
embeddedartists | 0:a771927a62fd | 619 | } |
embeddedartists | 0:a771927a62fd | 620 | } |
embeddedartists | 0:a771927a62fd | 621 | } |
embeddedartists | 0:a771927a62fd | 622 | } |
embeddedartists | 0:a771927a62fd | 623 | } |
embeddedartists | 0:a771927a62fd | 624 | |
embeddedartists | 0:a771927a62fd | 625 | void CubeDemo::render(uint32_t idx) |
embeddedartists | 0:a771927a62fd | 626 | { |
embeddedartists | 0:a771927a62fd | 627 | static uint8_t cnt=0; |
embeddedartists | 0:a771927a62fd | 628 | |
embeddedartists | 0:a771927a62fd | 629 | if (cnt == 0) |
embeddedartists | 0:a771927a62fd | 630 | { |
embeddedartists | 0:a771927a62fd | 631 | cnt = 1; |
embeddedartists | 0:a771927a62fd | 632 | pFrmBuf = pFrmBuf1; |
embeddedartists | 0:a771927a62fd | 633 | } |
embeddedartists | 0:a771927a62fd | 634 | else if (cnt == 1) |
embeddedartists | 0:a771927a62fd | 635 | { |
embeddedartists | 0:a771927a62fd | 636 | cnt = 2; |
embeddedartists | 0:a771927a62fd | 637 | pFrmBuf = pFrmBuf2; |
embeddedartists | 0:a771927a62fd | 638 | } |
embeddedartists | 0:a771927a62fd | 639 | else |
embeddedartists | 0:a771927a62fd | 640 | { |
embeddedartists | 0:a771927a62fd | 641 | cnt = 0; |
embeddedartists | 0:a771927a62fd | 642 | pFrmBuf = pFrmBuf3; |
embeddedartists | 0:a771927a62fd | 643 | } |
embeddedartists | 0:a771927a62fd | 644 | |
embeddedartists | 0:a771927a62fd | 645 | graphics.setFrameBuffer(pFrmBuf); |
embeddedartists | 0:a771927a62fd | 646 | |
embeddedartists | 0:a771927a62fd | 647 | // rendering here |
embeddedartists | 0:a771927a62fd | 648 | memset((void*)(pFrmBuf), BACKGROUND_COLOR, this->windowX * this->windowY * 2); |
embeddedartists | 0:a771927a62fd | 649 | |
embeddedartists | 0:a771927a62fd | 650 | rotateAndProject(rx, ry, 0); |
embeddedartists | 0:a771927a62fd | 651 | |
embeddedartists | 0:a771927a62fd | 652 | switch(mode) |
embeddedartists | 0:a771927a62fd | 653 | { |
embeddedartists | 0:a771927a62fd | 654 | case 0: //draw just points |
embeddedartists | 0:a771927a62fd | 655 | graphics.put_circle( cubeModel[0].scrx, cubeModel[0].scry, RED, 2, 1); |
embeddedartists | 0:a771927a62fd | 656 | graphics.put_circle( cubeModel[1].scrx, cubeModel[1].scry, SMALL_CIRCLE_FRONT_COLOR, 2, 1); |
embeddedartists | 0:a771927a62fd | 657 | graphics.put_circle( cubeModel[2].scrx, cubeModel[2].scry, GREEN, 2, 1); |
embeddedartists | 0:a771927a62fd | 658 | graphics.put_circle( cubeModel[3].scrx, cubeModel[3].scry, SMALL_CIRCLE_FRONT_COLOR, 2, 1); |
embeddedartists | 0:a771927a62fd | 659 | graphics.put_circle( cubeModel[4].scrx, cubeModel[4].scry, SMALL_CIRCLE_FRONT_COLOR, 2, 1); |
embeddedartists | 0:a771927a62fd | 660 | graphics.put_circle( cubeModel[5].scrx, cubeModel[5].scry, SMALL_CIRCLE_FRONT_COLOR, 2, 1); |
embeddedartists | 0:a771927a62fd | 661 | graphics.put_circle( cubeModel[6].scrx, cubeModel[6].scry, SMALL_CIRCLE_FRONT_COLOR, 2, 1); |
embeddedartists | 0:a771927a62fd | 662 | graphics.put_circle( cubeModel[7].scrx, cubeModel[7].scry, SMALL_CIRCLE_FRONT_COLOR, 2, 1); |
embeddedartists | 0:a771927a62fd | 663 | break; |
embeddedartists | 0:a771927a62fd | 664 | case 1: //draw lines points |
embeddedartists | 0:a771927a62fd | 665 | graphics.put_line( cubeModel[0].scrx, cubeModel[0].scry, cubeModel[1].scrx, cubeModel[1].scry, RED); |
embeddedartists | 0:a771927a62fd | 666 | graphics.put_line( cubeModel[1].scrx, cubeModel[1].scry, cubeModel[2].scrx, cubeModel[2].scry, SMALL_CIRCLE_FRONT_COLOR); |
embeddedartists | 0:a771927a62fd | 667 | graphics.put_line( cubeModel[2].scrx, cubeModel[2].scry, cubeModel[3].scrx, cubeModel[3].scry, GREEN); |
embeddedartists | 0:a771927a62fd | 668 | graphics.put_line( cubeModel[3].scrx, cubeModel[3].scry, cubeModel[0].scrx, cubeModel[0].scry, SMALL_CIRCLE_FRONT_COLOR); |
embeddedartists | 0:a771927a62fd | 669 | |
embeddedartists | 0:a771927a62fd | 670 | graphics.put_line( cubeModel[5].scrx, cubeModel[5].scry, cubeModel[4].scrx, cubeModel[4].scry, SMALL_CIRCLE_FRONT_COLOR); |
embeddedartists | 0:a771927a62fd | 671 | graphics.put_line( cubeModel[4].scrx, cubeModel[4].scry, cubeModel[7].scrx, cubeModel[7].scry, SMALL_CIRCLE_FRONT_COLOR); |
embeddedartists | 0:a771927a62fd | 672 | graphics.put_line( cubeModel[7].scrx, cubeModel[7].scry, cubeModel[6].scrx, cubeModel[6].scry, SMALL_CIRCLE_FRONT_COLOR); |
embeddedartists | 0:a771927a62fd | 673 | graphics.put_line( cubeModel[6].scrx, cubeModel[6].scry, cubeModel[5].scrx, cubeModel[5].scry, SMALL_CIRCLE_FRONT_COLOR); |
embeddedartists | 0:a771927a62fd | 674 | |
embeddedartists | 0:a771927a62fd | 675 | graphics.put_line( cubeModel[0].scrx, cubeModel[0].scry, cubeModel[4].scrx, cubeModel[4].scry, SMALL_CIRCLE_FRONT_COLOR); |
embeddedartists | 0:a771927a62fd | 676 | graphics.put_line( cubeModel[1].scrx, cubeModel[1].scry, cubeModel[5].scrx, cubeModel[5].scry, SMALL_CIRCLE_FRONT_COLOR); |
embeddedartists | 0:a771927a62fd | 677 | graphics.put_line( cubeModel[2].scrx, cubeModel[2].scry, cubeModel[6].scrx, cubeModel[6].scry, SMALL_CIRCLE_FRONT_COLOR); |
embeddedartists | 0:a771927a62fd | 678 | graphics.put_line( cubeModel[3].scrx, cubeModel[3].scry, cubeModel[7].scrx, cubeModel[7].scry, SMALL_CIRCLE_FRONT_COLOR); |
embeddedartists | 0:a771927a62fd | 679 | break; |
embeddedartists | 0:a771927a62fd | 680 | case 2: //draw cube with texture |
embeddedartists | 0:a771927a62fd | 681 | if (sourcePicture1.pixels == NULL) |
embeddedartists | 0:a771927a62fd | 682 | { |
embeddedartists | 0:a771927a62fd | 683 | drawCubeZ( NULL, false); |
embeddedartists | 0:a771927a62fd | 684 | } |
embeddedartists | 0:a771927a62fd | 685 | else |
embeddedartists | 0:a771927a62fd | 686 | { |
embeddedartists | 0:a771927a62fd | 687 | drawCubeZ( &sourcePicture1, false); |
embeddedartists | 0:a771927a62fd | 688 | } |
embeddedartists | 0:a771927a62fd | 689 | break; |
embeddedartists | 0:a771927a62fd | 690 | case 3: //draw cube with texture |
embeddedartists | 0:a771927a62fd | 691 | drawCubeZ( NULL, true); |
embeddedartists | 0:a771927a62fd | 692 | break; |
embeddedartists | 0:a771927a62fd | 693 | case 4: //draw cube with texture |
embeddedartists | 0:a771927a62fd | 694 | if (sourcePicture2.pixels == NULL) |
embeddedartists | 0:a771927a62fd | 695 | { |
embeddedartists | 0:a771927a62fd | 696 | drawCubeZ( NULL, false); |
embeddedartists | 0:a771927a62fd | 697 | } |
embeddedartists | 0:a771927a62fd | 698 | else |
embeddedartists | 0:a771927a62fd | 699 | { |
embeddedartists | 0:a771927a62fd | 700 | drawCubeZ( &sourcePicture2, false); |
embeddedartists | 0:a771927a62fd | 701 | } |
embeddedartists | 0:a771927a62fd | 702 | break; |
embeddedartists | 0:a771927a62fd | 703 | case 5: //draw sorted lines |
embeddedartists | 0:a771927a62fd | 704 | drawCubeZ( NULL, false); |
embeddedartists | 0:a771927a62fd | 705 | break; |
embeddedartists | 0:a771927a62fd | 706 | default: |
embeddedartists | 0:a771927a62fd | 707 | mode = 0; |
embeddedartists | 0:a771927a62fd | 708 | break; |
embeddedartists | 0:a771927a62fd | 709 | } |
embeddedartists | 0:a771927a62fd | 710 | ry += ry_; |
embeddedartists | 0:a771927a62fd | 711 | rx += rx_; |
embeddedartists | 0:a771927a62fd | 712 | } |
embeddedartists | 0:a771927a62fd | 713 | |
embeddedartists | 0:a771927a62fd | 714 | /*********************************************************************** |
embeddedartists | 0:a771927a62fd | 715 | * Private functions |
embeddedartists | 0:a771927a62fd | 716 | **********************************************************************/ |
embeddedartists | 0:a771927a62fd | 717 | |
embeddedartists | 0:a771927a62fd | 718 | void CubeDemo::initialize() |
embeddedartists | 0:a771927a62fd | 719 | { |
embeddedartists | 0:a771927a62fd | 720 | mode = 3; |
embeddedartists | 0:a771927a62fd | 721 | rx = 0x9000; |
embeddedartists | 0:a771927a62fd | 722 | ry = 0; |
embeddedartists | 0:a771927a62fd | 723 | ry_ = 350; |
embeddedartists | 0:a771927a62fd | 724 | rx_ = -25; //-3 |
embeddedartists | 0:a771927a62fd | 725 | camX = 0; |
embeddedartists | 0:a771927a62fd | 726 | camY = 0; |
embeddedartists | 0:a771927a62fd | 727 | camZ = 128; |
embeddedartists | 0:a771927a62fd | 728 | |
embeddedartists | 0:a771927a62fd | 729 | createCubeModel(70); |
embeddedartists | 0:a771927a62fd | 730 | |
embeddedartists | 0:a771927a62fd | 731 | Image::ImageData_t d; |
embeddedartists | 0:a771927a62fd | 732 | if (Image::decode(cube_image1, cube_image1_sz, &d) == 0) { |
embeddedartists | 0:a771927a62fd | 733 | sourcePicture1.w = d.width; |
embeddedartists | 0:a771927a62fd | 734 | sourcePicture1.h = d.height; |
embeddedartists | 0:a771927a62fd | 735 | sourcePicture1.pixels = d.pixels; |
embeddedartists | 0:a771927a62fd | 736 | } |
embeddedartists | 0:a771927a62fd | 737 | if (Image::decode(cube_image2, cube_image2_sz, &d) == 0) { |
embeddedartists | 0:a771927a62fd | 738 | sourcePicture2.w = d.width; |
embeddedartists | 0:a771927a62fd | 739 | sourcePicture2.h = d.height; |
embeddedartists | 0:a771927a62fd | 740 | sourcePicture2.pixels = d.pixels; |
embeddedartists | 0:a771927a62fd | 741 | } |
embeddedartists | 0:a771927a62fd | 742 | } |
embeddedartists | 0:a771927a62fd | 743 | |
embeddedartists | 0:a771927a62fd | 744 | |
embeddedartists | 0:a771927a62fd | 745 | /****************************************************************************** |
embeddedartists | 0:a771927a62fd | 746 | * Public functions |
embeddedartists | 0:a771927a62fd | 747 | *****************************************************************************/ |
embeddedartists | 0:a771927a62fd | 748 | CubeDemo::CubeDemo(uint8_t *pFrameBuf, uint16_t dispWidth, uint16_t dispHeight) |
embeddedartists | 0:a771927a62fd | 749 | : graphics((uint16_t *)pFrameBuf, dispWidth, dispHeight) { |
embeddedartists | 0:a771927a62fd | 750 | |
embeddedartists | 0:a771927a62fd | 751 | this->windowX = dispWidth; |
embeddedartists | 0:a771927a62fd | 752 | this->windowY = dispHeight; |
embeddedartists | 0:a771927a62fd | 753 | this->pFrmBuf = (uint16_t *)pFrameBuf; |
embeddedartists | 0:a771927a62fd | 754 | this->pFrmBuf1 = (uint16_t *)pFrameBuf; |
embeddedartists | 0:a771927a62fd | 755 | this->pFrmBuf2 = (uint16_t *)((uint32_t)pFrameBuf + dispWidth*dispHeight*2); |
embeddedartists | 0:a771927a62fd | 756 | this->pFrmBuf3 = (uint16_t *)((uint32_t)pFrameBuf + dispWidth*dispHeight*4); |
embeddedartists | 0:a771927a62fd | 757 | |
embeddedartists | 0:a771927a62fd | 758 | sourcePicture1.w = 0; |
embeddedartists | 0:a771927a62fd | 759 | sourcePicture1.h = 0; |
embeddedartists | 0:a771927a62fd | 760 | sourcePicture1.pixels = NULL; |
embeddedartists | 0:a771927a62fd | 761 | sourcePicture2.w = 0; |
embeddedartists | 0:a771927a62fd | 762 | sourcePicture2.h = 0; |
embeddedartists | 0:a771927a62fd | 763 | sourcePicture2.pixels = NULL; |
embeddedartists | 0:a771927a62fd | 764 | |
embeddedartists | 0:a771927a62fd | 765 | initialize(); |
embeddedartists | 0:a771927a62fd | 766 | } |
embeddedartists | 0:a771927a62fd | 767 | |
embeddedartists | 0:a771927a62fd | 768 | CubeDemo::~CubeDemo() |
embeddedartists | 0:a771927a62fd | 769 | { |
embeddedartists | 0:a771927a62fd | 770 | if (sourcePicture1.pixels != NULL) { |
embeddedartists | 0:a771927a62fd | 771 | free(sourcePicture1.pixels); |
embeddedartists | 0:a771927a62fd | 772 | } |
embeddedartists | 0:a771927a62fd | 773 | if (sourcePicture2.pixels != NULL) { |
embeddedartists | 0:a771927a62fd | 774 | free(sourcePicture2.pixels); |
embeddedartists | 0:a771927a62fd | 775 | } |
embeddedartists | 0:a771927a62fd | 776 | } |
embeddedartists | 0:a771927a62fd | 777 | void CubeDemo::run(uint32_t loops, uint32_t delayMs) { |
embeddedartists | 0:a771927a62fd | 778 | |
embeddedartists | 0:a771927a62fd | 779 | printf("CubeDemo, %d loops, %dms delay\n", loops, delayMs); |
embeddedartists | 0:a771927a62fd | 780 | |
embeddedartists | 0:a771927a62fd | 781 | for(int32_t n=0;n<loops;n++) { |
embeddedartists | 0:a771927a62fd | 782 | |
embeddedartists | 0:a771927a62fd | 783 | mode = ((n/128) % 5); |
embeddedartists | 0:a771927a62fd | 784 | //mode = 4; |
embeddedartists | 0:a771927a62fd | 785 | |
embeddedartists | 0:a771927a62fd | 786 | //render globe |
embeddedartists | 0:a771927a62fd | 787 | render(n); |
embeddedartists | 0:a771927a62fd | 788 | |
embeddedartists | 0:a771927a62fd | 789 | //update framebuffer |
embeddedartists | 0:a771927a62fd | 790 | lcdBoard.setFrameBuffer((uint32_t)this->pFrmBuf); |
embeddedartists | 0:a771927a62fd | 791 | |
embeddedartists | 0:a771927a62fd | 792 | if (abortTest) { |
embeddedartists | 0:a771927a62fd | 793 | break; |
embeddedartists | 0:a771927a62fd | 794 | } |
embeddedartists | 0:a771927a62fd | 795 | |
embeddedartists | 0:a771927a62fd | 796 | if (mode == 3) |
embeddedartists | 0:a771927a62fd | 797 | wait_ms(delayMs-7); |
embeddedartists | 0:a771927a62fd | 798 | else |
embeddedartists | 0:a771927a62fd | 799 | wait_ms(delayMs); |
embeddedartists | 0:a771927a62fd | 800 | } |
embeddedartists | 0:a771927a62fd | 801 | } |
embeddedartists | 0:a771927a62fd | 802 |