This commit is contained in:
2024-10-11 01:52:10 -04:00
parent 823a8f79d3
commit a663e45131
7 changed files with 96 additions and 76 deletions

View File

@@ -1,7 +1,7 @@
// "Squashes" two dimensional coordinates onto the one dimensional screen buffer
draw :: (using screen: *Screen, p: Vec2s64, char: u8 = DEFAULT_PIXEL_CHAR) {
if p.x >= 0 && p.x < width && p.y >= 0 && p.y < height {
buffer[p.y * width + p.x] = cast(u8)char;
buffer[p.y * width + p.x] = char;
}
}

View File

@@ -16,19 +16,4 @@ make_quad_from_rect :: (p1: Vec2s64, p2: Vec2s64) -> Quad {
.{ p2.x, p2.y },
.{ p1.x, p2.y },
};
}
scale :: (factor: float, pn: ..*Vec2s64) {
for pn {
it.x = cast(s64)(it.x * factor);
it.y = cast(s64)(it.y * factor);
}
}
scale :: (factor: float, t: *Triangle) {
scale(factor, *t.p1, *t.p2, *t.p3);
}
scale :: (factor: float, q: *Quad) {
scale(factor, *q.p1, *q.p2, *q.p3, *q.p4);
}

View File

@@ -106,6 +106,8 @@ maybe_resize_screen :: (screen: *Screen) {
#load "draw.jai";
#load "rotate.jai";
#load "scale.jai";
#load "translate.jai";
#load "file_operations.jai";
#load "console.jai";
#load "math_extras.jai";

View File

@@ -1,5 +1,5 @@
// single point rotation
rotate :: (p: *Vec2s64, center: Vec2s64, angle: s64) {
rotate :: (angle: s64, center: Vec2s64, p: *Vec2s64) {
rad := cast(float64)angle * (PI / 180.0);
// translate to center
@@ -16,18 +16,18 @@ rotate :: (p: *Vec2s64, center: Vec2s64, angle: s64) {
}
// rotate n points
rotate :: (pn: ..*Vec2s64, center: Vec2s64, angle: s64) {
rotate :: (angle: s64, center: Vec2s64, pn: ..*Vec2s64) {
for pn {
rotate(it, center, angle);
rotate(angle, center, it);
}
}
// rotate 3 points via triangle struct
rotate :: (t: *Triangle, center: Vec2s64, angle: s64) {
rotate(*t.p1, *t.p2, *t.p3, center = center, angle = angle);
rotate :: (angle: s64, center: Vec2s64, t: *Triangle) {
rotate(angle, center, *t.p1, *t.p2, *t.p3);
}
// rotate 4 points via quad struct
rotate :: (q: *Quad, center: Vec2s64, angle: s64) {
rotate(*q.p1, *q.p2, *q.p3, *q.p4, center = center, angle = angle);
rotate :: (angle: s64, center: Vec2s64, q: *Quad) {
rotate(angle, center, *q.p1, *q.p2, *q.p3, *q.p4);
}

View File

@@ -0,0 +1,14 @@
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

@@ -0,0 +1,18 @@
// 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);
}