move transformations into single file

This commit is contained in:
2025-06-30 09:36:36 -04:00
parent be43704a64
commit 13d5944e2a
6 changed files with 41 additions and 55 deletions

View File

@@ -1,4 +1,4 @@
[6] # Version number. Do not delete.
[18] # Version number. Do not delete.
[[workspace]]
# These directories and files will be scanned when a workspace is opened so that search etc. works.
@@ -26,13 +26,7 @@ build_command: jai build.jai
build_command: arch -x86_64 /opt/jai/bin/jai-macos build.jai
key_binding: Cmd-Shift-B
[Run MacOS]
run_working_dir: .
run_command: term.scpt "cd %RUN_WORKING_DIR%/build_debug && ./console3d"
key_binding: F5
[[settings]]
tab_size: 4
insert_spaces_when_pressing_tab: true
indent_using: spaces # options: spaces, tabs
strip_trailing_whitespace_on_save: except_lines_with_cursor # options: all, except_lines_with_cursor, disabled

View File

@@ -105,9 +105,7 @@ maybe_resize_screen :: (screen: *Screen) {
}
#load "draw.jai";
#load "rotate.jai";
#load "scale.jai";
#load "translate.jai";
#load "transform.jai";
#load "file_operations.jai";
#load "console.jai";
#load "math_extras.jai";

View File

@@ -1,14 +0,0 @@
scale :: (factor: Vector2, pn: ..*Vec2s64) {
for pn {
it.x = cast(s64)(it.x * factor.x);
it.y = cast(s64)(it.y * factor.y);
}
}
scale :: (factor: Vector2, t: *Triangle) {
scale(factor, *t.p1, *t.p2, *t.p3);
}
scale :: (factor: Vector2, q: *Quad) {
scale(factor, *q.p1, *q.p2, *q.p3, *q.p4);
}

View File

@@ -1,3 +1,22 @@
// for n points
translate :: (amount: Vec2s64, pn: ..*Vec2s64) {
for pn {
it.x += amount.x;
it.y += amount.y;
}
}
// for a triangle
translate :: (amount: Vec2s64, t: *Triangle) {
translate(amount, *t.p1, *t.p2, *t.p3);
}
// for a quad
translate :: (amount: Vec2s64, q: *Quad) {
translate(amount, *q.p1, *q.p2, *q.p3, *q.p4);
}
// single point rotation
rotate :: (angle: s64, center: Vec2s64, p: *Vec2s64) {
rad := cast(float64)angle * (PI / 180.0);
@@ -30,4 +49,19 @@ rotate :: (angle: s64, center: Vec2s64, t: *Triangle) {
// rotate 4 points via quad struct
rotate :: (angle: s64, center: Vec2s64, q: *Quad) {
rotate(angle, center, *q.p1, *q.p2, *q.p3, *q.p4);
}
scale :: (factor: Vector2, pn: ..*Vec2s64) {
for pn {
it.x = cast(s64)(it.x * factor.x);
it.y = cast(s64)(it.y * factor.y);
}
}
scale :: (factor: Vector2, t: *Triangle) {
scale(factor, *t.p1, *t.p2, *t.p3);
}
scale :: (factor: Vector2, q: *Quad) {
scale(factor, *q.p1, *q.p2, *q.p3, *q.p4);
}

View File

@@ -1,18 +0,0 @@
// for n points
translate :: (amount: Vec2s64, pn: ..*Vec2s64) {
for pn {
it.x += amount.x;
it.y += amount.y;
}
}
// for a triangle
translate :: (amount: Vec2s64, t: *Triangle) {
translate(amount, *t.p1, *t.p2, *t.p3);
}
// for a quad
translate :: (amount: Vec2s64, q: *Quad) {
translate(amount, *q.p1, *q.p2, *q.p3, *q.p4);
}

View File

@@ -22,10 +22,10 @@ main :: () {
fill_entire_screen(screen, BLANK_PIXEL);
// cool_demo_2(screen, offset, theta);
// cool_demo_1(screen, offset, theta);
dvd_logo_bounce(screen);
cool_demo_1(screen, offset, theta);
// dvd_logo_bounce(screen);
annoying_color_effect(screen, offset);
// annoying_color_effect(screen, offset);
swap_buffer(screen);
sleep_milliseconds(20);
@@ -47,7 +47,7 @@ annoying_color_effect :: (screen: *Screen, modifier: s64) {
cool_demo_1 :: (screen: *Screen, offset: s64, theta: s64) {
t1 := Triangle.{
.{30 - offset, 20},
.{95, 10 - (offset / 2)},
.{95, 10 - (offset / 2)},
.{90 + offset, 40},
};
@@ -64,16 +64,8 @@ cool_demo_1 :: (screen: *Screen, offset: s64, theta: s64) {
// draw centroid lines
draw_text(screen, get_triangle_centroid(t2), " [ TEXT-BASED RENDERING DEMO ]");
draw_line(screen, get_triangle_centroid(t1), get_triangle_centroid(t2), #char ".");
// draw_line(screen, get_triangle_centroid(t1), t1.p1, #char ".");
// draw_line(screen, get_triangle_centroid(t1), t1.p2, #char ".");
// draw_line(screen, get_triangle_centroid(t1), t1.p3, #char ".");18
// draw_line(screen, get_triangle_centroid(t2), t2.p1, #char ".");
// draw_line(screen, get_triangle_centroid(t2), t2.p2, #char ".");
// draw_line(screen, get_triangle_centroid(t2), t2.p3, #char ".");
// connect triangles to eachother for fake 3d effect
draw_line(screen, t1.p1, t2.p1, #char "%");
draw_line(screen, t1.p2, t2.p2, #char "%");