summaryrefslogtreecommitdiff
path: root/client/src/camera.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2025-01-09 23:45:52 +0100
committermetamuffin <metamuffin@disroot.org>2025-01-09 23:45:52 +0100
commit87f67ff9ae1aa74008042750d354a7dad030020d (patch)
tree0210229d6db5db6cd90a0b85911b6f654e72b51b /client/src/camera.rs
parente2a3c56206080008f34072b5c7cf2ef961e0ed49 (diff)
downloadweareserver-87f67ff9ae1aa74008042750d354a7dad030020d.tar
weareserver-87f67ff9ae1aa74008042750d354a7dad030020d.tar.bz2
weareserver-87f67ff9ae1aa74008042750d354a7dad030020d.tar.zst
fix camera coordinate madness
Diffstat (limited to 'client/src/camera.rs')
-rw-r--r--client/src/camera.rs20
1 files changed, 9 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)
}
}