Display two not textured triangles in 3D with camera with horizontal rotation
Thanks to `glium/examples/teapot` which was loading an OBJ and not having any rotation for the camera.
This commit is contained in:
@@ -0,0 +1,132 @@
|
||||
#![allow(dead_code)]
|
||||
use glium::glutin::event::{Event, StartCause};
|
||||
use glium::glutin::event_loop::{ControlFlow, EventLoop};
|
||||
use glium::vertex::VertexBufferAny;
|
||||
use glium::{self, Display};
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
pub mod camera;
|
||||
|
||||
pub enum Action {
|
||||
Stop,
|
||||
Continue,
|
||||
}
|
||||
|
||||
pub fn start_loop<F>(event_loop: EventLoop<()>, mut callback: F) -> !
|
||||
where
|
||||
F: 'static + FnMut(&Vec<Event<'_, ()>>) -> Action,
|
||||
{
|
||||
let mut events_buffer = Vec::new();
|
||||
let mut next_frame_time = Instant::now();
|
||||
event_loop.run(move |event, _, control_flow| {
|
||||
let run_callback = match event.to_static() {
|
||||
Some(Event::NewEvents(cause)) => match cause {
|
||||
StartCause::ResumeTimeReached { .. } | StartCause::Init => true,
|
||||
_ => false,
|
||||
},
|
||||
Some(event) => {
|
||||
events_buffer.push(event);
|
||||
false
|
||||
}
|
||||
None => {
|
||||
// Ignore this event.
|
||||
false
|
||||
}
|
||||
};
|
||||
|
||||
let action = if run_callback {
|
||||
let action = callback(&events_buffer);
|
||||
next_frame_time = Instant::now() + Duration::from_nanos(16666667);
|
||||
// TODO: Add back the old accumulator loop in some way
|
||||
|
||||
events_buffer.clear();
|
||||
action
|
||||
} else {
|
||||
Action::Continue
|
||||
};
|
||||
|
||||
match action {
|
||||
Action::Continue => {
|
||||
*control_flow = ControlFlow::WaitUntil(next_frame_time);
|
||||
}
|
||||
Action::Stop => *control_flow = ControlFlow::Exit,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/// Returns a vertex buffer that should be rendered as `TrianglesList`.
|
||||
pub fn load_ground(display: &Display) -> VertexBufferAny {
|
||||
#[derive(Copy, Clone)]
|
||||
struct Vertex {
|
||||
position: [f32; 3],
|
||||
normal: [f32; 3],
|
||||
texture: [f32; 2],
|
||||
}
|
||||
|
||||
implement_vertex!(Vertex, position, normal, texture);
|
||||
|
||||
let mut vertex_data = Vec::new();
|
||||
|
||||
vertex_data.push(Vertex {
|
||||
position: [0.0, 0.0, 0.0],
|
||||
normal: [0.0, 0.0, 1.0],
|
||||
texture: [0.0, 0.0],
|
||||
});
|
||||
|
||||
vertex_data.push(Vertex {
|
||||
position: [1.0, 0.0, 0.0],
|
||||
normal: [0.0, 0.0, 1.0],
|
||||
texture: [0.0, 0.0],
|
||||
});
|
||||
|
||||
vertex_data.push(Vertex {
|
||||
position: [0.0, 0.0, 1.0],
|
||||
normal: [0.0, 0.0, 1.0],
|
||||
texture: [0.0, 0.0],
|
||||
});
|
||||
|
||||
vertex_data.push(Vertex {
|
||||
position: [1.0, 0.0, 0.0],
|
||||
normal: [0.0, 0.0, 1.0],
|
||||
texture: [0.0, 0.0],
|
||||
});
|
||||
|
||||
vertex_data.push(Vertex {
|
||||
position: [0.0, 0.0, 1.0],
|
||||
normal: [0.0, 0.0, 1.0],
|
||||
texture: [0.0, 0.0],
|
||||
});
|
||||
|
||||
vertex_data.push(Vertex {
|
||||
position: [1.0, 0.0, 1.0],
|
||||
normal: [0.0, 0.0, 1.0],
|
||||
texture: [0.0, 0.0],
|
||||
});
|
||||
|
||||
/*for object in data.objects.iter() {
|
||||
for polygon in object.groups.iter().flat_map(|g| g.polys.iter()) {
|
||||
match polygon {
|
||||
obj::SimplePolygon(indices) => {
|
||||
for v in indices.iter() {
|
||||
let position = data.position[v.0];
|
||||
let texture = v.1.map(|index| data.texture[index]);
|
||||
let normal = v.2.map(|index| data.normal[index]);
|
||||
|
||||
let texture = texture.unwrap_or([0.0, 0.0]);
|
||||
let normal = normal.unwrap_or([0.0, 0.0, 0.0]);
|
||||
|
||||
vertex_data.push(Vertex {
|
||||
position,
|
||||
normal,
|
||||
texture,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
glium::vertex::VertexBuffer::new(display, &vertex_data)
|
||||
.unwrap()
|
||||
.into()
|
||||
}
|
||||
Reference in New Issue
Block a user