You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
3.3 KiB
72 lines
3.3 KiB
5 years ago
|
use std::sync::Arc;
|
||
|
use crate::canvas::*;
|
||
|
use crate::canvas::managed::handles::{CanvasFontHandle, CanvasImageHandle, CanvasTextureHandle, Handle};
|
||
|
use crate::canvas::canvas_frame::{Drawable};
|
||
|
use crate::util::vertex::{VertexTypes, TextureVertex3D, Vertex3D, ColorVertex3D};
|
||
|
use crate::drawables::sprite::Sprite;
|
||
|
|
||
|
/// Convex multi verticy polygon
|
||
|
#[derive(Debug, Clone)]
|
||
|
pub struct Polygon {
|
||
|
|
||
|
pub verts: VertexTypes,
|
||
|
|
||
|
position: (f32, f32),
|
||
|
size: (f32, f32),
|
||
|
}
|
||
|
|
||
|
/// Container class which implements drawable.
|
||
|
impl Polygon {
|
||
|
|
||
|
///
|
||
|
pub fn new(position: (f32, f32),
|
||
|
size: (f32, f32),
|
||
|
depth: u32,) -> Polygon {
|
||
|
|
||
|
let normalized_depth = (depth as f32 / 255.0);
|
||
|
|
||
|
let verts = vec![
|
||
|
ColorVertex3D{v_position: [-0.5, -0.5, normalized_depth], color: [1.0, 1.0, 0.0, 1.0] },
|
||
|
ColorVertex3D{v_position: [-1.0, 1.0, normalized_depth], color: [1.0, 1.0, 0.0, 1.0] },
|
||
|
ColorVertex3D{v_position: [-0.25, 0.0, normalized_depth], color: [1.0, 1.0, 0.0, 1.0] },
|
||
|
ColorVertex3D{v_position: [-0.25, 0.0, normalized_depth], color: [1.0, 1.0, 0.0, 1.0] },
|
||
|
ColorVertex3D{v_position: [-1.0, 1.0, normalized_depth], color: [1.0, 1.0, 0.0, 1.0] },
|
||
|
ColorVertex3D{v_position: [0.0, 0.5, normalized_depth], color: [1.0, 1.0, 0.0, 1.0] },
|
||
|
ColorVertex3D{v_position: [0.25, 0.0, normalized_depth], color: [1.0, 1.0, 0.0, 1.0] },
|
||
|
ColorVertex3D{v_position: [-1.0, 1.0, normalized_depth], color: [1.0, 1.0, 0.0, 1.0] },
|
||
|
ColorVertex3D{v_position: [0.0, 0.5, normalized_depth], color: [1.0, 1.0, 0.0, 1.0] },
|
||
|
ColorVertex3D{v_position: [0.5, -0.5, normalized_depth], color: [1.0, 1.0, 0.0, 1.0] },
|
||
|
ColorVertex3D{v_position: [-1.0, 1.0, normalized_depth], color: [1.0, 1.0, 0.0, 1.0] },
|
||
|
ColorVertex3D{v_position: [0.25, 0.0, normalized_depth], color: [1.0, 1.0, 0.0, 1.0] },
|
||
|
ColorVertex3D{v_position: [0.25, -0.5, normalized_depth], color: [1.0, 1.0, 0.0, 1.0] },
|
||
|
ColorVertex3D{v_position: [-1.0, 1.0, normalized_depth], color: [1.0, 1.0, 0.0, 1.0] },
|
||
|
ColorVertex3D{v_position: [0.5, -0.5, normalized_depth], color: [1.0, 1.0, 0.0, 1.0] },
|
||
|
ColorVertex3D{v_position: [0.25, -0.5, normalized_depth], color: [1.0, 1.0, 0.0, 1.0] },
|
||
|
ColorVertex3D{v_position: [-1.0, 1.0, normalized_depth], color: [1.0, 1.0, 0.0, 1.0] },
|
||
|
ColorVertex3D{v_position: [0.0, -0.1, normalized_depth], color: [1.0, 1.0, 0.0, 1.0] },
|
||
|
ColorVertex3D{v_position: [-0.25, -0.5, normalized_depth], color: [1.0, 1.0, 0.0, 1.0] },
|
||
|
ColorVertex3D{v_position: [-1.0, 1.0, normalized_depth], color: [1.0, 1.0, 0.0, 1.0] },
|
||
|
ColorVertex3D{v_position: [0.0, -0.1, normalized_depth], color: [1.0, 1.0, 0.0, 1.0] },
|
||
|
ColorVertex3D{v_position: [-0.5, -0.5, normalized_depth], color: [1.0, 1.0, 0.0, 1.0] },
|
||
|
ColorVertex3D{v_position: [-1.0, 1.0, normalized_depth], color: [1.0, 1.0, 0.0, 1.0] },
|
||
|
ColorVertex3D{v_position: [-0.25, -0.5, normalized_depth], color: [1.0, 1.0, 0.0, 1.0] },
|
||
|
];
|
||
|
|
||
|
|
||
|
Polygon {
|
||
|
verts: VertexTypes::ColorType(verts),
|
||
|
position: position,
|
||
|
size: size,
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
impl Drawable for Polygon {
|
||
|
fn get(&self) -> VertexTypes {
|
||
|
self.verts.clone()
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
|