sync
This commit is contained in:
parent
b73bbdc91e
commit
06aa9ce6c1
@ -4,6 +4,7 @@
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <SDL.h>
|
||||
#include <SDL_ttf.h>
|
||||
#include "triangle.h"
|
||||
|
||||
#define FPS 30
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <SDL.h>
|
||||
#include <SDL_ttf.h>
|
||||
#include "display.h"
|
||||
#include "mesh.h"
|
||||
#include "vector.h"
|
||||
@ -9,6 +10,21 @@
|
||||
|
||||
#define STEP 0.075
|
||||
|
||||
uint32_t colors[12] = {
|
||||
0xFF6A2EFF, // purple
|
||||
0xFFE9C46A, // sand yellow
|
||||
0xFF2A9D8F, // teal green
|
||||
0xFFF4A261, // orange
|
||||
0xFF264653, // dark blue-grey
|
||||
0xFFB5838D, // mauve
|
||||
0xFFD7263D, // red
|
||||
0xFF38A3A5, // turquoise
|
||||
0xFF757575, // grey
|
||||
0xFF70C1B3, // light green-blue
|
||||
0xFFFFC300, // yellow
|
||||
0xFF5D2E8C // deep purple
|
||||
};
|
||||
|
||||
triangle_t* triangles_to_render = NULL; //[N_MESH_FACES];
|
||||
|
||||
vec3_t camera_position = { 0, 0, 0 };
|
||||
@ -179,17 +195,24 @@ void update(void) {
|
||||
|
||||
void render(void) {
|
||||
draw_grid();
|
||||
|
||||
//uint32_t colors[] = { 0xFFFF0000, 0xFF00FF00, 0xFF0000FF, 0xFF757500, 0xFF007575, 0xFF750075 };
|
||||
// Loop all projected points and render them
|
||||
|
||||
for (int i = 0; i < array_length(triangles_to_render); i++) {
|
||||
triangle_t triangle = triangles_to_render[i];
|
||||
draw_filled_triangle(triangle, 0xFFFFFFFF);
|
||||
draw_triangle(triangle, 0xFF000000);
|
||||
draw_rect(triangle.points[0].x, triangle.points[0].y, 3, 3, 0xFFFFFF00);
|
||||
draw_rect(triangle.points[1].x, triangle.points[1].y, 3, 3, 0xFFFFFF00);
|
||||
draw_rect(triangle.points[2].x, triangle.points[2].y, 3, 3, 0xFFFFFF00);
|
||||
draw_filled_triangle(triangle, colors[i]);
|
||||
//draw_triangle(triangle, 0xFFFF0000);
|
||||
//draw_rect(triangle.points[0].x, triangle.points[0].y, 3, 3, 0xFFFFFF00);
|
||||
//draw_rect(triangle.points[1].x, triangle.points[1].y, 3, 3, 0xFFFFFF00);
|
||||
//draw_rect(triangle.points[2].x, triangle.points[2].y, 3, 3, 0xFFFFFF00);
|
||||
}
|
||||
|
||||
triangle_t t;
|
||||
t.points[0] = (vec2_t){ 100, 100 };
|
||||
t.points[1] = (vec2_t){ 100, 200.1 };
|
||||
t.points[2] = (vec2_t){ 300, 200.5};
|
||||
draw_filled_triangle(t, 0xFF00FF00);
|
||||
|
||||
//vec2_t m = triangle_midpoint(t);
|
||||
//draw_rect(m.x, m.y, 10, 10, 0xFFFF0000);
|
||||
|
||||
|
||||
@ -13,15 +13,25 @@ int compare_vec2_t(const void* a, const void* b) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define FUNC ceilf
|
||||
#define FUNC2 floorf
|
||||
|
||||
uint32_t invert_rgb(uint32_t color) {
|
||||
uint32_t a = color & 0xFF000000; // Alpha channel
|
||||
uint32_t rgb = color & 0x00FFFFFF; // RGB channels
|
||||
rgb = ~rgb & 0x00FFFFFF; // Invert RGB only
|
||||
return a | rgb;
|
||||
}
|
||||
|
||||
void fill_flat_bottom_triangle(const triangle_t* triangle, uint32_t color) {
|
||||
float inv_slope_1 = (triangle->points[1].x - triangle->points[0].x) / (triangle->points[1].y - triangle->points[0].y);
|
||||
float inv_slope_2 = (triangle->points[2].x - triangle->points[0].x) / (triangle->points[2].y - triangle->points[0].y);;
|
||||
|
||||
float x_start = triangle->points[0].x, x_end = triangle->points[0].x;
|
||||
|
||||
for (int x = (int)triangle->points[0].y; x <= (int)triangle->points[2].y; x++) {
|
||||
for (int x = FUNC(triangle->points[0].y); x < FUNC(triangle->points[2].y); x++) {
|
||||
//draw_rect((int)triangle->points[0].x, i, 1, 1, 0xFFFF0000);
|
||||
draw_line(round(x_start), x, round(x_end), x, color);
|
||||
draw_line(FUNC2(x_start), x, FUNC2(x_end), x, color);
|
||||
x_start += inv_slope_1;
|
||||
x_end += inv_slope_2;
|
||||
}
|
||||
@ -33,9 +43,9 @@ void fill_flat_top_triangle(const triangle_t* triangle, uint32_t color) {
|
||||
|
||||
float x_start = triangle->points[2].x, x_end = triangle->points[2].x;
|
||||
|
||||
for (int y = (int)triangle->points[2].y; y >= (int)triangle->points[0].y; y--) {
|
||||
for (int y = FUNC(triangle->points[2].y); y > FUNC(triangle->points[0].y); y--) {
|
||||
//draw_rect((int)triangle->points[0].x, i, 1, 1, 0xFFFF0000);
|
||||
draw_line(round(x_start), y, round(x_end), y, color);
|
||||
draw_line(FUNC2(x_start), y, FUNC2(x_end), y, color);
|
||||
x_start -= inv_slope_1;
|
||||
x_end -= inv_slope_2;
|
||||
}
|
||||
@ -77,6 +87,6 @@ void draw_filled_triangle(triangle_t triangle, uint32_t color) {
|
||||
flat_top.points[2] = triangle.points[max_idx];
|
||||
|
||||
fill_flat_bottom_triangle(&flat_bottom, color);
|
||||
fill_flat_top_triangle(&flat_top, color);
|
||||
fill_flat_top_triangle(&flat_top, (color));
|
||||
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user