Added center and scale
This commit is contained in:
parent
53137b9d89
commit
b42abd0325
12
src/model.rs
12
src/model.rs
|
@ -406,4 +406,16 @@ impl Model {
|
|||
(avg, sd)
|
||||
|
||||
}
|
||||
|
||||
/// Centers and scales the model.
|
||||
pub fn center_and_scale(&mut self) {
|
||||
let bbox = self.bounding_box();
|
||||
let center = (bbox.min() + bbox.max()) / 2.0;
|
||||
let size = (bbox.max() - bbox.min()).norm();
|
||||
|
||||
for vertex in &mut self.vertices {
|
||||
*vertex -= center;
|
||||
*vertex /= size;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,6 +57,8 @@ fn main() {
|
|||
}
|
||||
}
|
||||
|
||||
model.center_and_scale();
|
||||
|
||||
let mut events_loop = EventsLoop::new();
|
||||
let window = WindowBuilder::new().with_visibility(false);
|
||||
let context = glutin::ContextBuilder::new().with_depth_buffer(24);
|
||||
|
|
Loading…
Reference in New Issue