diff options
Diffstat (limited to 'client/src')
-rw-r--r-- | client/src/camera.rs | 20 | ||||
-rw-r--r-- | client/src/shader.wgsl | 2 | ||||
-rw-r--r-- | client/src/state.rs | 1 |
3 files changed, 12 insertions, 11 deletions
diff --git a/client/src/camera.rs b/client/src/camera.rs index f40e073..3876e8a 100644 --- a/client/src/camera.rs +++ b/client/src/camera.rs @@ -14,13 +14,13 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>. */ -use glam::{EulerRot, Mat3, Mat4, Vec2, Vec3}; +use glam::{EulerRot, Mat3, Mat4, Vec2, Vec3, vec3}; pub struct Camera { pos: Vec3, rot: Vec3, fov: f32, - aspect: f32, + pub aspect: f32, } impl Camera { @@ -33,9 +33,12 @@ impl Camera { } } pub fn update(&mut self, input_move: Vec3, input_rot: Vec2, dt: f32) { - self.pos += input_move * dt; - self.rot.x += input_rot.y * 0.002; - self.rot.y += input_rot.x * 0.002; + self.pos += self.rotation_mat() * (-vec3(input_move.z, input_move.y, input_move.x) * dt); + self.rot.x += input_rot.x * 0.002; + self.rot.y += input_rot.y * 0.002; + } + pub fn rotation_mat(&self) -> Mat3 { + Mat3::from_euler(EulerRot::YXZ, self.rot.x, self.rot.y, self.rot.z) } pub fn to_matrix(&self) -> Mat4 { // let tdir = @@ -43,12 +46,7 @@ impl Camera { // * Mat4::look_at_rh(self.pos, self.pos + tdir, Vec3::Y) Mat4::perspective_infinite_reverse_rh(self.fov, self.aspect, 0.1) - * Mat4::from_mat3(Mat3::from_euler( - EulerRot::YXZ, - self.rot.x, - self.rot.y, - self.rot.z, - )) + * Mat4::from_mat3(self.rotation_mat().inverse()) * Mat4::from_translation(-self.pos) } } diff --git a/client/src/shader.wgsl b/client/src/shader.wgsl index 89c9d70..fddff86 100644 --- a/client/src/shader.wgsl +++ b/client/src/shader.wgsl @@ -37,6 +37,8 @@ var<push_constant> project: mat4x4<f32>; fn vs_main(vi: VertexIn) -> VertexOut { var clip = project * vec4(vi.x, vi.y, vi.z, -1.); clip /= clip.w; + clip.x *= -1.; + clip.y *= -1.; let vo = VertexOut( clip, vec3(vi.nx, vi.ny, vi.nz), diff --git a/client/src/state.rs b/client/src/state.rs index 5faa778..b0d19e6 100644 --- a/client/src/state.rs +++ b/client/src/state.rs @@ -60,6 +60,7 @@ impl<'a> State<'a> { } pub fn resize(&mut self, width: u32, height: u32) { self.renderer.resize(width, height); + self.camera.aspect = width as f32 / height as f32; } pub fn update(&mut self) -> Result<()> { let now = Instant::now(); |