Application prototype #14
27
app-proto/full-interface/src/engine.rs
Normal file
27
app-proto/full-interface/src/engine.rs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
use nalgebra::DVector;
|
||||||
|
|
||||||
|
// the sphere with the given center and radius, with inward-pointing normals
|
||||||
|
pub fn sphere(center_x: f64, center_y: f64, center_z: f64, radius: f64) -> DVector<f64> {
|
||||||
|
let center_norm_sq = center_x * center_x + center_y * center_y + center_z * center_z;
|
||||||
|
DVector::from_column_slice(&[
|
||||||
|
center_x / radius,
|
||||||
|
center_y / radius,
|
||||||
|
center_z / radius,
|
||||||
|
0.5 / radius,
|
||||||
|
0.5 * (center_norm_sq / radius - radius)
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
|
// the sphere of curvature `curv` whose closest point to the origin has position
|
||||||
|
// `off * dir` and normal `dir`, where `dir` is a unit vector. setting the
|
||||||
|
// curvature to zero gives a plane
|
||||||
|
pub fn sphere_with_offset(dir_x: f64, dir_y: f64, dir_z: f64, off: f64, curv: f64) -> DVector<f64> {
|
||||||
|
let norm_sp = 1.0 + off * curv;
|
||||||
|
DVector::from_column_slice(&[
|
||||||
|
norm_sp * dir_x,
|
||||||
|
norm_sp * dir_y,
|
||||||
|
norm_sp * dir_z,
|
||||||
|
0.5 * curv,
|
||||||
|
off * (1.0 + 0.5 * off * curv)
|
||||||
|
])
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
mod add_remove;
|
mod add_remove;
|
||||||
mod assembly;
|
mod assembly;
|
||||||
mod display;
|
mod display;
|
||||||
|
mod engine;
|
||||||
mod outline;
|
mod outline;
|
||||||
|
|
||||||
use nalgebra::DVector;
|
use nalgebra::DVector;
|
||||||
@ -34,36 +35,63 @@ fn main() {
|
|||||||
let assemb = &state.assembly;
|
let assemb = &state.assembly;
|
||||||
let _ = assemb.try_insert_element(
|
let _ = assemb.try_insert_element(
|
||||||
Element {
|
Element {
|
||||||
id: String::from("wing_a"),
|
id: String::from("gemini_a"),
|
||||||
label: String::from("Wing A"),
|
label: String::from("Castor"),
|
||||||
color: [1.00_f32, 0.25_f32, 0.00_f32],
|
color: [1.00_f32, 0.25_f32, 0.00_f32],
|
||||||
rep: DVector::<f64>::from_column_slice(&[0.5, 0.5, 0.0, 0.5, -0.25]),
|
rep: engine::sphere(0.5, 0.5, 0.0, 1.0),
|
||||||
constraints: BTreeSet::default()
|
constraints: BTreeSet::default()
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
let _ = assemb.try_insert_element(
|
let _ = assemb.try_insert_element(
|
||||||
Element {
|
Element {
|
||||||
id: String::from("wing_b"),
|
id: String::from("gemini_b"),
|
||||||
label: String::from("Wing B"),
|
label: String::from("Pollux"),
|
||||||
color: [0.00_f32, 0.25_f32, 1.00_f32],
|
color: [0.00_f32, 0.25_f32, 1.00_f32],
|
||||||
rep: DVector::<f64>::from_column_slice(&[-0.5, -0.5, 0.0, 0.5, -0.25]),
|
rep: engine::sphere(-0.5, -0.5, 0.0, 1.0),
|
||||||
constraints: BTreeSet::default()
|
constraints: BTreeSet::default()
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
let _ = assemb.try_insert_element(
|
let _ = assemb.try_insert_element(
|
||||||
Element {
|
Element {
|
||||||
id: String::from("central"),
|
id: String::from("ursa_major"),
|
||||||
label: String::from("Central"),
|
label: String::from("Ursa major"),
|
||||||
color: [0.75_f32, 0.75_f32, 0.75_f32],
|
color: [0.25_f32, 0.00_f32, 1.00_f32],
|
||||||
rep: DVector::<f64>::from_column_slice(&[0.0, 0.0, 0.0, 0.4, -0.625]),
|
rep: engine::sphere(-0.5, 0.5, 0.0, 0.75),
|
||||||
|
constraints: BTreeSet::default()
|
||||||
|
}
|
||||||
|
);
|
||||||
|
let _ = assemb.try_insert_element(
|
||||||
|
Element {
|
||||||
|
id: String::from("ursa_minor"),
|
||||||
|
label: String::from("Ursa minor"),
|
||||||
|
color: [0.25_f32, 1.00_f32, 0.00_f32],
|
||||||
|
rep: engine::sphere(0.5, -0.5, 0.0, 0.5),
|
||||||
|
constraints: BTreeSet::default()
|
||||||
|
}
|
||||||
|
);
|
||||||
|
let _ = assemb.try_insert_element(
|
||||||
|
Element {
|
||||||
|
id: String::from("moon_deimos"),
|
||||||
|
label: String::from("Deimos"),
|
||||||
|
color: [0.75_f32, 0.75_f32, 0.00_f32],
|
||||||
|
rep: engine::sphere(0.0, 0.15, 1.0, 0.25),
|
||||||
|
constraints: BTreeSet::default()
|
||||||
|
}
|
||||||
|
);
|
||||||
|
let _ = assemb.try_insert_element(
|
||||||
|
Element {
|
||||||
|
id: String::from("moon_phobos"),
|
||||||
|
label: String::from("Phobos"),
|
||||||
|
color: [0.00_f32, 0.75_f32, 0.50_f32],
|
||||||
|
rep: engine::sphere(0.0, -0.15, -1.0, 0.25),
|
||||||
constraints: BTreeSet::default()
|
constraints: BTreeSet::default()
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
assemb.insert_constraint(
|
assemb.insert_constraint(
|
||||||
Constraint {
|
Constraint {
|
||||||
args: (
|
args: (
|
||||||
assemb.elements_by_id.with(|elts_by_id| elts_by_id["wing_a"]),
|
assemb.elements_by_id.with(|elts_by_id| elts_by_id["gemini_a"]),
|
||||||
assemb.elements_by_id.with(|elts_by_id| elts_by_id["wing_b"])
|
assemb.elements_by_id.with(|elts_by_id| elts_by_id["gemini_b"])
|
||||||
),
|
),
|
||||||
rep: 0.5
|
rep: 0.5
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user