19 lookAt(
const Vec3d& pos,
const Vec3d& target,
const Vec3d& up)
21 Mat4d results = Mat4d::Identity();
23 R.col(2) = (pos - target).normalized();
24 R.col(0) = up.cross(R.col(2)).normalized();
25 R.col(1) = R.col(2).cross(R.col(0));
26 results.topLeftCorner<3, 3>() = R.transpose();
27 results.topRightCorner<3, 1>() = -R.transpose() * pos;
62 virtual ~
Camera() =
default;
98 m_viewModified =
false;
125 double getNearZ()
const {
return m_nearZ; }
134 double getFarZ()
const {
return m_farZ; }
136 virtual void update()
142 m_viewModified =
false;
162 m_viewModified =
true;
185 m_viewModified =
true;
211 const Vec4d worldPos = (
m_proj *
m_view).inverse() * Vec4d(ndcPos[0], ndcPos[1], 0.0, 1.0);
212 return (worldPos.head<3>() / worldPos[3] -
m_position).normalized();
221 m_viewModified =
true;
241 bool m_viewModified =
true;
254 Mat4d m_hmdView = Mat4d::Identity();
void setFieldOfView(const double fov)
Sets the field of view.
Vec3d m_viewUp
camera up vector
Vec3d m_position
camera position
double getFieldOfView() const
Gets the field of view.
const Vec3d & getViewUp() const
Get the up direction of the view.
Mat4d m_invView
Inverse is often needed so we maintain it.
void print()
Utility function to quickly print cam stats.
Mat4d & getView()
Get camera view matrix.
void setFarZ(const double farZ)
Set clipping near note: You lose depth accuracy as the range between near and far increases could cau...
const Mat4d & getInvView()
Get the inverse view matrix.
const Vec3d & getFocalPoint() const
Returns the focal point The focal point is the point that the camera points to.
double m_fieldOfView
field of view in degrees
Mat4d m_view
Actual view matrix used.
Mat4d m_proj
Only modifiable through projection parameters (fov,near,far)
double m_farZ
far plane of the camera
Vec3d getEyeRayDir(const Vec2d &ndcPos) const
Compute ray emanating from the camera position that travels through the point in normalized device co...
Mat4d & getProj()
Get camera projection matrix, this matrix will be identity until first render is done.
const Vec3d & getPosition() const
Gets the camera position.
void setPosition(const Vec3d &pos)
Sets the camera position.
void setViewUp(const Vec3d &up)
Set the up vector.
double m_nearZ
near plane of the camera
void setNearZ(const double nearZ)
Set clipping near note: You lose depth accuracy as the range between near and far increases could cau...
Vec3d m_focalPoint
camera focal point
Produces a perpsective transformation matrix.
void setFocalPoint(const Vec3d &focalPt)
Sets the point to look at, point the camera towards.
Vec3d getForward() const
Get the forward/look direction of the view.
const Mat4d & getHMDView() const
Get the HMD view, supplied when using VR.
void setView(const Mat4d &view)
Set the camera view matrix.