Last active
September 26, 2021 15:03
-
-
Save pr0g/6d6cd11c0278291e79e3f6eca073d0bd to your computer and use it in GitHub Desktop.
Free look and custom pivot orbit camera implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <as/as-math-ops.hpp> // https://github.com/pr0g/as | |
struct Camera | |
{ | |
as::vec3 pivot = as::vec3::zero(); // pivot point to rotate about | |
as::vec3 offset = as::vec3::zero(); // offset relative to pivot | |
float yaw = 0.0f; // yaw rotation in radians | |
float pitch = 0.0f; // pitch rotation in radians | |
// view camera transform (v in MVP) | |
as::affine view() const; | |
// world camera transform | |
as::affine transform() const; | |
}; | |
inline as::affine Camera::view() const | |
{ | |
return as::affine_inverse(transform()); | |
} | |
inline as::affine Camera::transform() const | |
{ | |
// multiplication order left to right | |
return as::affine_mul( | |
as::affine_mul( | |
as::affine_from_vec3(offset), as::affine_from_mat3(as::mat3_rotation_zxy( | |
pitch, yaw, 0.0f))), | |
as::affine_from_vec3(pivot)); | |
} | |
// see https://github.com/pr0g/as-camera/blob/0ed6ea8284bede968d20392b792d35ad6d33c3bc/include/as-camera/as-camera.hpp | |
// for a more complete implementation |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment