From bac7618df20c3aa05ecfcd19368e7e4f98feddef Mon Sep 17 00:00:00 2001 From: Zack Buhman Date: Tue, 5 Dec 2023 21:53:04 +0800 Subject: [PATCH] two triangles --- main.cpp | 2 +- scene.cpp | 32 +++++++++++++++++++++----------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/main.cpp b/main.cpp index 43cd040..4dc3f3d 100644 --- a/main.cpp +++ b/main.cpp @@ -53,7 +53,7 @@ void serial_string(const char * s) /* 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. // `+ 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) { diff --git a/scene.cpp b/scene.cpp index 636ed8a..ed642ff 100644 --- a/scene.cpp +++ b/scene.cpp @@ -9,10 +9,18 @@ -0.5,0.5 | 0.5,0.5 */ -float scene_triangle[3][3] = { - { 0.f, -0.5f, 1/10.f}, - { 0.5f, 0.5f, 1/10.f}, - { -0.5f, 0.5f, 1/10.f}, +struct triangle { + float x; + float y; + 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; @@ -25,14 +33,16 @@ uint32_t scene_transform(volatile uint32_t * scene) triangle(&scene[(32 * ix) / 4]); ix++; - for (int i = 0; i < 3; i++) { - bool end_of_strip = i == 2; + for (int i = 0; i < 4; i++) { + bool end_of_strip = i == 3; - float x = scene_triangle[i][0]; - float y = scene_triangle[i][1]; + float x = scene_triangle[i].x; + 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); + x = x1; x *= 240.f; y *= 240.f; x += 320.f; @@ -41,8 +51,8 @@ uint32_t scene_transform(volatile uint32_t * scene) vertex(&scene[(32 * ix) / 4], x, // x y, // y - scene_triangle[i][2], // z - 0xffff00ff, // base_color + scene_triangle[i].z, // z + scene_triangle[i].color, // base_color end_of_strip); ix++; }