reference

This documentation is automatically generated from the openFrameworks source code using doxygen and refers to the most recent release, version 0.12.0.

ofCamera.h
Go to the documentation of this file.
1#pragma once
2
3#include "ofNode.h"
4
5class ofRectangle;
6
7// \todo Use the public API of ofNode for all transformations
8// \todo add set projection matrix
9// \todo support for left handed or right handed?
10
13class ofCamera : public ofNode {
14public:
17
19 ofCamera();
20
22 virtual ~ofCamera();
23
27
35 void setFov(float f);
36
37 void setNearClip(float f);
38
39 void setFarClip(float f);
40
53 void setLensOffset(const glm::vec2 & lensOffset);
54
63 void setAspectRatio(float aspectRatio);
64
73 void setForceAspectRatio(bool forceAspectRatio);
74
81 float getFov() const { return fov; };
82
83 float getNearClip() const { return nearClip; };
84
85 float getFarClip() const { return farClip; };
86
98 glm::vec2 getLensOffset() const { return lensOffset; };
99
103 bool getForceAspectRatio() const {return forceAspectRatio;};
104
112 float getAspectRatio() const {return aspectRatio; };
113
117
118 void setupPerspective(bool vFlip = true, float fov = 60, float nearDist = 0, float farDist = 0, const glm::vec2 & lensOffset = glm::vec2(0.0f, 0.0f));
119
120 void setupOffAxisViewPortal(const glm::vec3 & topLeft, const glm::vec3 & bottomLeft, const glm::vec3 & bottomRight);
121
122 void setVFlip(bool vflip);
123
124 bool isVFlipped() const;
125
126 void enableOrtho();
127
128 void disableOrtho();
129
130 bool getOrtho() const;
131
132 float getImagePlaneDistance(const ofRectangle & viewport = ofRectangle()) const;
133
137
153 virtual void begin(){
155 }
156 virtual void begin(const ofRectangle & viewport);
157
159 virtual void end();
160
164
167 glm::mat4 getProjectionMatrix() const{
169 }
170 glm::mat4 getProjectionMatrix(const ofRectangle & viewport) const;
171
174 glm::mat4 getModelViewMatrix() const;
175
177 glm::mat4 getModelViewProjectionMatrix(const ofRectangle & viewport) const;
181
185
196 glm::vec3 worldToScreen(glm::vec3 WorldXYZ, const ofRectangle & viewport) const;
197 glm::vec3 worldToScreen(glm::vec3 WorldXYZ) const{
198 return worldToScreen(WorldXYZ, getViewport());
199 }
200
209 glm::vec3 screenToWorld(glm::vec3 ScreenXYZ, const ofRectangle & viewport) const;
210 glm::vec3 screenToWorld(glm::vec3 ScreenXYZ) const{
211 return screenToWorld(ScreenXYZ, getViewport());
212 }
213
215 glm::vec3 worldToCamera(glm::vec3 WorldXYZ, const ofRectangle & viewport) const;
216 glm::vec3 worldToCamera(glm::vec3 WorldXYZ) const{
217 return worldToCamera(WorldXYZ, getViewport());
218 }
219
221 glm::vec3 cameraToWorld(glm::vec3 CameraXYZ, const ofRectangle & viewport) const;
222 glm::vec3 cameraToWorld(glm::vec3 CameraXYZ) const{
223 return cameraToWorld(CameraXYZ, getViewport());
224 }
225
229
230 void setRenderer(std::shared_ptr<ofBaseRenderer> renderer);
231
233
237 void drawFrustum(const ofRectangle & viewport) const;
238 void drawFrustum() const{
240 }
241
242protected:
243 ofRectangle getViewport() const;
244 std::shared_ptr<ofBaseRenderer> getRenderer() const;
245 void calcClipPlanes(const ofRectangle & viewport);
246
247private:
248 bool isOrtho;
249 float fov;
250 float nearClip;
251 float farClip;
252 glm::vec2 lensOffset;
253 bool forceAspectRatio;
254 float aspectRatio; // only used when forceAspect=true, = w / h
255 bool vFlip;
256 std::shared_ptr<ofBaseRenderer> renderer;
257};
258
A basic camera object for interacting with objects in 3D space.
Definition ofCamera.h:13
ofRectangle getViewport() const
Definition ofCamera.cpp:232
void setForceAspectRatio(bool forceAspectRatio)
Set whether or not the aspect ratio of this camera is forced to a non-default setting.
Definition ofCamera.cpp:54
float getFov() const
Get the camera's field of view, in degrees.
Definition ofCamera.h:81
void setAspectRatio(float aspectRatio)
Set the recommended aspect ratio for a perspective camera.
Definition ofCamera.cpp:48
glm::vec3 screenToWorld(glm::vec3 ScreenXYZ) const
Definition ofCamera.h:210
virtual void end()
Ends rendering with the camera.
Definition ofCamera.cpp:142
void enableOrtho()
Definition ofCamera.cpp:116
void setupPerspective(bool vFlip=true, float fov=60, float nearDist=0, float farDist=0, const glm::vec2 &lensOffset=glm::vec2(0.0f, 0.0f))
Definition ofCamera.cpp:59
bool getForceAspectRatio() const
Get the boolean state which indicates whether the aspect ratio of this camera is forced to a non-defa...
Definition ofCamera.h:103
void setNearClip(float f)
Definition ofCamera.cpp:33
bool getOrtho() const
Definition ofCamera.cpp:126
void setRenderer(std::shared_ptr< ofBaseRenderer > renderer)
Definition ofCamera.cpp:244
glm::vec3 screenToWorld(glm::vec3 ScreenXYZ, const ofRectangle &viewport) const
Obtain the coordinates, in the 3D world, of a 2D point presumed to be on your screen.
Definition ofCamera.cpp:191
void calcClipPlanes(const ofRectangle &viewport)
Definition ofCamera.cpp:223
glm::mat4 getProjectionMatrix() const
Access the projection matrix.
Definition ofCamera.h:167
glm::vec2 getLensOffset() const
Get the "lens offset" applied to this camera, encoded as an glm::vec2.
Definition ofCamera.h:98
glm::vec3 worldToCamera(glm::vec3 WorldXYZ) const
Definition ofCamera.h:216
virtual ~ofCamera()
Destroy the camera.
Definition ofCamera.cpp:25
glm::vec3 worldToScreen(glm::vec3 WorldXYZ) const
Definition ofCamera.h:197
void drawFrustum() const
Definition ofCamera.h:238
void disableOrtho()
Definition ofCamera.cpp:121
glm::vec3 worldToScreen(glm::vec3 WorldXYZ, const ofRectangle &viewport) const
Obtain the screen coordinates of a point in the 3D world.
Definition ofCamera.cpp:179
glm::vec3 worldToCamera(glm::vec3 WorldXYZ, const ofRectangle &viewport) const
Definition ofCamera.cpp:202
glm::mat4 getModelViewMatrix() const
Access the model view matrix.
Definition ofCamera.cpp:169
glm::vec3 cameraToWorld(glm::vec3 CameraXYZ) const
Definition ofCamera.h:222
float getAspectRatio() const
Get the aspect ratio of this camera's viewport.
Definition ofCamera.h:112
std::shared_ptr< ofBaseRenderer > getRenderer() const
Definition ofCamera.cpp:236
void setLensOffset(const glm::vec2 &lensOffset)
Set the "lens offset" applied to this camera.
Definition ofCamera.cpp:43
glm::vec3 cameraToWorld(glm::vec3 CameraXYZ, const ofRectangle &viewport) const
Definition ofCamera.cpp:213
ofCamera()
Construct a default camera.
Definition ofCamera.cpp:12
glm::mat4 getModelViewProjectionMatrix() const
Definition ofCamera.h:178
void setupOffAxisViewPortal(const glm::vec3 &topLeft, const glm::vec3 &bottomLeft, const glm::vec3 &bottomRight)
Definition ofCamera.cpp:82
float getNearClip() const
Definition ofCamera.h:83
void setFov(float f)
Set the field of view for a perspective camera.
Definition ofCamera.cpp:28
float getFarClip() const
Definition ofCamera.h:85
bool isVFlipped() const
Definition ofCamera.cpp:111
virtual void begin()
Begins rendering with the camera.
Definition ofCamera.h:153
void setFarClip(float f)
Definition ofCamera.cpp:38
void setVFlip(bool vflip)
Definition ofCamera.cpp:106
float getImagePlaneDistance(const ofRectangle &viewport=ofRectangle()) const
Definition ofCamera.cpp:131
A generic 3d object in space with transformation (position, rotation, scale).
Definition ofNode.h:14
A class representing a 2D rectangle.
Definition ofRectangle.h:87