going round and round
This commit is contained in:
parent
adc8759e0e
commit
3aa61d683d
3 changed files with 40 additions and 35 deletions
|
@ -30,19 +30,33 @@ pub struct Circle {
|
||||||
|
|
||||||
impl Circle {
|
impl Circle {
|
||||||
pub fn new(p1: &types::Planet, p2: &types::Planet) -> Self {
|
pub fn new(p1: &types::Planet, p2: &types::Planet) -> Self {
|
||||||
let dx = p1.x - p2.x;
|
let x1 = p1.x;
|
||||||
let dy = p1.y - p2.y;
|
let y1 = p1.y;
|
||||||
let dr = (dx * dx + dy * dy).sqrt();
|
let x2 = p2.x;
|
||||||
let r = dr * 1.05;
|
let y2 = p2.y;
|
||||||
let distance = (dx * dx + dy * dy).sqrt().ceil() as usize;
|
|
||||||
|
|
||||||
let d = p1.x * p2.y - p2.x * p1.y;
|
let q = ((x2-x1).powi(2) + (y2-y1).powi(2)).sqrt();
|
||||||
|
let x3 = (x1+x2)/2.0;
|
||||||
|
let y3 = (y1+y2)/2.0;
|
||||||
|
|
||||||
let x = (d * dy + dy.signum() * dx * (r * r * dr * dr - d * d).sqrt()) / (dr * dr);
|
let r = q * 1.1;
|
||||||
let y = (-d * dx + dy.abs() * (r * r * dr * dr - d * d).sqrt()) / (dr * dr);
|
|
||||||
|
|
||||||
let a1 = (y - p1.y).atan2(x - p1.x);
|
let (x, y) = if true {
|
||||||
let a2 = (y - p2.y).atan2(x - p2.x);
|
(
|
||||||
|
x3 + (r.powi(2)-(q/2.0).powi(2)).sqrt() * (y1-y2)/q,
|
||||||
|
y3 + (r.powi(2)-(q/2.0).powi(2)).sqrt() * (x2-x1)/q
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
(
|
||||||
|
x3 - (r.powi(2)-(q/2.0).powi(2)).sqrt() * (y1-y2)/q,
|
||||||
|
y3 - (r.powi(2)-(q/2.0).powi(2)).sqrt() * (x2-x1)/q
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
|
let a1 = (y - y1).atan2(x - x1);
|
||||||
|
let a2 = (y - y2).atan2(x - x2);
|
||||||
|
|
||||||
|
let distance = q.ceil() as usize + 1;
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
r, x, y, a1, a2, distance
|
r, x, y, a1, a2, distance
|
||||||
|
@ -57,23 +71,16 @@ impl Circle {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_remaining(&self, remaining: usize) -> Mat3<f32> {
|
fn get_remaining(&self, remaining: usize) -> Mat3<f32> {
|
||||||
let alpha = self.a1 + (1.0 - (remaining as f32 / self.distance as f32)) * (self.a2 - self.a1);
|
let alpha = (self.a1 * remaining as f32 + (self.distance - remaining) as f32 * self.a2) / self.distance as f32;
|
||||||
let c = alpha.cos();
|
|
||||||
let s = alpha.sin();
|
|
||||||
|
|
||||||
|
let cos = alpha.cos();
|
||||||
|
let sin = alpha.sin();
|
||||||
|
// Mat3::rotate_z(alpha) *
|
||||||
Mat3::new(
|
Mat3::new(
|
||||||
c, -s, 0.0,
|
0.3, 0.0, 0.0,
|
||||||
s, c, 0.0,
|
0.0, 0.4, 0.0,
|
||||||
0.0, 0.0, 1.0
|
-self.x + cos * self.r, -self.y + sin * self.r, 0.3,
|
||||||
) * Mat3::new(
|
) * Mat3::rotate_z(alpha)
|
||||||
1.0, 0.0, 0.0,
|
|
||||||
0.0, 1.0, 0.0,
|
|
||||||
self.x, self.y, 1.0,
|
|
||||||
) * Mat3::new(
|
|
||||||
c, -s, 0.0,
|
|
||||||
s, c, 0.0,
|
|
||||||
0.0, 0.0, 1.0
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,8 +121,6 @@ impl Line {
|
||||||
// let x = self.x1 + (remaining as f32 / self.d as f32) * (self.x2 - self.x1);
|
// let x = self.x1 + (remaining as f32 / self.d as f32) * (self.x2 - self.x1);
|
||||||
let y = (self.y1 * remaining as f32 + (self.d - remaining) as f32 * self.y2) / self.d as f32;
|
let y = (self.y1 * remaining as f32 + (self.d - remaining) as f32 * self.y2) / self.d as f32;
|
||||||
|
|
||||||
let c = self.a.cos();
|
|
||||||
let s = self.a.sin();
|
|
||||||
// let y = self.y1 + (remaining as f32 / self.d as f32) * (self.y2 - self.y1);
|
// let y = self.y1 + (remaining as f32 / self.d as f32) * (self.y2 - self.y1);
|
||||||
Mat3::new(
|
Mat3::new(
|
||||||
0.3, 0.0, 0.0,
|
0.3, 0.0, 0.0,
|
||||||
|
@ -131,7 +136,7 @@ pub struct Game {
|
||||||
states: Vec<types::State>,
|
states: Vec<types::State>,
|
||||||
turn: usize,
|
turn: usize,
|
||||||
|
|
||||||
planet_map: HashMap<(String, String), Line>,
|
planet_map: HashMap<(String, String), Circle>,
|
||||||
|
|
||||||
/* put extra shit here */
|
/* put extra shit here */
|
||||||
view_box: Vec<f32>,
|
view_box: Vec<f32>,
|
||||||
|
@ -162,7 +167,7 @@ impl Game {
|
||||||
// Iterator?
|
// Iterator?
|
||||||
for p1 in states[0].planets.iter() {
|
for p1 in states[0].planets.iter() {
|
||||||
for p2 in states[0].planets.iter() {
|
for p2 in states[0].planets.iter() {
|
||||||
planet_map.insert((p1.name.clone(), p2.name.clone()), Line::new(&p1, &p2));
|
planet_map.insert((p1.name.clone(), p2.name.clone()), Circle::new(&p1, &p2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -80,7 +80,7 @@ class GameInstance {
|
||||||
const transform = new UniformMatrix3fv([
|
const transform = new UniformMatrix3fv([
|
||||||
1, 0, 0,
|
1, 0, 0,
|
||||||
0, 1, 0,
|
0, 1, 0,
|
||||||
planets[i*3], planets[i*3+1], 1,
|
-planets[i*3], -planets[i*3+1], 1,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const indexBuffer = new IndexBuffer(GL, meshes[i % meshes.length].cells);
|
const indexBuffer = new IndexBuffer(GL, meshes[i % meshes.length].cells);
|
||||||
|
|
|
@ -25,9 +25,9 @@
|
||||||
borderopacity="1.0"
|
borderopacity="1.0"
|
||||||
inkscape:pageopacity="0.0"
|
inkscape:pageopacity="0.0"
|
||||||
inkscape:pageshadow="2"
|
inkscape:pageshadow="2"
|
||||||
inkscape:zoom="0.24748737"
|
inkscape:zoom="1.0993438"
|
||||||
inkscape:cx="-106.07564"
|
inkscape:cx="-51.525162"
|
||||||
inkscape:cy="608.26605"
|
inkscape:cy="316.36545"
|
||||||
inkscape:document-units="mm"
|
inkscape:document-units="mm"
|
||||||
inkscape:current-layer="layer1"
|
inkscape:current-layer="layer1"
|
||||||
showgrid="false"
|
showgrid="false"
|
||||||
|
@ -58,8 +58,8 @@
|
||||||
id="layer1"
|
id="layer1"
|
||||||
transform="translate(229.05372,-117.27915)">
|
transform="translate(229.05372,-117.27915)">
|
||||||
<path
|
<path
|
||||||
style="opacity:1;fill:#000000;fill-opacity:1;stroke:none;stroke-width:2.72543406;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
style="opacity:1;fill:#000000;fill-opacity:1;stroke:none;stroke-width:3.57897162;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||||
d="m -229.05372,167.27915 c 0,0 13.45401,-50 48.27481,-50 11.57339,0 21.79319,8.51775 27.92829,21.52314 7.7319,-15.5144 21.11806,-16.32589 22.56968,-13.92304 1.75107,2.89851 1.72384,19.14347 -0.70314,25.00722 -1.17787,2.84584 -10.35261,5.01798 -16.67359,6.19846 0.55938,3.59896 0.85565,7.34571 0.85565,11.19422 0,3.84851 -0.29627,7.59526 -0.85565,11.19423 6.32098,1.18047 15.49572,3.35262 16.67359,6.19845 2.42698,5.86375 2.45421,22.10872 0.70314,25.00723 -1.45162,2.40285 -14.83778,1.59135 -22.56968,-13.92304 -6.1351,13.00539 -16.3549,21.52313 -27.92829,21.52313 -34.8208,0 -48.27481,-50 -48.27481,-50 z m 24.32378,0 a 25.255825,28.025483 0 0 0 25.25579,28.02559 25.255825,28.025483 0 0 0 25.25578,-28.02559 25.255825,28.025483 0 0 0 -25.25578,-28.02558 25.255825,28.025483 0 0 0 -25.25579,28.02558 z"
|
d="m -179.05372,44.836309 c 0,0 50,23.200477 50,83.246451 0,19.95749 -8.51775,37.5808 -21.52314,48.16034 15.5144,13.33311 16.32589,36.41658 13.92304,38.91979 -2.89851,3.01961 -19.14347,2.97265 -25.00722,-1.2125 -2.84584,-2.03116 -5.01798,-17.85234 -6.19846,-28.75242 -3.59896,0.96461 -7.34571,1.4755 -11.19422,1.4755 -3.84851,0 -7.59526,-0.51089 -11.19423,-1.4755 -1.18047,10.90008 -3.35262,26.72126 -6.19845,28.75242 -5.86375,4.18515 -22.10872,4.23211 -25.00723,1.2125 -2.40285,-2.50321 -1.59135,-25.58668 13.92304,-38.91979 -13.00539,-10.57954 -21.52313,-28.20285 -21.52313,-48.16034 0,-60.045974 50,-83.246451 50,-83.246451 z m 0,41.944617 a 28.025483,43.551862 0 0 0 -28.02559,43.551794 28.025483,43.551862 0 0 0 28.02559,43.55179 28.025483,43.551862 0 0 0 28.02558,-43.55179 28.025483,43.551862 0 0 0 -28.02558,-43.551794 z"
|
||||||
id="path815"
|
id="path815"
|
||||||
inkscape:connector-curvature="0" />
|
inkscape:connector-curvature="0" />
|
||||||
</g>
|
</g>
|
||||||
|
|
Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 2.7 KiB |
Loading…
Reference in a new issue