void Camera::lookAt(const vector3f &refPos, const vector3f &upVector) { front = refPos.normalized(); up = upVector.normalized(); vector3f s = cross(front, up); vector3f u = cross(s, front); view = matrix4f( s.x, u.x, -front.x, 0, s.y, u.y, -front.y, 0, s.z, u.z, -front.z, 0, 0, 0, 0, 1 ); }
matrix4x4 matrix4x4::rotation_around_axis(vector3f const& axis, float const radians) { vector3f axis_normalized{axis.normalized()}; float const cos_value{std::cos(radians)}; float const sin_value{std::sin(radians)}; return matrix4x4{ axis_normalized.x * axis_normalized.x * (1.0f - cos_value) + cos_value, axis_normalized.x * axis_normalized.y * (1.0f - cos_value) + axis_normalized.z * sin_value, axis_normalized.x * axis_normalized.z * (1.0f - cos_value) - axis_normalized.y * sin_value, 0.0f, axis_normalized.x * axis_normalized.y * (1.0f - cos_value) - axis_normalized.z * sin_value, axis_normalized.y * axis_normalized.y * (1.0f - cos_value) + cos_value, axis_normalized.y * axis_normalized.z * (1.0f - cos_value) + axis_normalized.x * sin_value, 0.0f, axis_normalized.x * axis_normalized.z * (1.0f - cos_value) + axis_normalized.y * sin_value, axis_normalized.y * axis_normalized.z * (1.0f - cos_value) - axis_normalized.x * sin_value, axis_normalized.z * axis_normalized.z * (1.0f - cos_value) + cos_value, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}; }
camera::camera( vector3f const& position, vector3f const& forward, vector3f const& fake_up, float const horizontal_fov, float const aspect_ratio, float const near_plane_z, float const far_plane_z) : m_position{position}, m_forward{forward.normalized()}, m_horizontal_fov{horizontal_fov}, m_vertical_fov{horizontal_fov * aspect_ratio}, m_aspect_ratio{aspect_ratio}, m_near_plane_z{near_plane_z}, m_far_plane_z{far_plane_z} { establish_coordinate_system(fake_up.normalized()); }