mirror of https://github.com/Leinnan/doppler.git
Start creating client
This commit is contained in:
parent
dd6b42e55d
commit
3cea406fd9
|
|
@ -0,0 +1,61 @@
|
||||||
|
|
||||||
|
use crate::gaia::camera::*;
|
||||||
|
use crate::gaia::consts;
|
||||||
|
use crate::gaia::*;
|
||||||
|
#[macro_use]
|
||||||
|
use crate::gaia::macros;
|
||||||
|
use crate::gaia::engine::Engine;
|
||||||
|
use crate::gaia::client::Client;
|
||||||
|
use cgmath::{perspective, vec3, Deg, Matrix4, Point3, Rad, Vector3};
|
||||||
|
macro_rules! c_str {
|
||||||
|
($literal:expr) => {
|
||||||
|
std::ffi::CStr::from_bytes_with_nul_unchecked(concat!($literal, "\0").as_bytes())
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct ExampleClient {
|
||||||
|
model: model::Model,
|
||||||
|
camera: Camera,
|
||||||
|
shader: shader::Shader,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ExampleClient {
|
||||||
|
pub fn create() -> ExampleClient {
|
||||||
|
ExampleClient {
|
||||||
|
model: model::Model::new("resources/objects/nanosuit/nanosuit.obj"),
|
||||||
|
camera: Camera {
|
||||||
|
position: Point3::new(0.0, 0.0, 3.0),
|
||||||
|
..Camera::default()
|
||||||
|
},
|
||||||
|
shader: shader::Shader::from_file(
|
||||||
|
"resources/shaders/model_loading.vs",
|
||||||
|
"resources/shaders/model_loading.fs",
|
||||||
|
),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Client for ExampleClient {
|
||||||
|
unsafe fn draw(&mut self) {
|
||||||
|
self.shader.useProgram();
|
||||||
|
|
||||||
|
// view/projection transformations
|
||||||
|
let projection: Matrix4<f32> = perspective(
|
||||||
|
Deg(self.camera.Zoom),
|
||||||
|
consts::SCR_WIDTH as f32 / consts::SCR_HEIGHT as f32,
|
||||||
|
0.1,
|
||||||
|
100.0,
|
||||||
|
);
|
||||||
|
let view = self.camera.get_view_matrix();
|
||||||
|
self.shader.setMat4(c_str!("projection"), &projection);
|
||||||
|
self.shader.setMat4(c_str!("view"), &view);
|
||||||
|
|
||||||
|
let mut m = Matrix4::<f32>::from_translation(vec3(3.0, -1.75, -1.25)); // translate it down so it's at the center of the scene
|
||||||
|
m = m * Matrix4::from_scale(0.2); // it's a bit too big for our scene, so scale it down
|
||||||
|
self.shader.setMat4(c_str!("model"), &m);
|
||||||
|
self.model.Draw(&self.shader);
|
||||||
|
}
|
||||||
|
fn update(&mut self, engine: &mut Engine) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
use crate::gaia::engine::Engine;
|
||||||
|
|
||||||
|
pub trait Client {
|
||||||
|
fn update(&mut self, engine: &mut Engine);
|
||||||
|
// fn draw<T>(&mut self, engine: &mut Engine<T>) where T: Client;
|
||||||
|
unsafe fn draw(&mut self);
|
||||||
|
}
|
||||||
|
|
@ -2,6 +2,8 @@ use crate::gaia::bg_info::BgInfo;
|
||||||
use crate::gaia::camera::*;
|
use crate::gaia::camera::*;
|
||||||
use crate::gaia::consts;
|
use crate::gaia::consts;
|
||||||
use crate::gaia::*;
|
use crate::gaia::*;
|
||||||
|
use crate::example_client::ExampleClient;
|
||||||
|
use crate::gaia::client::Client;
|
||||||
use cgmath::{perspective, vec3, Deg, Matrix4, Point3, Rad, Vector3};
|
use cgmath::{perspective, vec3, Deg, Matrix4, Point3, Rad, Vector3};
|
||||||
use imgui_glfw_rs::glfw;
|
use imgui_glfw_rs::glfw;
|
||||||
use imgui_glfw_rs::glfw::{Action, Context, Key};
|
use imgui_glfw_rs::glfw::{Action, Context, Key};
|
||||||
|
|
@ -20,6 +22,7 @@ pub struct Engine {
|
||||||
pub imgui_glfw: ImguiGLFW,
|
pub imgui_glfw: ImguiGLFW,
|
||||||
pub shader: shader::Shader,
|
pub shader: shader::Shader,
|
||||||
pub models: Vec<model::Model>,
|
pub models: Vec<model::Model>,
|
||||||
|
pub client: Box<dyn Client>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Engine {
|
impl Engine {
|
||||||
|
|
@ -91,6 +94,7 @@ impl Engine {
|
||||||
m.Draw(&self.shader);
|
m.Draw(&self.shader);
|
||||||
i = i + 1;
|
i = i + 1;
|
||||||
}
|
}
|
||||||
|
self.client.draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
// glfw: swap buffers and poll IO events (keys pressed/released, mouse moved etc.)
|
// glfw: swap buffers and poll IO events (keys pressed/released, mouse moved etc.)
|
||||||
|
|
@ -247,10 +251,6 @@ impl Default for Engine {
|
||||||
unsafe{gl::Enable(gl::DEPTH_TEST);}
|
unsafe{gl::Enable(gl::DEPTH_TEST);}
|
||||||
|
|
||||||
Engine {
|
Engine {
|
||||||
camera: Camera {
|
|
||||||
position: Point3::new(0.0, 0.0, 3.0),
|
|
||||||
..Camera::default()
|
|
||||||
},
|
|
||||||
bg_info: BgInfo::default(),
|
bg_info: BgInfo::default(),
|
||||||
window: window,
|
window: window,
|
||||||
window_size: (consts::SCR_WIDTH as f32, consts::SCR_HEIGHT as f32),
|
window_size: (consts::SCR_WIDTH as f32, consts::SCR_HEIGHT as f32),
|
||||||
|
|
@ -258,8 +258,13 @@ impl Default for Engine {
|
||||||
glfw: glfw,
|
glfw: glfw,
|
||||||
imgui: imgui,
|
imgui: imgui,
|
||||||
imgui_glfw: imgui_glfw,
|
imgui_glfw: imgui_glfw,
|
||||||
|
camera: Camera {
|
||||||
|
position: Point3::new(0.0, 0.0, 3.0),
|
||||||
|
..Camera::default()
|
||||||
|
},
|
||||||
shader: shader::Shader::default(),
|
shader: shader::Shader::default(),
|
||||||
models: vec![],
|
models: vec![],
|
||||||
|
client: Box::new(ExampleClient::create()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
pub mod camera;
|
pub mod camera;
|
||||||
|
pub mod client;
|
||||||
pub mod consts;
|
pub mod consts;
|
||||||
pub mod utils;
|
pub mod utils;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,9 @@ extern crate image;
|
||||||
extern crate imgui_glfw_rs;
|
extern crate imgui_glfw_rs;
|
||||||
use human_panic::setup_panic;
|
use human_panic::setup_panic;
|
||||||
mod gaia;
|
mod gaia;
|
||||||
|
mod example_client;
|
||||||
use crate::gaia::engine::Engine;
|
use crate::gaia::engine::Engine;
|
||||||
|
use crate::example_client::ExampleClient;
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
setup_panic!();
|
setup_panic!();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue