Added center and scale

This commit is contained in:
Thomas Forgione 2018-04-12 09:44:32 +02:00
parent 53137b9d89
commit b42abd0325
No known key found for this signature in database
GPG Key ID: C75CD416BD1FFCE1
2 changed files with 14 additions and 0 deletions

View File

@ -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;
}
}
}

View File

@ -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);