Fix points ordering
This commit is contained in:
parent
87cf72bbe5
commit
9e9254b04c
2 changed files with 20 additions and 1 deletions
|
@ -29,7 +29,7 @@ impl GlobalState {
|
||||||
window_extent: Vec2::default(),
|
window_extent: Vec2::default(),
|
||||||
polygon_started: false,
|
polygon_started: false,
|
||||||
view_2d: true,
|
view_2d: true,
|
||||||
extrusion_height: 20.0,
|
extrusion_height: 50.0,
|
||||||
|
|
||||||
offscreen_image,
|
offscreen_image,
|
||||||
offscreen_image_size,
|
offscreen_image_size,
|
||||||
|
|
|
@ -145,6 +145,8 @@ impl Polygon {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.order_points();
|
||||||
|
|
||||||
// create triangle mesh
|
// create triangle mesh
|
||||||
let triangle_mesh = self.create_triangulated_mesh();
|
let triangle_mesh = self.create_triangulated_mesh();
|
||||||
|
|
||||||
|
@ -272,6 +274,23 @@ impl Polygon {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn order_points(&mut self) {
|
||||||
|
let n = Vec3::Z;
|
||||||
|
|
||||||
|
let v1 = (self.points[0] - self.points[1]).normalize().extend(0.0);
|
||||||
|
let v2 = (self.points[1] - self.points[2]).normalize().extend(0.0);
|
||||||
|
|
||||||
|
let c1 = v1.cross(n);
|
||||||
|
|
||||||
|
let d = c1.dot(v2);
|
||||||
|
|
||||||
|
// dot product is bigger than 0 if normal and connection line are facing in the same direction
|
||||||
|
// reverse the order of points, thus the face of the 3d object is directed to the outside
|
||||||
|
if d >= 0.0 {
|
||||||
|
self.points = self.points.iter().cloned().rev().collect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn check_all_for_proximity(&self, point: Vec2) -> bool {
|
fn check_all_for_proximity(&self, point: Vec2) -> bool {
|
||||||
self.points
|
self.points
|
||||||
.iter()
|
.iter()
|
||||||
|
|
Loading…
Reference in a new issue