Map basics

This commit is contained in:
Piotr Siuszko 2021-09-12 00:17:50 +02:00
parent 294c687d5d
commit 35befda242
11 changed files with 391 additions and 104 deletions

52
Cargo.lock generated
View File

@ -1,5 +1,7 @@
# This file is automatically @generated by Cargo. # This file is automatically @generated by Cargo.
# It is not intended for manual editing. # It is not intended for manual editing.
version = 3
[[package]] [[package]]
name = "ab_glyph_rasterizer" name = "ab_glyph_rasterizer"
version = "0.1.4" version = "0.1.4"
@ -322,6 +324,7 @@ dependencies = [
"log", "log",
"serde", "serde",
"serde_json", "serde_json",
"serde_yaml",
"simple-logging", "simple-logging",
"tobj", "tobj",
] ]
@ -339,6 +342,12 @@ version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650" checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650"
[[package]]
name = "dtoa"
version = "0.4.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56899898ce76aaf4a0f24d914c97ea6ed976d42fec6ad33fcbb0a1103e07b2b0"
[[package]] [[package]]
name = "fnv" name = "fnv"
version = "1.0.7" version = "1.0.7"
@ -468,6 +477,12 @@ dependencies = [
"gl_generator", "gl_generator",
] ]
[[package]]
name = "hashbrown"
version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e"
[[package]] [[package]]
name = "ident_case" name = "ident_case"
version = "1.0.1" version = "1.0.1"
@ -547,6 +562,16 @@ dependencies = [
"winit", "winit",
] ]
[[package]]
name = "indexmap"
version = "1.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc633605454125dec4b66843673f01c7df2b89479b32e0ed634e43a91cff62a5"
dependencies = [
"autocfg",
"hashbrown",
]
[[package]] [[package]]
name = "inline_tweak" name = "inline_tweak"
version = "1.0.8" version = "1.0.8"
@ -640,6 +665,12 @@ dependencies = [
"winapi 0.3.9", "winapi 0.3.9",
] ]
[[package]]
name = "linked-hash-map"
version = "0.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fb9b38af92608140b86b693604b9ffcc5824240a484d1ecd4795bacb2fe88f3"
[[package]] [[package]]
name = "lock_api" name = "lock_api"
version = "0.4.3" version = "0.4.3"
@ -1108,6 +1139,18 @@ dependencies = [
"serde", "serde",
] ]
[[package]]
name = "serde_yaml"
version = "0.8.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d8c608a35705a5d3cdc9fbe403147647ff34b921f8e833e49306df898f9b20af"
dependencies = [
"dtoa",
"indexmap",
"serde",
"yaml-rust",
]
[[package]] [[package]]
name = "shared_library" name = "shared_library"
version = "0.1.9" version = "0.1.9"
@ -1451,3 +1494,12 @@ name = "xml-rs"
version = "0.8.3" version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b07db065a5cf61a7e4ba64f29e67db906fb1787316516c4e6e5ff0fea1efcd8a" checksum = "b07db065a5cf61a7e4ba64f29e67db906fb1787316516c4e6e5ff0fea1efcd8a"
[[package]]
name = "yaml-rust"
version = "0.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56c1936c4cc7a1c9ab21a1ebb602eb942ba868cbd44a99cb7cdc5892335e1c85"
dependencies = [
"linked-hash-map",
]

50
doppler/Cargo.lock generated
View File

