it runs
This commit is contained in:
@@ -36,7 +36,7 @@ fn offset<T>(n: u32) -> *const c_void {
|
||||
}
|
||||
// ptr::null()
|
||||
|
||||
pub unsafe fn draw_scene(node: &SceneNode,
|
||||
unsafe fn draw_scene(node: &SceneNode,
|
||||
view_projection_matrix: &glm::Mat4,
|
||||
mut transformation_so_far: glm::Mat4,
|
||||
shader: &Shader,
|
||||
@@ -156,12 +156,12 @@ unsafe fn create_vao(vertices: &Vec<f32>, indices: &Vec<u32>, colors: &Vec<f32>,
|
||||
}
|
||||
|
||||
pub struct World {
|
||||
meshes: HashMap<Nodes, Mesh>,
|
||||
nodes: HashMap<Nodes, SceneNode>,
|
||||
pub meshes: HashMap<Nodes, Mesh>,
|
||||
pub nodes: HashMap<Nodes, ManuallyDrop<Pin<Box<SceneNode>>>>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Eq, PartialEq, Hash)]
|
||||
enum Nodes {
|
||||
pub enum Nodes {
|
||||
LunarSurface=0,
|
||||
HeliBody=1,
|
||||
HeliDoor=2,
|
||||
@@ -194,11 +194,11 @@ pub fn load_models() -> HashMap<Nodes, Mesh> {
|
||||
]);
|
||||
}
|
||||
|
||||
pub fn setup_scene_graph(meshes: HashMap<Nodes, Mesh>) -> HashMap<Nodes, ManuallyDrop<Pin<Box<SceneNode>>>> {
|
||||
pub fn setup_scene_graph(meshes: &HashMap<Nodes, Mesh>) -> HashMap<Nodes, ManuallyDrop<Pin<Box<SceneNode>>>> {
|
||||
let mut nodes = HashMap::new();
|
||||
|
||||
// Create all nodes
|
||||
for (node, mesh) in &meshes {
|
||||
for (node, mesh) in meshes {
|
||||
nodes.insert(*node, SceneNode::from_vao(*node as u32, mesh.index_count));
|
||||
}
|
||||
|
||||
|
||||
@@ -86,7 +86,6 @@ fn main() {
|
||||
println!("GLSL\t: {}", util::get_gl_string(gl::SHADING_LANGUAGE_VERSION));
|
||||
}
|
||||
|
||||
|
||||
let mut transformation: glm::Mat4;
|
||||
let perspective: glm::Mat4 = glm::perspective(
|
||||
window_aspect_ratio,
|
||||
@@ -95,6 +94,13 @@ fn main() {
|
||||
1000.0f32
|
||||
);
|
||||
|
||||
let meshes = draw::load_models();
|
||||
let nodes = draw::setup_scene_graph(&meshes);
|
||||
let mut world = draw::World {
|
||||
meshes: meshes,
|
||||
nodes: nodes
|
||||
};
|
||||
|
||||
let mut camera_position: glm::Vec3 = glm::vec3(0.0, 0.0, 0.0);
|
||||
let translation_speed = 30.0f32;
|
||||
let rotation_speed = 1.5f32;
|
||||
@@ -220,6 +226,8 @@ fn main() {
|
||||
// Clear the color and depth buffers
|
||||
gl::ClearColor(0.40, 0.55, 1.0, 1.0); // night sky
|
||||
gl::Clear(gl::COLOR_BUFFER_BIT | gl::DEPTH_BUFFER_BIT);
|
||||
|
||||
draw::update(elapsed, &mut world, perspective, transformation, &simple_shader);
|
||||
|
||||
// Display the new color buffer on the display
|
||||
context.swap_buffers().unwrap(); // we use "double buffering" to avoid artifacts
|
||||
|
||||
Reference in New Issue
Block a user