🚧 wip: matrices are giving me grief again

main
_ 2021-12-23 00:43:58 +00:00
parent 3803a48c13
commit c8baadc24c
2 changed files with 17 additions and 4 deletions

View File

@ -2,6 +2,11 @@ use std::{
collections::HashMap, collections::HashMap,
}; };
use glam::{
Quat,
Vec4,
};
use opengl_rust::{ use opengl_rust::{
prelude::*, prelude::*,
gl_state::{ gl_state::{
@ -184,7 +189,15 @@ impl Graphics {
let proj_mat = Mat4::perspective_rh_gl (fov.to_radians (), screen_size.0 / screen_size.1, 0.125, 200.0); let proj_mat = Mat4::perspective_rh_gl (fov.to_radians (), screen_size.0 / screen_size.1, 0.125, 200.0);
let view_mat = proj_mat * camera.mat; let (
cam_trans,
cam_rot,
_
) = 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 world_model_mat = Mat4::IDENTITY; let world_model_mat = Mat4::IDENTITY;
self.passes [0].with (gl_state, || { self.passes [0].with (gl_state, || {
@ -319,7 +332,7 @@ impl Graphics {
} }
} }
if false { if true {
let sky_mvp_mat = view_mat * Mat4::from_scale ((64.0, 64.0, 64.0).into ()); let sky_mvp_mat = view_mat * Mat4::from_scale ((64.0, 64.0, 64.0).into ());
self.texture_sky.bind (); self.texture_sky.bind ();

View File

@ -75,7 +75,7 @@ async fn main () -> Result <()> {
for node in scene.nodes () { for node in scene.nodes () {
if let Some (c) = node.camera () { if let Some (c) = node.camera () {
camera = Some (Camera { camera = Some (Camera {
mat: gltf_node_get_mat4 (&node).inverse (), transform: node.transform ().clone (),
}); });
} }
@ -412,7 +412,7 @@ struct TriangleStream {
} }
struct Camera { struct Camera {
mat: Mat4, transform: gltf::scene::Transform,
} }
fn gltf_node_get_mat4 (node: &gltf::Node) -> Mat4 { fn gltf_node_get_mat4 (node: &gltf::Node) -> Mat4 {