extern crate ami;
extern crate awi;
use std::cmp::Ordering;
pub use awi::{
afi, afi::Graphic, Input, Window, WindowConnection
};
pub use ami::{ Mat4, Vec3, Vec4, BBox, IDENTITY };
pub trait Display {
fn color(&mut self, color: (f32, f32, f32)) -> ();
fn fog(&mut self, fog: Option<(f32, f32)>) -> ();
fn update(&mut self) -> Option<Input>;
fn camera(&mut self, position: (f32, f32, f32),
rotation: (f32, f32, f32)) -> ();
fn model(&mut self, vertices: &[f32], fans: Vec<(u32, u32)>) -> Model;
fn texture(&mut self, graphic: &Graphic) -> Texture;
fn gradient(&mut self, colors: &[f32]) -> Gradient;
fn texcoords(&mut self, texcoords: &[f32]) -> TexCoords;
fn set_texture(&mut self, texture: &mut Texture, pixels: &[u32])
-> ();
fn shape_solid(&mut self, model: &Model, transform: Mat4,
color: [f32; 4], blending: bool, fog: bool, camera: bool)
-> Shape;
fn shape_gradient(&mut self, model: &Model, transform: Mat4,
gradient: Gradient, blending: bool, fog: bool, camera: bool)
-> Shape;
fn shape_texture(&mut self, model: &Model, transform: Mat4,
texture: &Texture, tc: TexCoords, blending: bool,
fog: bool, camera: bool) -> Shape;
fn shape_faded(&mut self, model: &Model, transform: Mat4,
texture: &Texture, tc: TexCoords, alpha: f32,
fog: bool, camera: bool) -> Shape;
fn shape_tinted(&mut self, model: &Model, transform: Mat4,
texture: &Texture, tc: TexCoords, tint: [f32; 4],
blending: bool, fog: bool, camera: bool) -> Shape;
fn shape_complex(&mut self, model: &Model, transform: Mat4,
texture: &Texture, tc: TexCoords,
gradient: Gradient, blending: bool,
fog: bool, camera: bool) -> Shape;
fn transform(&mut self, shape: &Shape, transform: Mat4);
fn resize(&mut self, wh: (u32, u32)) -> ();
fn wh(&self) -> (u32, u32);
}
#[derive(Clone)]
pub enum ShapeHandle {
Alpha(u32),
Opaque(u32),
Gui(u32),
}
pub struct Shape(ShapeHandle);
#[derive(Copy, Clone)]
pub struct Model(pub usize);
#[derive(Copy, Clone)]
pub struct Gradient(pub usize);
#[derive(Copy, Clone)]
pub struct TexCoords(pub usize);
pub struct Texture(pub usize);
pub fn new_shape(i: ShapeHandle) -> Shape {
Shape(i)
}
pub fn get_shape(s: &Shape) -> ShapeHandle {
s.0.clone()
}
pub fn projection(ratio: f32, fov: f32) -> Mat4 {
let scale = (fov * 0.5 * ::std::f32::consts::PI / 180.).tan().recip();
let yscale = scale * ratio;
Mat4([
scale, 0., 0., 0.,
0., yscale, 0., 0.,
0., 0., 1., 1.,
0., 0., 0., 1.,
])
}
pub trait Point {
fn point(&self) -> ami::Vec3;
}
pub fn zsort<T: Point>(sorted: &mut Vec<u32>, points: &Vec<T>, nr: bool,
position: Vec3)
{
sorted.sort_unstable_by(|a, b| {
let p1 = points[*a as usize].point() - position;
let p2 = points[*b as usize].point() - position;
if p1.mag() > p2.mag() {
if nr { Ordering::Greater } else { Ordering::Less }
} else if p1.mag() < p2.mag() {
if nr { Ordering::Less } else { Ordering::Greater }
} else {
Ordering::Equal
}
});
}