colors, rotations, and more
This commit is contained in:
33
modules/Console_Render/rotate.jai
Normal file
33
modules/Console_Render/rotate.jai
Normal file
@@ -0,0 +1,33 @@
|
||||
// single point rotation
|
||||
rotate :: (p: *Vec2s64, center: Vec2s64, angle: s64) {
|
||||
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 :: (pn: ..*Vec2s64, center: Vec2s64, angle: s64) {
|
||||
for pn {
|
||||
rotate(it, center, angle);
|
||||
}
|
||||
}
|
||||
|
||||
// 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 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);
|
||||
}
|
||||
Reference in New Issue
Block a user