Example for the LPC4088 QSB Base Board

Dependencies:   EALib mbed

Committer:
embeddedartists
Date:
Wed Jan 08 12:33:57 2014 +0000
Revision:
0:a771927a62fd
First version (with temporary stack fix)

Who changed what in which revision?

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