drawing circles in glium

This commit is contained in:
Dustin Carlino 2019-01-23 09:49:31 -08:00
parent 5dc8542856
commit ca00dda8be
2 changed files with 28 additions and 22 deletions

View File

@ -66,7 +66,7 @@
## Switch to OpenGL (for speed) ## Switch to OpenGL (for speed)
- get things running again - get things running again
- circles, arrows, other disabled things - arrows
- forking - forking
- render text - render text
- colors still seem off - colors still seem off

View File

@ -24,7 +24,7 @@ pub use crate::text::Text;
pub use crate::text_box::TextBox; pub use crate::text_box::TextBox;
pub use crate::top_menu::{Folder, TopMenu}; pub use crate::top_menu::{Folder, TopMenu};
pub use crate::wizard::{Wizard, WrappedWizard}; pub use crate::wizard::{Wizard, WrappedWizard};
use geom::Pt2D; use geom::{Angle, Circle, Line, Polygon, Pt2D, Triangle};
use glium::{implement_vertex, uniform, Surface}; use glium::{implement_vertex, uniform, Surface};
// TODO Not super happy about exposing this; fork_screenspace for external callers should be // TODO Not super happy about exposing this; fork_screenspace for external callers should be
@ -153,17 +153,17 @@ impl<'a> GfxCtx<'a> {
// Use graphics::Line internally for now, but make it easy to switch to something else by // Use graphics::Line internally for now, but make it easy to switch to something else by
// picking this API now. // picking this API now.
pub fn draw_line(&mut self, color: Color, thickness: f64, line: &geom::Line) { pub fn draw_line(&mut self, color: Color, thickness: f64, line: &Line) {
self.draw_polygon(color, &line.to_polyline().make_polygons(thickness)); self.draw_polygon(color, &line.to_polyline().make_polygons(thickness));
} }
pub fn draw_rounded_line(&mut self, color: Color, thickness: f64, line: &geom::Line) { pub fn draw_rounded_line(&mut self, color: Color, thickness: f64, line: &Line) {
self.draw_line(color, thickness, line); self.draw_line(color, thickness, line);
self.draw_circle(color, &geom::Circle::new(line.pt1(), thickness / 2.0)); self.draw_circle(color, &Circle::new(line.pt1(), thickness / 2.0));
self.draw_circle(color, &geom::Circle::new(line.pt2(), thickness / 2.0)); self.draw_circle(color, &Circle::new(line.pt2(), thickness / 2.0));
} }
pub fn draw_arrow(&mut self, color: Color, thickness: f64, line: &geom::Line) { pub fn draw_arrow(&mut self, color: Color, thickness: f64, line: &Line) {
// TODO Raw method doesn't work yet in all cases... // TODO Raw method doesn't work yet in all cases...
/*graphics::Line::new_round(color.0, thickness).draw_arrow( /*graphics::Line::new_round(color.0, thickness).draw_arrow(
[ [
@ -184,7 +184,7 @@ impl<'a> GfxCtx<'a> {
let triangle_height = (head_size / 2.0).sqrt() * si::M; let triangle_height = (head_size / 2.0).sqrt() * si::M;
self.draw_polygon( self.draw_polygon(
color, color,
&geom::Polygon::new(&vec![ &Polygon::new(&vec![
//line.pt2(), //line.pt2(),
//line.pt2().project_away(head_size, angle.rotate_degs(-135.0)), //line.pt2().project_away(head_size, angle.rotate_degs(-135.0)),
line.reverse() line.reverse()
@ -202,7 +202,7 @@ impl<'a> GfxCtx<'a> {
); );
self.draw_polygon( self.draw_polygon(
color, color,
&geom::Polygon::new(&vec![ &Polygon::new(&vec![
line.pt2(), line.pt2(),
line.pt2() line.pt2()
.project_away(head_size, angle.rotate_degs(-135.0)), .project_away(head_size, angle.rotate_degs(-135.0)),
@ -211,7 +211,7 @@ impl<'a> GfxCtx<'a> {
);*/ );*/
} }
pub fn draw_polygon(&mut self, color: Color, poly: &geom::Polygon) { pub fn draw_polygon(&mut self, color: Color, poly: &Polygon) {
let mut vertices: Vec<Vertex> = Vec::new(); let mut vertices: Vec<Vertex> = Vec::new();
for tri in &poly.triangles { for tri in &poly.triangles {
vertices.push(Vertex { vertices.push(Vertex {
@ -236,17 +236,23 @@ impl<'a> GfxCtx<'a> {
.unwrap(); .unwrap();
} }
pub fn draw_circle(&mut self, color: Color, circle: &geom::Circle) { pub fn draw_circle(&mut self, color: Color, circle: &Circle) {
/*graphics::Ellipse::new(color.0).draw( let num_triangles = 60;
[
circle.center.x() - circle.radius, let mut triangles: Vec<Triangle> = Vec::new();
circle.center.y() - circle.radius, for i in 0..num_triangles {
2.0 * circle.radius, triangles.push(Triangle {
2.0 * circle.radius, pt1: circle.center,
], pt2: circle.center.project_away(
&self.ctx.draw_state, circle.radius,
self.ctx.transform, Angle::new_degs((i as f64) / (num_triangles as f64) * 360.0),
self.gfx, ),
);*/ pt3: circle.center.project_away(
circle.radius,
Angle::new_degs(((i + 1) as f64) / (num_triangles as f64) * 360.0),
),
});
}
self.draw_polygon(color, &Polygon { triangles });
} }
} }