6#ifndef MATERIALX_CAMERA_H
7#define MATERIALX_CAMERA_H
11MATERIALX_NAMESPACE_BEGIN
14using CameraPtr = std::shared_ptr<class Camera>;
23 _worldMatrix(Matrix44::IDENTITY),
24 _viewMatrix(Matrix44::IDENTITY),
25 _projectionMatrix(Matrix44::IDENTITY),
26 _arcballActive(
false),
27 _arcballQuat(Quaternion::IDENTITY),
28 _arcballDelta(Quaternion::IDENTITY),
35 static CameraPtr
create() {
return std::make_shared<Camera>(); }
67 _projectionMatrix = mat;
73 return _projectionMatrix;
79 return _worldMatrix * _viewMatrix * _projectionMatrix;
86 return Vector3(invView[3][0], invView[3][1], invView[3][2]);
93 return Vector3(invView[2][0], invView[2][1], invView[2][2]);
103 _viewportSize = size;
109 return _viewportSize;
115 v = transformPointPerspective(getWorldViewProjMatrix(), v);
117 v[0] *= _viewportSize[0];
118 v[1] *= _viewportSize[1];
125 v[0] /= _viewportSize[0];
126 v[1] /= _viewportSize[1];
128 v = transformPointPerspective(getWorldViewProjMatrix().getInverse(), v);
137 void arcballButtonEvent(
const Vector2& pos,
bool pressed);
140 bool applyArcballMotion(
const Vector2& pos);
145 return (_arcballDelta * _arcballQuat).toMatrix();
158 static Matrix44 createPerspectiveMatrix(
float left,
float right,
159 float bottom,
float top,
160 float nearP,
float farP);
163 static Matrix44 createOrthographicMatrix(
float left,
float right,
164 float bottom,
float top,
165 float nearP,
float farP);
168 static Matrix44 createPerspectiveMatrixZP(
float left,
float right,
169 float bottom,
float top,
170 float nearP,
float farP);
173 static Matrix44 createOrthographicMatrixZP(
float left,
float right,
174 float bottom,
float top,
175 float nearP,
float farP);
182 return Vector3(res[0], res[1], res[2]) / res[3];
204MATERIALX_NAMESPACE_END
Data types for rendering functionality.
A simple camera class, supporting transform matrices and arcball functionality for object-viewing app...
Definition: Camera.h:20
void setProjectionMatrix(const Matrix44 &mat)
Set the projection matrix.
Definition: Camera.h:65
Vector3 getViewPosition() const
Derive viewer position from the view matrix.
Definition: Camera.h:83
const Matrix44 & getWorldMatrix() const
Return the world matrix.
Definition: Camera.h:47
void setViewMatrix(const Matrix44 &mat)
Set the view matrix.
Definition: Camera.h:53
Vector3 unprojectFromViewport(Vector3 v)
Unproject a position from viewport to object space.
Definition: Camera.h:123
const Matrix44 & getViewMatrix() const
Return the view matrix.
Definition: Camera.h:59
Vector3 projectToViewport(Vector3 v)
Project a position from object to viewport space.
Definition: Camera.h:113
static Vector3 transformPointPerspective(const Matrix44 &m, const Vector3 &v)
Apply a perspective transform to the given 3D point, performing a homogeneous divide on the transform...
Definition: Camera.h:179
Vector3 getViewDirection() const
Derive viewer direction from the view matrix.
Definition: Camera.h:90
void setViewportSize(const Vector2 &size)
Set the size of the viewport window.
Definition: Camera.h:101
Matrix44 getWorldViewProjMatrix() const
Compute our full model-view-projection matrix.
Definition: Camera.h:77
const Matrix44 & getProjectionMatrix() const
Return the projection matrix.
Definition: Camera.h:71
const Vector2 & getViewportSize() const
Return the size of the viewport window.
Definition: Camera.h:107
void setWorldMatrix(const Matrix44 &mat)
Set the world matrix.
Definition: Camera.h:41
static CameraPtr create()
Create a new camera.
Definition: Camera.h:35
Matrix44 arcballMatrix() const
Return the arcball matrix.
Definition: Camera.h:143
A 4x4 matrix of floating-point values.
Definition: Types.h:656
Vector4 multiply(const Vector4 &v) const
Return the product of this matrix and a 4D vector.
Definition: Types.cpp:237
Matrix44 getInverse() const
Return the inverse of the matrix.
Definition: Types.h:685
A quaternion vector.
Definition: Types.h:21
A vector of two floating-point values.
Definition: Types.h:286
A vector of three floating-point values.
Definition: Types.h:306
A vector of four floating-point values.
Definition: Types.h:328