broken lighting

This commit is contained in:
2020-06-28 21:20:26 +02:00
parent 419a329fc8
commit f868a8e45a
7 changed files with 68 additions and 15 deletions

View File

@@ -1,4 +1,4 @@
use cgmath::{Deg, Matrix4, One, Quaternion, Rad, Rotation, Rotation3, Vector3};
use cgmath::{Deg, Matrix4, One, Quaternion, Rad, Rotation, Rotation3, Vector3, vec3, Vector4};
use winit::event::Event;
use crate::config::LogConfig;
@@ -53,6 +53,9 @@ impl Game for TestGame {
println!("{:.0} ms / {:.0} FPS", frame_time * 1000.0, 1.0 / frame_time);
}
let light_pos = vec3(f32::sin(time) * 10.0, f32::cos(time) * 10.0, 0.0);
self.game_objects[0].get_game_object(renderer).unwrap().set_position(light_pos.into());
self.cam_rotation = self.cam_rotation * Quaternion::from_angle_y(Deg(self.input.get_axis("look_horizontal") * 0.05));
self.cam_rotation = Quaternion::from_angle_x(Deg(self.input.get_axis("look_vertical") * 0.05)) * self.cam_rotation;
self.cam_position += self.cam_rotation.invert().rotate_vector(Vector3::new(
@@ -82,19 +85,27 @@ impl Game for TestGame {
view: view.into(),
projection: proj.into(),
time,
light_position: light_pos.into(),
_dummy0: [0; 12],
}
}
}
fn matrix_vector_mul(matrix: &Matrix4<f32>, vector: &Vector3<f32>) -> Vector3<f32> {
let v4 = Vector4::new(vector.x, vector.y, vector.z, 1.0);
let out = matrix * v4;
Vector3::new(out.x, out.y, out.z)
}
impl TestGame {
fn game_start(self: &mut Self, renderer: &mut VulkanRenderer) {
self.load_gltf(renderer, "models/box.gltf.glb");
self.load_gltf(renderer, "models/sphere.glb");
let cube = self.add_game_object(renderer, 0, 0);
cube.get_game_object(renderer).unwrap().set_position(0.0, 2.0, 0.0);
cube.get_game_object(renderer).unwrap().set_position((3.0, 4.0, 5.0));
let sphere = self.add_game_object(renderer, 1, 0);
sphere.get_game_object(renderer).unwrap().set_position(2.0, 0.0, 0.0);
sphere.get_game_object(renderer).unwrap().set_position((0.0, 0.0, 0.0));
println!("Game loaded!");
}