void SpatialCamera::setFrame(const Vec3& position, const Vec3& right, const Vec3& up, const Vec3& back) { m_worldTransform.setTranslate(position); m_worldTransform.setRotate(Quat(right, up, back)); updateViewMatrix(); updateViewProjectionMatrix(); updateFrustumPlanesAndPoints(); }
Camera::Camera(const Type& type) : m_type(type) , m_position(Vec3::zero) , m_right(Vec3::xxx) , m_up(Vec3::yyy) , m_front(Vec3::zzz) , m_upFovDegrees(0.0f) , m_aspectRatio(0.0f) , m_rightMin(0.0f) , m_rightMax(0.0f) , m_upMin(0.0f) , m_upMax(0.0f) , m_frontMin(0.0f) , m_frontMax(0.0f) , m_preViewMatrix(Mat4::identity) , m_viewMatrix(Mat4::identity) , m_orthographicProjectionMatrix(Mat4::identity) , m_perspectiveProjectionMatrix(Mat4::identity) , m_viewOrthographicProjectionMatrix(Mat4::identity) , m_viewPerspectiveProjectionMatrix(Mat4::identity) , m_postProjectionMatrix(Mat4::identity) { updateViewMatrix(); updateProjectionMatrix(); updateViewProjectionMatrix(); updateFrustumPlanesAndPoints(); }
void Camera::setAxes(const Vec3& right, const Vec3& up, const Vec3& front) { m_right = right; m_up = up; m_front = front; updateViewMatrix(); updateViewProjectionMatrix(); updateFrustumPlanesAndPoints(); }
vec3 Camera::getRealCameraPosition() { updateViewProjectionMatrix(); vec3 relative(0, 0, camDist); relative = glm::rotateX(relative, pitch); relative = glm::rotateY(relative, yaw); return getPosition() + relative; }
void SpatialCamera::setFrustum(const float& l, const float& r, const float& b, const float& t, const float& n, const float& f) { m_projectionParameters.l = l; m_projectionParameters.r = r; m_projectionParameters.b = b; m_projectionParameters.t = t; m_projectionParameters.n = n; m_projectionParameters.f = f; updateProjectionMatrix(); updateViewProjectionMatrix(); updateFrustumPlanesAndPoints(); }
void Camera::setFrustum(const float& rightMin, const float& rightMax, const float& upMin, const float& upMax, const float& frontMin, const float& frontMax) { m_rightMin = rightMin; m_rightMax = rightMax; m_upMin = upMin; m_upMax = upMax; m_frontMin = frontMin; m_frontMax = frontMax; updateProjectionMatrix(); updateViewProjectionMatrix(); updateFrustumPlanesAndPoints(); }
void SpatialCamera::setFrustum(const float& upFovRadian, const float& aspectRatio, const float& n, const float& f) { m_upFovRadian = upFovRadian; m_aspectRatio = aspectRatio; m_projectionParameters.n = n; m_projectionParameters.f = f; m_projectionParameters.t = n * tanf(0.5f * upFovRadian); m_projectionParameters.r = aspectRatio * m_projectionParameters.t; m_projectionParameters.b = -m_projectionParameters.t; m_projectionParameters.l = -m_projectionParameters.r; updateProjectionMatrix(); updateViewProjectionMatrix(); updateFrustumPlanesAndPoints(); }
void Camera::setFrustum(const float& upFovDegrees, const float& aspectRatio, const float& frontMin, const float& frontMax) { m_upFovDegrees = upFovDegrees; m_aspectRatio = aspectRatio; m_frontMin = frontMin; m_frontMax = frontMax; m_upMax = frontMin * tan(0.5f * upFovDegrees * M_DEGREE_TO_RADIAN); m_rightMax = aspectRatio * m_upMax; m_upMin = -m_upMax; m_rightMin = -m_rightMax; updateProjectionMatrix(); updateViewProjectionMatrix(); updateFrustumPlanesAndPoints(); }
void SpatialCamera::setFrame(const Vec3& position, const Vec3& lookAtPoint) { Vec3 back = position - lookAtPoint; back.normalize(); Vec3 up = Vec3(0.0f, 1.0f, 0.0f); Vec3 right = cross(up, back); right.normalize(); up = cross(back, right); up.normalize(); m_worldTransform.setTranslate(position); m_worldTransform.setRotate(Quat(right, up, back)); updateViewMatrix(); updateViewProjectionMatrix(); updateFrustumPlanesAndPoints(); }
SpatialCamera::SpatialCamera(const ProjectionType& type, const Mat4& ndc, const Transform3& transform) : Spatial3(transform) , m_projectionNdc(ndc) , m_projectionType(type) //, m_projectionRange(ForwardFiniteZ) //, m_projectionRange(ReverseInfiniteZ) //, m_projectionRange(ReverseFiniteZ) , m_projectionRange(ReverseInfiniteZ) , m_projectionParameters(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f) , m_upFovRadian(0.0f) , m_aspectRatio(0.0f) , m_viewMatrix(Mat4::identity) , m_orthographicProjectionMatrix(Mat4::identity) , m_perspectiveProjectionMatrix(Mat4::identity) , m_viewOrthographicProjectionMatrix(Mat4::identity) , m_viewPerspectiveProjectionMatrix(Mat4::identity) { updateViewMatrix(); updateProjectionMatrix(); updateViewProjectionMatrix(); updateFrustumPlanesAndPoints(); }
void SpatialCamera::setPosition(const Vec3& position) { m_worldTransform.setTranslate(position); updateViewMatrix(); updateViewProjectionMatrix(); updateFrustumPlanesAndPoints(); }
void SpatialCamera::setScale(const Vec3& scale) { m_worldTransform.setScale(scale); updateViewMatrix(); updateViewProjectionMatrix(); updateFrustumPlanesAndPoints(); }
void SpatialCamera::setRotate(const Quat& rotate) { m_worldTransform.setRotate(rotate); updateViewMatrix(); updateViewProjectionMatrix(); updateFrustumPlanesAndPoints(); }
void Camera::setPostProjectionMatrix(const Mat4& postProjectionMatrix) { m_postProjectionMatrix = postProjectionMatrix; updateViewProjectionMatrix(); updateFrustumPlanesAndPoints(); }
void Camera::setPosition(const Vec3& position) { m_position = position; updateViewMatrix(); updateViewProjectionMatrix(); updateFrustumPlanesAndPoints(); }
mat4 Camera::getVPMatrix() { updateViewProjectionMatrix(); return vpMatrix; }
void SpatialCamera::setType(const ProjectionType& type) { m_projectionType = type; updateProjectionMatrix(); updateViewProjectionMatrix(); updateFrustumPlanesAndPoints(); }