broken lighting
This commit is contained in:
@@ -13,10 +13,10 @@ impl GameObject {
|
||||
GameObject { mesh_index: mesh, texture_index, model_matrix: Matrix4::identity() }
|
||||
}
|
||||
|
||||
pub fn set_position(&mut self, x: f32, y: f32, z: f32) {
|
||||
self.model_matrix.w.x = x;
|
||||
self.model_matrix.w.y = y;
|
||||
self.model_matrix.w.z = z;
|
||||
pub fn set_position(&mut self, pos: (f32, f32, f32)) {
|
||||
self.model_matrix.w.x = pos.0;
|
||||
self.model_matrix.w.y = pos.1;
|
||||
self.model_matrix.w.z = pos.2;
|
||||
}
|
||||
|
||||
pub fn get_position(&self) -> Vector3<f32> {
|
||||
|
||||
17
src/main.rs
17
src/main.rs
@@ -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!");
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use std::sync::Arc;
|
||||
use std::time::SystemTime;
|
||||
|
||||
use cgmath::{Matrix4, SquareMatrix};
|
||||
use cgmath::{Matrix4, SquareMatrix, vec3};
|
||||
use image::{ImageBuffer, ImageFormat, Rgb, Rgba};
|
||||
use image::buffer::ConvertBuffer;
|
||||
use vulkano::buffer::{BufferUsage, CpuAccessibleBuffer};
|
||||
@@ -276,7 +276,13 @@ impl VulkanRenderer {
|
||||
let framebuffers = window_size_dependent_setup(device.clone(), &images, render_pass.clone(), &mut dynamic_state);
|
||||
|
||||
let mut uniform_buffers = Vec::new();
|
||||
let uniform_buffer = vs::ty::ObjectUniformData { view: Matrix4::identity().into(), projection: Matrix4::identity().into(), time: 0.0 };
|
||||
let uniform_buffer = vs::ty::ObjectUniformData {
|
||||
view: Matrix4::identity().into(),
|
||||
projection: Matrix4::identity().into(),
|
||||
time: 0.0,
|
||||
light_position: vec3(0.0, 0.0, 0.0).into(),
|
||||
_dummy0: [0; 12],
|
||||
};
|
||||
|
||||
for _ in 0..swapchain.num_images() {
|
||||
uniform_buffers.push(CpuAccessibleBuffer::from_data(
|
||||
|
||||
Reference in New Issue
Block a user