two triangles

This commit is contained in:
Zack Buhman 2023-12-05 21:53:04 +08:00
parent a73327c76d
commit bac7618df2
2 changed files with 22 additions and 12 deletions

View File

@ -53,7 +53,7 @@ void serial_string(const char * s)
/* must be aligned to 32-bytes for DMA transfer */ /* must be aligned to 32-bytes for DMA transfer */
// the aligned(32) attribute does not actually align to 32 bytes; gcc is the best compiler. // the aligned(32) attribute does not actually align to 32 bytes; gcc is the best compiler.
// `+ 32` to allow for repositioning _scene to an actual 32-byte alignment. // `+ 32` to allow for repositioning _scene to an actual 32-byte alignment.
uint32_t __attribute__((aligned(32))) _scene[((32 * 5) + 32) / 4]; uint32_t __attribute__((aligned(32))) _scene[((32 * 6) + 32) / 4];
uint32_t * align_32byte(uint32_t * mem) uint32_t * align_32byte(uint32_t * mem)
{ {

View File

@ -9,10 +9,18 @@
-0.5,0.5 | 0.5,0.5 -0.5,0.5 | 0.5,0.5
*/ */
float scene_triangle[3][3] = { struct triangle {
{ 0.f, -0.5f, 1/10.f}, float x;
{ 0.5f, 0.5f, 1/10.f}, float y;
{ -0.5f, 0.5f, 1/10.f}, float z;
uint32_t color;
};
const struct triangle scene_triangle[4] = {
{ -0.5f, 0.5f, 1/10.f, 0x00000000}, // the first two base colors in a
{ -0.5f, -0.5f, 1/10.f, 0x00000000}, // triangle strip are ignored
{ 0.5f, 0.5f, 1/10.f, 0xffff00ff},
{ 0.5f, -0.5f, 1/10.f, 0xffffff00},
}; };
static float theta = 0; static float theta = 0;
@ -25,14 +33,16 @@ uint32_t scene_transform(volatile uint32_t * scene)
triangle(&scene[(32 * ix) / 4]); triangle(&scene[(32 * ix) / 4]);
ix++; ix++;
for (int i = 0; i < 3; i++) { for (int i = 0; i < 4; i++) {
bool end_of_strip = i == 2; bool end_of_strip = i == 3;
float x = scene_triangle[i][0]; float x = scene_triangle[i].x;
float y = scene_triangle[i][1]; float y = scene_triangle[i].y;
float x1;
x = x * __builtin_cosf(theta) - y * __builtin_sinf(theta); x1 = x * __builtin_cosf(theta) - y * __builtin_sinf(theta);
y = x * __builtin_sinf(theta) + y * __builtin_cosf(theta); y = x * __builtin_sinf(theta) + y * __builtin_cosf(theta);
x = x1;
x *= 240.f; x *= 240.f;
y *= 240.f; y *= 240.f;
x += 320.f; x += 320.f;
@ -41,8 +51,8 @@ uint32_t scene_transform(volatile uint32_t * scene)
vertex(&scene[(32 * ix) / 4], vertex(&scene[(32 * ix) / 4],
x, // x x, // x
y, // y y, // y
scene_triangle[i][2], // z scene_triangle[i].z, // z
0xffff00ff, // base_color scene_triangle[i].color, // base_color
end_of_strip); end_of_strip);
ix++; ix++;
} }