67 lines
1.5 KiB
Plaintext
67 lines
1.5 KiB
Plaintext
// 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);
|
|
|
|
// translate to center
|
|
tx := p.x - center.x;
|
|
ty := p.y - center.y;
|
|
|
|
// apply rotation
|
|
rx := cast(s64)(tx * cos(rad) - ty * sin(rad));
|
|
ry := cast(s64)(tx * sin(rad) + ty * cos(rad));
|
|
|
|
// translate back
|
|
p.x = rx + center.x;
|
|
p.y = ry + center.y;
|
|
}
|
|
|
|
// rotate n points
|
|
rotate :: (angle: s64, center: Vec2s64, pn: ..*Vec2s64) {
|
|
for pn {
|
|
rotate(angle, center, it);
|
|
}
|
|
}
|
|
|
|
// rotate 3 points via triangle struct
|
|
rotate :: (angle: s64, center: Vec2s64, t: *Triangle) {
|
|
rotate(angle, center, *t.p1, *t.p2, *t.p3);
|
|
}
|
|
|
|
// 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);
|
|
} |