@ -324,6 +324,7 @@ dependencies = [
"log", "log",
"serde", "serde",
"serde_json", "serde_json",
"serde_yaml",
"simple-logging", "simple-logging",
"tobj", "tobj",
] ]
@ -334,6 +335,12 @@ version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650" checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650"
[[package]]
name = "dtoa"
version = "0.4.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56899898ce76aaf4a0f24d914c97ea6ed976d42fec6ad33fcbb0a1103e07b2b0"
[[package]] [[package]]
name = "fnv" name = "fnv"
version = "1.0.7" version = "1.0.7"
@ -463,6 +470,12 @@ dependencies = [
"gl_generator", "gl_generator",
] ]
[[package]]
name = "hashbrown"
version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e"
[[package]] [[package]]
name = "ident_case" name = "ident_case"
version = "1.0.1" version = "1.0.1"
@ -541,6 +554,16 @@ dependencies = [
"winit", "winit",
] ]
[[package]]
name = "indexmap"
version = "1.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc633605454125dec4b66843673f01c7df2b89479b32e0ed634e43a91cff62a5"
dependencies = [
"autocfg",
"hashbrown",
]
[[package]] [[package]]
name = "inline_tweak" name = "inline_tweak"
version = "1.0.8" version = "1.0.8"
@ -634,6 +657,12 @@ dependencies = [
"winapi 0.3.9", "winapi 0.3.9",
] ]
[[package]]
name = "linked-hash-map"
version = "0.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fb9b38af92608140b86b693604b9ffcc5824240a484d1ecd4795bacb2fe88f3"
[[package]] [[package]]
name = "lock_api" name = "lock_api"
version = "0.4.5" version = "0.4.5"
@ -1119,6 +1148,18 @@ dependencies = [
"serde", "serde",
] ]
[[package]]
name = "serde_yaml"
version = "0.8.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d8c608a35705a5d3cdc9fbe403147647ff34b921f8e833e49306df898f9b20af"
dependencies = [
"dtoa",
"indexmap",
"serde",
"yaml-rust",
]
[[package]] [[package]]
name = "shared_library" name = "shared_library"
version = "0.1.9" version = "0.1.9"
@ -1462,3 +1503,12 @@ name = "xml-rs"
version = "0.8.3" version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b07db065a5cf61a7e4ba64f29e67db906fb1787316516c4e6e5ff0fea1efcd8a" checksum = "b07db065a5cf61a7e4ba64f29e67db906fb1787316516c4e6e5ff0fea1efcd8a"
[[package]]
name = "yaml-rust"
version = "0.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56c1936c4cc7a1c9ab21a1ebb602eb942ba868cbd44a99cb7cdc5892335e1c85"
dependencies = [
"linked-hash-map",
]

View File

@ -20,6 +20,7 @@ image2 = { git = "https://github.com/Leinnan/image2-rs", branch="legacy", defaul
glutin = "0.26.0" glutin = "0.26.0"
serde = { version = "1.0.117", features = ["derive"] } serde = { version = "1.0.117", features = ["derive"] }
serde_json = "1.0.59" serde_json = "1.0.59"
serde_yaml = "0.8"
[features] [features]
default = ["imgui_inspect"] default = ["imgui_inspect"]

View File

@ -31,20 +31,19 @@ impl AssetsCache {
for line in lines { for line in lines {
let mut splitted = line.split_whitespace(); let mut splitted = line.split_whitespace();
let id = splitted.next();
let path = splitted.next(); let path = splitted.next();
if id.is_none() || path.is_none() || self.has_model(&path.unwrap()) { if path.is_none() || self.has_model(&path.unwrap()) {
error!("Skip wrong line: {}", line); error!("Skip wrong line: {}", line);
continue; continue;
} }
let texture = splitted.next(); let texture = splitted.next();
self.load_model_ext(path.unwrap(), texture); self.load_model_ext(path.unwrap(), texture);
info!("Added model {} from path {}", id.unwrap(), path.unwrap()); info!("Added model from path {}", path.unwrap());
} }
} }
pub fn has_model(&self, path: &str) -> bool { pub fn has_model(&self, path: &str) -> bool {
self.models.contains_key(&Self::to_hash(path)) self.models.contains_key(&Self::path_hash(path))
} }
pub fn get_model(&mut self, path: &str) -> Model { pub fn get_model(&mut self, path: &str) -> Model {
@ -52,7 +51,7 @@ impl AssetsCache {
} }
pub fn get_model_ext(&mut self, path: &str, diff_texture: Option<&str>) -> Model { pub fn get_model_ext(&mut self, path: &str, diff_texture: Option<&str>) -> Model {
match self.models.get(&Self::to_hash(path)) { match self.models.get(&Self::path_hash(path)) {
Some(model) => model.clone(), Some(model) => model.clone(),
None => { None => {
self.load_model_ext(path, diff_texture); self.load_model_ext(path, diff_texture);
@ -61,15 +60,22 @@ impl AssetsCache {
} }
} }
pub fn get_model_by_hash(&mut self, hash: &u64) -> Option<Model> {
match self.models.get(hash) {
Some(model) => Some(model.clone()),
None => None
}
}
fn load_model_ext(&mut self, path: &str, diff_texture: Option<&str>) { fn load_model_ext(&mut self, path: &str, diff_texture: Option<&str>) {
let hash = Self::to_hash(path); let hash = Self::path_hash(path);
info!("Loading model: {}({})", path, hash); info!("Loading model: {}({})", path, hash);
let model = Model::new_ext(path, diff_texture, self); let model = Model::new_ext(path, diff_texture, self);
self.models.insert(hash, model); self.models.insert(hash, model);
} }
pub fn get_material_texture(&mut self, dir: &str, path: &str, type_name: &str) -> Texture { pub fn get_material_texture(&mut self, dir: &str, path: &str, type_name: &str) -> Texture {
match self.textures.get(&Self::to_hash(path)) { match self.textures.get(&Self::path_hash(path)) {
Some(texture) => texture.clone(), Some(texture) => texture.clone(),
None => { None => {
let directory: String = dir.into(); let directory: String = dir.into();
@ -78,13 +84,13 @@ impl AssetsCache {
type_: type_name.into(), type_: type_name.into(),
path: path.into(), path: path.into(),
}; };
self.textures.insert(Self::to_hash(path), texture.clone()); self.textures.insert(Self::path_hash(path), texture.clone());
texture texture
} }
} }
} }
fn to_hash(path: &str) -> u64 { pub fn path_hash(path: &str) -> u64 {
let mut hasher = DefaultHasher::new(); let mut hasher = DefaultHasher::new();
path.hash(&mut hasher); path.hash(&mut hasher);
hasher.finish() hasher.finish()

View File

@ -3,6 +3,7 @@
#[cfg(feature = "imgui_inspect")] #[cfg(feature = "imgui_inspect")]
use crate::imgui_helper::*; use crate::imgui_helper::*;
use cgmath; use cgmath;
use serde::{Deserialize, Serialize};
use cgmath::prelude::*; use cgmath::prelude::*;
use cgmath::vec3; use cgmath::vec3;
#[cfg(feature = "imgui_inspect")] #[cfg(feature = "imgui_inspect")]
@ -31,7 +32,7 @@ const SPEED: f32 = 0.5;
const SENSITIVTY: f32 = 0.1; const SENSITIVTY: f32 = 0.1;
const ZOOM: f32 = 45.0; const ZOOM: f32 = 45.0;
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "imgui_inspect", derive(Inspect))] #[cfg_attr(feature = "imgui_inspect", derive(Inspect))]
pub struct Camera { pub struct Camera {
// Camera Attributes // Camera Attributes

View File

@ -43,6 +43,7 @@ impl Transform {
pub struct ModelComponent { pub struct ModelComponent {
pub model: Model, pub model: Model,
pub hash: u64,
pub transform: Transform, pub transform: Transform,
} }

View File

@ -25,3 +25,4 @@ pub mod model;
pub mod shader; pub mod shader;
pub mod sky; pub mod sky;
pub mod utils; pub mod utils;
pub mod map;

126
doppler/src/map.rs Normal file
View File

@ -0,0 +1,126 @@
use crate::assets_cache::AssetsCache;
use crate::model::Model;
use crate::components::*;
use crate::shader::Shader;
use crate::sky::Sky;
use crate::light::*;
use crate::consts;
use crate::camera::*;
use serde::{Deserialize, Serialize};
use crate::math::{perspective, vec3, Deg, Matrix4, Point3};
use log::{info,error};
#[derive(Serialize, Deserialize, Debug)]
pub struct MapObject {
pub model_hash: u64,
pub transform: Transform,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct MapSave {
pub objects: Vec<MapObject>,
pub camera: Camera
}
impl MapSave {
pub fn save(map: &Map, _path: &str) {
let mut objects = Vec::with_capacity(map.models.len());
for m in &map.models {
objects.push(MapObject{
model_hash: m.hash,
transform: m.transform
});
}
let ms = MapSave {
camera: map.camera.clone(),
objects: objects
};
match serde_yaml::to_string(&ms) {
Ok(result) =>
println!("{}", result),
Err(e) => println!("{:?}", e)
}
}
pub fn load(path: &str, cache: &mut AssetsCache) -> Map {
let mut map = Map::default();
info!("Loading map from file: {}", path);
use std::fs;
let savefile = fs::read_to_string(path);
if savefile.is_err() {
error!("Cannot read file {}: {:?}",path, savefile);
return map;
}
let save : Result<MapSave, serde_yaml::Error> = serde_yaml::from_str(&savefile.unwrap());
if save.is_err() {
error!("Cannot parse file {}: {:?}",path, save);
return map;
}
for m in &save.unwrap().objects {
let model = cache.get_model_by_hash(&m.model_hash);
if model.is_none() {
continue;
}
map.models.push(ModelComponent {
transform: m.transform,
hash: m.model_hash,
model: model.unwrap(),
})
}
info!("Map loaded: {}", path);
map
}
}
pub struct Map {
pub models: Vec<ModelComponent>,
pub camera: Camera,
pub lighting_system: LightingSystem,
pub sky: Sky,
}
impl Default for Map {
fn default() -> Self {
let sky = unsafe { Sky::new() };
Map {
models: Vec::new(),
camera: Camera {
position: Point3::new(0.0, 8.0, 13.0),
front: vec3(0.0, -0.4, -1.0),
up: vec3(0.0, 1.0, -0.4),
right: vec3(1.0, 0.0, 0.0),
yaw: -90.0,
pitch: -20.0,
..Camera::default()
},
lighting_system: LightingSystem::default(),
sky: sky,
}
}
}
impl Map {
pub unsafe fn draw(&mut self) {
use crate::math::prelude::*;
// view/projection transformations
let projection: Matrix4<f32> = perspective(
Deg(self.camera.zoom),
consts::SCR_WIDTH as f32 / consts::SCR_HEIGHT as f32,
0.1,
1000.0,
);
let view = self.camera.get_view_matrix();
let view_pos = self.camera.position.to_vec();
self.lighting_system
.prepare_for_draw(&projection, &view, &view_pos);
for model in self.models.iter() {
model.draw(&self.lighting_system.shader);
}
self.sky.draw(view, projection);
}
}

115
resources/test_map.yaml Normal file
View File

@ -0,0 +1,115 @@
objects:
- model_hash: 15116225178797259971
transform:
position:
x: 10.0
y: 0.0
z: 26.0
rotation:
x: 0.0
y: 0.0
z: 0.0
scale: 2.5
- model_hash: 12030087559729388911
transform:
position:
x: -9.0
y: 0.0
z: -15.0
rotation:
x: 0.0
y: 0.0
z: 0.0
scale: 2.5
- model_hash: 12030087559729388911
transform:
position:
x: 15.0
y: 0.0
z: -7.0
rotation:
x: 0.0
y: 0.0
z: 0.0
scale: 2.5
- model_hash: 10272171414862311589
transform:
position:
x: 0.0
y: 0.0
z: 0.0
rotation:
x: 0.0
y: 0.0
z: 0.0
scale: 0.56
- model_hash: 5402531760391502974
transform:
position:
x: 0.0
y: 0.0
z: 0.0
rotation:
x: 0.0
y: 0.0
z: 0.0
scale: 1.0
- model_hash: 4360533331876312021
transform:
position:
x: 0.0
y: 0.0
z: 0.0
rotation:
x: 0.0
y: 0.0
z: 0.0
scale: 1.0
- model_hash: 6024833582843300776
transform:
position:
x: 8.3
y: 0.0
z: 3.0
rotation:
x: 0.0
y: 120.0
z: 0.0
scale: 0.025
- model_hash: 12474845581084103280
transform:
position:
x: 0.0
y: 0.0
z: 0.0
rotation:
x: 0.0
y: 0.0
z: 0.0
scale: 1.0
camera:
position:
x: 0.0
y: 8.0
z: 13.0
front:
x: 0.0
y: -0.4
z: -1.0
up:
x: 0.0
y: 1.0
z: -0.4
right:
x: 1.0
y: 0.0
z: 0.0
worldup:
x: 0.0
y: 1.0
z: 0.0
yaw: -90.0
pitch: -20.0
movement_speed: 0.5
mouse_sensivity: 0.1
zoom: 45.0

View File

@ -0,0 +1,8 @@
resources/objects/ground/ground.obj
resources/objects/robot/robot.obj
resources/objects/grass/grass.obj foliage.png
resources/objects/gaz_tank/gaz_tank.obj
resources/objects/tree/tree_6_d.obj tree_e.png
resources/objects/tree/tree_6_c.obj tree_e.png
resources/objects/tree/tree_6_c.obj tree_e.png
resources/objects/ruins/ruins.obj

View File

@ -6,15 +6,13 @@ use doppler::consts;
use doppler::glutin::event::{ElementState, VirtualKeyCode}; use doppler::glutin::event::{ElementState, VirtualKeyCode};
use doppler::imgui::*; use doppler::imgui::*;
use doppler::light::*; use doppler::light::*;
use doppler::map::*;
use doppler::math::prelude::*; use doppler::math::prelude::*;
use doppler::math::{perspective, vec3, Deg, Matrix4, Point3}; use doppler::math::{perspective, vec3, Deg, Matrix4, Point3};
use doppler::sky::Sky; use doppler::sky::Sky;
pub struct ExampleClient { pub struct ExampleClient {
models: Vec<ModelComponent>, map: Map,
camera: Camera,
lighting_system: LightingSystem,
sky: Sky,
delta: f32, delta: f32,
show_object_info: bool, show_object_info: bool,
show_camera_info: bool, show_camera_info: bool,
@ -25,21 +23,9 @@ pub struct ExampleClient {
impl Default for ExampleClient { impl Default for ExampleClient {
fn default() -> Self { fn default() -> Self {
let sky = unsafe { Sky::new() };
ExampleClient { ExampleClient {
delta: 0.0, delta: 0.0,
models: vec![], map: Map::default(),
camera: Camera {
position: Point3::new(0.0, 8.0, 13.0),
front: vec3(0.0, -0.4, -1.0),
up: vec3(0.0, 1.0, -0.4),
right: vec3(1.0, 0.0, 0.0),
yaw: -90.0,
pitch: -20.0,
..Camera::default()
},
lighting_system: LightingSystem::default(),
sky: sky,
object_info_id: 0, object_info_id: 0,
show_camera_info: false, show_camera_info: false,
show_object_info: false, show_object_info: false,
@ -53,18 +39,23 @@ impl Client for ExampleClient {
fn on_keyboard(&mut self, code: &VirtualKeyCode, state: &ElementState) { fn on_keyboard(&mut self, code: &VirtualKeyCode, state: &ElementState) {
match (code, state) { match (code, state) {
(VirtualKeyCode::W, ElementState::Pressed) => self (VirtualKeyCode::W, ElementState::Pressed) => self
.map
.camera .camera
.process_keyboard(CameraMovement::FORWARD, self.delta), .process_keyboard(CameraMovement::FORWARD, self.delta),
(VirtualKeyCode::S, ElementState::Pressed) => self (VirtualKeyCode::S, ElementState::Pressed) => self
.map
.camera .camera
.process_keyboard(CameraMovement::BACKWARD, self.delta), .process_keyboard(CameraMovement::BACKWARD, self.delta),
(VirtualKeyCode::A, ElementState::Pressed) => self (VirtualKeyCode::A, ElementState::Pressed) => self
.map
.camera .camera
.process_keyboard(CameraMovement::LEFT, self.delta), .process_keyboard(CameraMovement::LEFT, self.delta),
(VirtualKeyCode::D, ElementState::Pressed) => self (VirtualKeyCode::D, ElementState::Pressed) => self
.map
.camera .camera
.process_keyboard(CameraMovement::RIGHT, self.delta), .process_keyboard(CameraMovement::RIGHT, self.delta),
(VirtualKeyCode::LControl, _) => self (VirtualKeyCode::LControl, _) => self
.map
.camera .camera
.enable_mouse_movement(state == &ElementState::Released), .enable_mouse_movement(state == &ElementState::Released),
(_, _) => (), (_, _) => (),
@ -72,78 +63,13 @@ impl Client for ExampleClient {
} }
fn load_assets(&mut self, cache: &mut AssetsCache) { fn load_assets(&mut self, cache: &mut AssetsCache) {
let ground = ModelComponent { cache.load_all_from_file("resources/test_objects.txt");
transform: Transform { self.map = MapSave::load("resources/test_map.yaml", cache);
scale: 0.56, MapSave::save(&self.map, "test");
..Transform::default()
},
model: cache.get_model("resources/objects/ground/ground.obj"),
};
let robot = ModelComponent {
transform: Transform::default(),
model: cache.get_model("resources/objects/robot/robot.obj"),
};
let grass = ModelComponent {
transform: Transform::default(),
model: cache.get_model_ext("resources/objects/grass/grass.obj", Some("foliage.png")),
};
let gaz_tank = ModelComponent {
transform: Transform {
position: vec3(8.3, 0.0, 3.0),
rotation: vec3(0.0, 120.0, 0.0),
scale: 0.025,
..Transform::default()
},
model: cache.get_model("resources/objects/gaz_tank/gaz_tank.obj"),
};
let tree = ModelComponent {
transform: Transform {
position: vec3(10.0, 0.0, 26.0),
scale: 2.5,
..Transform::default()
},
model: cache.get_model_ext("resources/objects/tree/tree_6_d.obj", Some("tree_e.png")),
};
let tree2 = ModelComponent {
transform: Transform {
position: vec3(-9.0, 0.0, -15.0),
scale: 2.5,
..Transform::default()
},
model: cache.get_model_ext("resources/objects/tree/tree_6_c.obj", Some("tree_e.png")),
};
let tree3 = ModelComponent {
transform: Transform {
position: vec3(15.0, 0.0, -7.0),
scale: 2.5,
..Transform::default()
},
model: cache.get_model_ext("resources/objects/tree/tree_6_c.obj", Some("tree_e.png")),
};
let ruins = ModelComponent {
transform: Transform::default(),
model: cache.get_model("resources/objects/ruins/ruins.obj"),
};
self.models = vec![tree, tree2, tree3, ground, robot, ruins, gaz_tank, grass];
} }
unsafe fn draw(&mut self) { unsafe fn draw(&mut self) {
// view/projection transformations self.map.draw();
let projection: Matrix4<f32> = perspective(
Deg(self.camera.zoom),
consts::SCR_WIDTH as f32 / consts::SCR_HEIGHT as f32,
0.1,
1000.0,
);
let view = self.camera.get_view_matrix();
let view_pos = self.camera.position.to_vec();
self.lighting_system
.prepare_for_draw(&projection, &view, &view_pos);
for model in self.models.iter() {
model.draw(&self.lighting_system.shader);
}
self.sky.draw(view, projection);
} }
fn update(&mut self, delta: f32) { fn update(&mut self, delta: f32) {
self.delta = delta; self.delta = delta;
@ -191,7 +117,7 @@ impl Client for ExampleClient {
ui.text(im_str!("Camera info")); ui.text(im_str!("Camera info"));
ui.separator(); ui.separator();
<Camera as imgui_inspect::InspectRenderDefault<Camera>>::render( <Camera as imgui_inspect::InspectRenderDefault<Camera>>::render(
&[&self.camera], &[&self.map.camera],
&"CameraInfo", &"CameraInfo",
ui, ui,
&imgui_inspect::InspectArgsDefault { &imgui_inspect::InspectArgsDefault {
@ -203,7 +129,7 @@ impl Client for ExampleClient {
} }
if self.show_object_info { if self.show_object_info {
let mut id = self.object_info_id; let mut id = self.object_info_id;
let max: i32 = self.models.len() as i32 - 1; let max: i32 = self.map.models.len() as i32 - 1;
let mut show_window = self.show_object_info; let mut show_window = self.show_object_info;
Window::new(im_str!("Object info")) Window::new(im_str!("Object info"))
@ -219,7 +145,7 @@ impl Client for ExampleClient {
id id
}; };
let mut selected_mut = vec![&mut self.models[id as usize].transform]; let mut selected_mut = vec![&mut self.map.models[id as usize].transform];
<Transform as imgui_inspect::InspectRenderStruct<Transform>>::render_mut( <Transform as imgui_inspect::InspectRenderStruct<Transform>>::render_mut(
&mut selected_mut, &mut selected_mut,
"Object info", "Object info",
@ -232,7 +158,7 @@ impl Client for ExampleClient {
} }
if self.show_light_info { if self.show_light_info {
let mut id = self.light_info_id; let mut id = self.light_info_id;
let max: i32 = self.lighting_system.point_lights.len() as i32 - 1; let max: i32 = self.map.lighting_system.point_lights.len() as i32 - 1;
let mut show_window = self.show_light_info; let mut show_window = self.show_light_info;
Window::new(im_str!("Lights info")) Window::new(im_str!("Lights info"))
@ -240,7 +166,7 @@ impl Client for ExampleClient {
.opened(&mut show_window) .opened(&mut show_window)
.build(&ui, || { .build(&ui, || {
{ {
let mut selected_mut = vec![&mut self.lighting_system.directional_light]; let mut selected_mut = vec![&mut self.map.lighting_system.directional_light];
<DirectionalLight as imgui_inspect::InspectRenderStruct< <DirectionalLight as imgui_inspect::InspectRenderStruct<
DirectionalLight, DirectionalLight,
>>::render_mut( >>::render_mut(
@ -256,7 +182,7 @@ impl Client for ExampleClient {
id = if id < 0 { 0 } else if id > max { max } else { id }; id = if id < 0 { 0 } else if id > max { max } else { id };
{ {
let mut selected_mut = let mut selected_mut =
vec![&mut self.lighting_system.point_lights[id as usize]]; vec![&mut self.map.lighting_system.point_lights[id as usize]];
<PointLight as imgui_inspect::InspectRenderStruct<PointLight>>::render_mut( <PointLight as imgui_inspect::InspectRenderStruct<PointLight>>::render_mut(
&mut selected_mut, &mut selected_mut,
"PointLightInfo", "PointLightInfo",
@ -273,9 +199,9 @@ impl Client for ExampleClient {
} }
fn on_mouse_scroll(&mut self, yoffset: f32) { fn on_mouse_scroll(&mut self, yoffset: f32) {
self.camera.process_mouse_scroll(yoffset as f32); self.map.camera.process_mouse_scroll(yoffset as f32);
} }
fn on_mouse_move(&mut self, x: f32, y: f32) { fn on_mouse_move(&mut self, x: f32, y: f32) {
self.camera.process_mouse_movement(x, y, true); self.map.camera.process_mouse_movement(x, y, true);
} }
} }