![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Graphical demo for the LPC4088 Experiment Base Board with one of the Display Expansion Kits. This demo shows a rotating 3D cube with and without textures.
CubeDemo.h@0:c828045bbe69, 2014-10-03 (annotated)
- Committer:
- embeddedartists
- Date:
- Fri Oct 03 12:48:37 2014 +0000
- Revision:
- 0:c828045bbe69
First version.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
embeddedartists | 0:c828045bbe69 | 1 | |
embeddedartists | 0:c828045bbe69 | 2 | #ifndef CUBEDEMO_H |
embeddedartists | 0:c828045bbe69 | 3 | #define CUBEDEMO_H |
embeddedartists | 0:c828045bbe69 | 4 | |
embeddedartists | 0:c828045bbe69 | 5 | #include "Graphics.h" |
embeddedartists | 0:c828045bbe69 | 6 | #include "GFXFb.h" |
embeddedartists | 0:c828045bbe69 | 7 | |
embeddedartists | 0:c828045bbe69 | 8 | #include "EaLcdBoardGPIO.h" |
embeddedartists | 0:c828045bbe69 | 9 | |
embeddedartists | 0:c828045bbe69 | 10 | class CubeDemo { |
embeddedartists | 0:c828045bbe69 | 11 | public: |
embeddedartists | 0:c828045bbe69 | 12 | |
embeddedartists | 0:c828045bbe69 | 13 | /** Set the address of the frame buffer to use. |
embeddedartists | 0:c828045bbe69 | 14 | * |
embeddedartists | 0:c828045bbe69 | 15 | * It is the content of the frame buffer that is shown on the |
embeddedartists | 0:c828045bbe69 | 16 | * display. All the drawing on the frame buffer can be done |
embeddedartists | 0:c828045bbe69 | 17 | * 'offline' and whenever it should be shown this function |
embeddedartists | 0:c828045bbe69 | 18 | * can be called with the address of the offline frame buffer. |
embeddedartists | 0:c828045bbe69 | 19 | * |
embeddedartists | 0:c828045bbe69 | 20 | * @param pFrameBuf Pointer to the frame buffer, which must be |
embeddedartists | 0:c828045bbe69 | 21 | * 3 times as big as the frame size (for tripple |
embeddedartists | 0:c828045bbe69 | 22 | * buffering). |
embeddedartists | 0:c828045bbe69 | 23 | * dispWidth The width of the display (in pixels). |
embeddedartists | 0:c828045bbe69 | 24 | * dispHeight The height of the display (in pixels). |
embeddedartists | 0:c828045bbe69 | 25 | * loops Number of loops in the demo code. |
embeddedartists | 0:c828045bbe69 | 26 | * delayMs Delay in milliseconds between schreen updates. |
embeddedartists | 0:c828045bbe69 | 27 | * |
embeddedartists | 0:c828045bbe69 | 28 | * @returns |
embeddedartists | 0:c828045bbe69 | 29 | * none |
embeddedartists | 0:c828045bbe69 | 30 | */ |
embeddedartists | 0:c828045bbe69 | 31 | CubeDemo(uint8_t *pFrameBuf, uint16_t dispWidth, uint16_t dispHeight); |
embeddedartists | 0:c828045bbe69 | 32 | ~CubeDemo(); |
embeddedartists | 0:c828045bbe69 | 33 | |
embeddedartists | 0:c828045bbe69 | 34 | void run(EaLcdBoardGPIO& lcdBoard, uint32_t loops, uint32_t delayMs); |
embeddedartists | 0:c828045bbe69 | 35 | |
embeddedartists | 0:c828045bbe69 | 36 | |
embeddedartists | 0:c828045bbe69 | 37 | private: |
embeddedartists | 0:c828045bbe69 | 38 | enum Constants { |
embeddedartists | 0:c828045bbe69 | 39 | BACKGROUND_COLOR = BLACK, |
embeddedartists | 0:c828045bbe69 | 40 | SMALL_CIRCLE_FRONT_COLOR = WHITE, |
embeddedartists | 0:c828045bbe69 | 41 | |
embeddedartists | 0:c828045bbe69 | 42 | LENS = 256, |
embeddedartists | 0:c828045bbe69 | 43 | X_OFFSET = 240, //120, |
embeddedartists | 0:c828045bbe69 | 44 | Y_OFFSET = 130 |
embeddedartists | 0:c828045bbe69 | 45 | }; |
embeddedartists | 0:c828045bbe69 | 46 | |
embeddedartists | 0:c828045bbe69 | 47 | typedef struct |
embeddedartists | 0:c828045bbe69 | 48 | { |
embeddedartists | 0:c828045bbe69 | 49 | uint32_t w; |
embeddedartists | 0:c828045bbe69 | 50 | uint32_t h; |
embeddedartists | 0:c828045bbe69 | 51 | void *pixels; |
embeddedartists | 0:c828045bbe69 | 52 | } Surface_t; |
embeddedartists | 0:c828045bbe69 | 53 | |
embeddedartists | 0:c828045bbe69 | 54 | typedef struct |
embeddedartists | 0:c828045bbe69 | 55 | { |
embeddedartists | 0:c828045bbe69 | 56 | int x; |
embeddedartists | 0:c828045bbe69 | 57 | int y; |
embeddedartists | 0:c828045bbe69 | 58 | } Coord2D_t; |
embeddedartists | 0:c828045bbe69 | 59 | |
embeddedartists | 0:c828045bbe69 | 60 | typedef struct |
embeddedartists | 0:c828045bbe69 | 61 | { |
embeddedartists | 0:c828045bbe69 | 62 | int32_t x; //normal 3d coords |
embeddedartists | 0:c828045bbe69 | 63 | int32_t y; |
embeddedartists | 0:c828045bbe69 | 64 | int32_t z; |
embeddedartists | 0:c828045bbe69 | 65 | int32_t xr; //rotated coords |
embeddedartists | 0:c828045bbe69 | 66 | int32_t yr; |
embeddedartists | 0:c828045bbe69 | 67 | int32_t zr; |
embeddedartists | 0:c828045bbe69 | 68 | int32_t scrx; //translated and projected 3d points |
embeddedartists | 0:c828045bbe69 | 69 | int32_t scry; |
embeddedartists | 0:c828045bbe69 | 70 | } tPoint3d; |
embeddedartists | 0:c828045bbe69 | 71 | |
embeddedartists | 0:c828045bbe69 | 72 | typedef struct |
embeddedartists | 0:c828045bbe69 | 73 | { |
embeddedartists | 0:c828045bbe69 | 74 | int32_t p1; //vertex |
embeddedartists | 0:c828045bbe69 | 75 | int32_t p2; |
embeddedartists | 0:c828045bbe69 | 76 | int32_t p3; |
embeddedartists | 0:c828045bbe69 | 77 | int32_t u1; //texture coords |
embeddedartists | 0:c828045bbe69 | 78 | int32_t v1; |
embeddedartists | 0:c828045bbe69 | 79 | int32_t u2; |
embeddedartists | 0:c828045bbe69 | 80 | int32_t v2; |
embeddedartists | 0:c828045bbe69 | 81 | int32_t u3; |
embeddedartists | 0:c828045bbe69 | 82 | int32_t v3; |
embeddedartists | 0:c828045bbe69 | 83 | } tPoly; |
embeddedartists | 0:c828045bbe69 | 84 | |
embeddedartists | 0:c828045bbe69 | 85 | typedef struct |
embeddedartists | 0:c828045bbe69 | 86 | { |
embeddedartists | 0:c828045bbe69 | 87 | int32_t x; |
embeddedartists | 0:c828045bbe69 | 88 | int32_t y; |
embeddedartists | 0:c828045bbe69 | 89 | int32_t z; |
embeddedartists | 0:c828045bbe69 | 90 | } tVector; |
embeddedartists | 0:c828045bbe69 | 91 | |
embeddedartists | 0:c828045bbe69 | 92 | int32_t windowX; |
embeddedartists | 0:c828045bbe69 | 93 | int32_t windowY; |
embeddedartists | 0:c828045bbe69 | 94 | uint16_t *pFrmBuf; |
embeddedartists | 0:c828045bbe69 | 95 | uint16_t *pFrmBuf1; |
embeddedartists | 0:c828045bbe69 | 96 | uint16_t *pFrmBuf2; |
embeddedartists | 0:c828045bbe69 | 97 | uint16_t *pFrmBuf3; |
embeddedartists | 0:c828045bbe69 | 98 | |
embeddedartists | 0:c828045bbe69 | 99 | Graphics graphics; |
embeddedartists | 0:c828045bbe69 | 100 | |
embeddedartists | 0:c828045bbe69 | 101 | Surface_t sourcePicture1; |
embeddedartists | 0:c828045bbe69 | 102 | Surface_t sourcePicture2; |
embeddedartists | 0:c828045bbe69 | 103 | Surface_t activeFrame; |
embeddedartists | 0:c828045bbe69 | 104 | |
embeddedartists | 0:c828045bbe69 | 105 | int32_t rx; |
embeddedartists | 0:c828045bbe69 | 106 | int32_t ry; |
embeddedartists | 0:c828045bbe69 | 107 | int32_t rx_; |
embeddedartists | 0:c828045bbe69 | 108 | int32_t ry_; |
embeddedartists | 0:c828045bbe69 | 109 | uint8_t mode; |
embeddedartists | 0:c828045bbe69 | 110 | |
embeddedartists | 0:c828045bbe69 | 111 | tPoint3d cubeModel[8]; |
embeddedartists | 0:c828045bbe69 | 112 | tPoly cubePoly[12]; |
embeddedartists | 0:c828045bbe69 | 113 | |
embeddedartists | 0:c828045bbe69 | 114 | uint32_t camX; |
embeddedartists | 0:c828045bbe69 | 115 | uint32_t camY; |
embeddedartists | 0:c828045bbe69 | 116 | uint32_t camZ; |
embeddedartists | 0:c828045bbe69 | 117 | |
embeddedartists | 0:c828045bbe69 | 118 | void plot4points( int32_t cx, int32_t cy, int32_t x, int32_t y, int16_t color, int32_t Filled ); |
embeddedartists | 0:c828045bbe69 | 119 | void plot8points( int32_t cx, int32_t cy, int32_t x, int32_t y, int16_t color, int32_t Filled ); |
embeddedartists | 0:c828045bbe69 | 120 | void put_circle( int32_t cx, int32_t cy, int16_t color, int32_t radius, int32_t Filled ); |
embeddedartists | 0:c828045bbe69 | 121 | int32_t swim_abs(int32_t v1); |
embeddedartists | 0:c828045bbe69 | 122 | void put_line(int32_t x1, int32_t y1, int32_t x2, int32_t y2, int16_t color); |
embeddedartists | 0:c828045bbe69 | 123 | |
embeddedartists | 0:c828045bbe69 | 124 | int32_t sgn(int32_t val) const; |
embeddedartists | 0:c828045bbe69 | 125 | short icosine(short x) const; |
embeddedartists | 0:c828045bbe69 | 126 | short isine(short x) const; |
embeddedartists | 0:c828045bbe69 | 127 | short _cos(short y) const; |
embeddedartists | 0:c828045bbe69 | 128 | short _sin(short y) const; |
embeddedartists | 0:c828045bbe69 | 129 | |
embeddedartists | 0:c828045bbe69 | 130 | void TriangleProjectFast(Surface_t *SrcRP_p, Surface_t *DstRP_p, Coord2D_t *SrcCoords_p, Coord2D_t *DstCoords_p); |
embeddedartists | 0:c828045bbe69 | 131 | void CpPixel16Fast(int xSrc, int ySrc, int x, int y, Surface_t *SrcRP_p, Surface_t *DstRP_p); |
embeddedartists | 0:c828045bbe69 | 132 | |
embeddedartists | 0:c828045bbe69 | 133 | void drawCubeZ(Surface_t *pSourcePicture, uint8_t shades); |
embeddedartists | 0:c828045bbe69 | 134 | void rotateAndProject(uint16_t rotX, uint16_t rotY, uint16_t rotZ); |
embeddedartists | 0:c828045bbe69 | 135 | void createCubeModel(uint32_t radius); |
embeddedartists | 0:c828045bbe69 | 136 | |
embeddedartists | 0:c828045bbe69 | 137 | unsigned decodePNG(const unsigned char* pIn, size_t insize, Surface_t* pOut); |
embeddedartists | 0:c828045bbe69 | 138 | |
embeddedartists | 0:c828045bbe69 | 139 | |
embeddedartists | 0:c828045bbe69 | 140 | void initialize(); |
embeddedartists | 0:c828045bbe69 | 141 | void render(uint32_t idx); |
embeddedartists | 0:c828045bbe69 | 142 | }; |
embeddedartists | 0:c828045bbe69 | 143 | |
embeddedartists | 0:c828045bbe69 | 144 | |
embeddedartists | 0:c828045bbe69 | 145 | #endif /* CUBEDEMO_H */ |
embeddedartists | 0:c828045bbe69 | 146 |