added SceneObj
parent
452d1cb1ea
commit
2229e3e742
|
@ -34,6 +34,9 @@ use std::ffi::{CString, CStr};
|
|||
mod shader;
|
||||
mod model;
|
||||
mod camera;
|
||||
mod scene;
|
||||
|
||||
|
||||
fn main() {
|
||||
|
||||
let (gl, shader_version, window, mut events_loop, _context) = {
|
||||
|
@ -96,11 +99,6 @@ fn main() {
|
|||
Pitch: -20.0,
|
||||
..camera::Camera::default()
|
||||
};
|
||||
|
||||
let mut firstMouse = true;
|
||||
let mut lastX: f32 = SCR_WIDTH as f32 / 2.0;
|
||||
let mut lastY: f32 = SCR_HEIGHT as f32 / 2.0;
|
||||
|
||||
// timing
|
||||
let mut deltaTime: f32; // time between current frame and last frame
|
||||
let mut lastFrame: f32 = 0.0;
|
||||
|
|
|
@ -0,0 +1,97 @@
|
|||
|
||||
use crate::model::Model;
|
||||
use crate::camera::Camera;
|
||||
use crate::shader::shader;
|
||||
use std::sync::Arc;
|
||||
use std::rc::Rc;
|
||||
|
||||
|
||||
use imgui_glow_renderer::AutoRenderer;
|
||||
use imgui_sdl2_support::SdlPlatform;
|
||||
|
||||
use cgmath::{Matrix4, vec3, Point3, Deg, perspective};
|
||||
use cgmath::prelude::*;
|
||||
|
||||
const MODELS: [&str; 3]= ["resources/models/TestCarModel/CarW4.obj", "resources/models/TestCarModel/CarW1.obj",
|
||||
"resources/models/TestCarModel/CarW0.obj"];
|
||||
|
||||
/// XXX this is temporary, thus the name
|
||||
pub struct tempData {
|
||||
pub projection: Matrix4<f32>,
|
||||
pub spinSpeed: f32,
|
||||
pub current_rad: f32,
|
||||
pub currentFrame: f32,
|
||||
pub deltaTime: f32,
|
||||
pub lastFrame: f32,
|
||||
}
|
||||
|
||||
|
||||
|
||||
struct Scene {
|
||||
gl: Arc<glow::Context>,
|
||||
pub Car: Model,
|
||||
camera: Camera,
|
||||
imgui: imgui::Context,
|
||||
imgui_rend: AutoRenderer,
|
||||
imgui_plat: SdlPlatform,
|
||||
shaders: Vec<Rc<shader>>,
|
||||
time: std::time::Instant,
|
||||
tempData: tempData,
|
||||
}
|
||||
|
||||
impl Scene{
|
||||
fn new(gl: Arc<glow::Context>) -> Scene
|
||||
{
|
||||
let Car = Model::new(MODELS[0], Arc::clone(&gl));
|
||||
|
||||
let shader = Rc::new(shader::new("model", Arc::clone(&gl)));
|
||||
|
||||
let time = std::time::Instant::now();
|
||||
|
||||
let camera = Camera {
|
||||
Position: Point3::new(0.0, 0.40, 1.0),
|
||||
Pitch: -20.0,
|
||||
..Camera::default()
|
||||
};
|
||||
|
||||
let tempData = tempData {
|
||||
projection: perspective(Deg(45.0), 1600.0/ 900.0, 0.1, 100.0),
|
||||
spinSpeed: 1.0,
|
||||
current_rad: 1.0,
|
||||
currentFrame: 0.0,
|
||||
deltaTime: 0.0,
|
||||
lastFrame: 0.0
|
||||
|
||||
};
|
||||
|
||||
let mut imgui = imgui::Context::create();
|
||||
|
||||
imgui
|
||||
.fonts()
|
||||
.add_font(&[imgui::FontSource::DefaultFontData {config: None}]);
|
||||
|
||||
let mut platform = SdlPlatform::init(&mut imgui);
|
||||
let mut renderer = match AutoRenderer::initialize(gl.clone(), &mut imgui)
|
||||
{
|
||||
Ok(ret) => ret,
|
||||
Err(s) => panic!("Failed to initialize Imgui Platform Renderer: {}", s),
|
||||
};
|
||||
|
||||
Scene{
|
||||
gl,
|
||||
Car,
|
||||
camera,
|
||||
imgui,
|
||||
imgui_rend: renderer,
|
||||
imgui_plat: platform,
|
||||
shaders: vec![shader],
|
||||
time,
|
||||
tempData,
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue