camera scrolls right as the player moves
parent
c8baadc24c
commit
a3fcff78f9
|
@ -426,9 +426,9 @@ checksum = "3c6015bb2d300661a0014e29025374a32a68e8ef7e4effe547baa00eef38b8e3"
|
|||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "0.4.6"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6"
|
||||
checksum = "1aab8fc367588b89dcee83ab0fd66b72b50b72fa1904d7095045ace2b0c81c35"
|
||||
|
||||
[[package]]
|
||||
name = "jpeg-decoder"
|
||||
|
@ -647,6 +647,7 @@ dependencies = [
|
|||
"rmp-serde",
|
||||
"sdl2",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"tokio",
|
||||
"tracing",
|
||||
"tracing-subscriber",
|
||||
|
@ -1201,9 +1202,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.60"
|
||||
version = "1.0.73"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1500e84d27fe482ed1dc791a56eddc2f230046a040fa908c08bda1d9fb615779"
|
||||
checksum = "bcbd0344bc6533bc7ec56df11d42fb70f1b912351c0825ccb7211b59d8af7cf5"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"ryu",
|
||||
|
|
|
@ -27,6 +27,7 @@ rand = "0.6.5"
|
|||
rcgen = "0.8.11"
|
||||
rmp-serde = "0.15.4"
|
||||
serde = { version = "1.0.125", features = ["derive"] }
|
||||
serde_json = "1.0.73"
|
||||
sdl2 = "0.32.2"
|
||||
tokio = { version = "1.5.0", features = ["full"] }
|
||||
tracing = "0.1.22"
|
||||
|
|
|
@ -177,8 +177,28 @@ impl Graphics {
|
|||
level: &crate::LoadedLevel,
|
||||
camera: &crate::Camera,
|
||||
) {
|
||||
use serde::Deserialize;
|
||||
use uniforms as u;
|
||||
|
||||
#[derive (Default, Deserialize)]
|
||||
struct Config {
|
||||
camera: CameraCfg,
|
||||
}
|
||||
|
||||
#[derive (Default, Deserialize)]
|
||||
struct CameraCfg {
|
||||
#[serde(default)]
|
||||
rotate_mix: f32,
|
||||
#[serde(default)]
|
||||
translate_mix: f32,
|
||||
}
|
||||
/*
|
||||
let cfg: Option <Config> = std::fs::read_to_string ("config.json").ok ()
|
||||
.map (|s| serde_json::from_str (s.as_str ()).ok ())
|
||||
.flatten ();
|
||||
|
||||
let cfg = cfg.unwrap_or_else (Config::default);
|
||||
*/
|
||||
let white = color_from_255 ((255.0, 255.0, 255.0));
|
||||
let black = color_from_255 ((0.0, 0.0, 0.0));
|
||||
let shadow_blue = color_from_255 ((68.0, 36.0, 52.0));
|
||||
|
@ -195,9 +215,17 @@ impl Graphics {
|
|||
_
|
||||
) = camera.transform.clone ().decomposed ();
|
||||
|
||||
let view_mat = proj_mat *
|
||||
Mat4::from_quat (Quat::from_array (cam_rot).inverse ());
|
||||
//Mat4::from_translation (cam_trans.into ()) *
|
||||
let cam_trans = Vec3::from (cam_trans);
|
||||
let cam_trans = Vec3::new (cam_trans.x.max (state.player.pos.x + 4.0), cam_trans.y, cam_trans.z);
|
||||
|
||||
let view_mat =
|
||||
Mat4::from_quat (Quat::from_array (cam_rot).inverse ()) *
|
||||
Mat4::from_translation (-cam_trans);
|
||||
|
||||
// println! ("Camera is at {:?}", view_mat.inverse ().transform_point3 ((0.0, 0.0, 0.0).into ()));
|
||||
|
||||
let view_mat = proj_mat * view_mat;
|
||||
|
||||
let world_model_mat = Mat4::IDENTITY;
|
||||
|
||||
self.passes [0].with (gl_state, || {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
use std::{
|
||||
collections::HashMap,
|
||||
time::Instant,
|
||||
};
|
||||
|
||||
use anyhow::Result;
|
||||
|
@ -177,6 +178,9 @@ async fn main () -> Result <()> {
|
|||
game_state.reset_level (&level);
|
||||
game_state.phys_tris = phys_tris;
|
||||
|
||||
let mut next_mpf_print = 60;
|
||||
let mut last_mpf_instant = Instant::now ();
|
||||
|
||||
'running: loop {
|
||||
let _frames_to_do = time_step.step ();
|
||||
let mut player_wants_to_jump = false;
|
||||
|
@ -292,13 +296,23 @@ async fn main () -> Result <()> {
|
|||
});
|
||||
}
|
||||
|
||||
dbg! (game_state.player.pos);
|
||||
// dbg! (game_state.player.pos);
|
||||
|
||||
window.gl_make_current (&gl_ctx).unwrap ();
|
||||
|
||||
graphics.draw (&game_state, &mut gl_state, &level, &camera);
|
||||
graphics.frames += 1;
|
||||
|
||||
if graphics.frames == next_mpf_print {
|
||||
let now = Instant::now ();
|
||||
let mpf = (now - last_mpf_instant).as_millis () / 60;
|
||||
|
||||
dbg! (mpf);
|
||||
|
||||
next_mpf_print += 60;
|
||||
last_mpf_instant = now;
|
||||
}
|
||||
|
||||
window.gl_swap_window ();
|
||||
|
||||
tokio::time::sleep (Duration::from_millis (15)).await;
|
||||
|
|
Loading…
Reference in New Issue