class methods
- ofCamera()
- ~ofCamera()
- begin()
- cameraToWorld()
- disableOrtho()
- drawFrustum()
- enableOrtho()
- end()
- getAspectRatio()
- getFarClip()
- getForceAspectRatio()
- getFov()
- getImagePlaneDistance()
- getLensOffset()
- getModelViewMatrix()
- getModelViewProjectionMatrix()
- getNearClip()
- getOrtho()
- getProjectionMatrix()
- isVFlipped()
- screenToWorld()
- setAspectRatio()
- setFarClip()
- setForceAspectRatio()
- setFov()
- setLensOffset()
- setNearClip()
- setRenderer()
- setVFlip()
- setupOffAxisViewPortal()
- setupPerspective()
- worldToCamera()
- worldToScreen()
Extends
This class extends others, you can call their methods on an instance of ofCamera too:
ofCamera provides a camera onto a 3D scene. Some of the different properties of the camera are shown in the picture below:
The far and near clip planes are the boundaries of what's visible in the camera. If you need more information on these, check http://www.falloutsoftware.com/tutorials/gl/gl0.htm
Documentation from code comments
A basic camera object for interacting with objects in 3D space.
By: Memo Akten, MSA Visuals Ltd. 2011
ofCamera()
ofCamera::ofCamera()
The default camera is positioned at (0, 0, 0) with a 60 degree field of view. Its up vector is the positive y-axis, and it is looking down the negative z-axis. Near and far planes are determined by the current viewport size.
Documentation from code comments
Construct a default camera.
begin()
void ofCamera::begin()
This function pushes the cameras view and projection matrix to a stack of transformations so that draw calls done within begin() and end() will appear to be viewed from the cameras perspective.
Documentation from code comments
Begins rendering with the camera.
void draw() {
// Begin rendering from the camera's perspective.
camera.begin();
ofLine(0, 0, ofGetWidth(), ofGetHeight());
// Additional rendering ...
// End rendering form the camera's perspective.
camera.end();
}
Parameters:
viewport The camera's rendering viewport.
cameraToWorld(...)
glm::vec3 ofCamera::cameraToWorld(glm::vec3 CameraXYZ)
When you have a position in camera coordinates you can get what it would be in world coordinates, transforming it using the ofCamera.
cameraToWorld(...)
glm::vec3 ofCamera::cameraToWorld(glm::vec3 CameraXYZ, const ofRectangle &viewport)
When you have a position in camera coordinates you can get what it would be in world coordinates, transforming it using the ofCamera.
Documentation from code comments
\todo cameraToWorld()
disableOrtho()
void ofCamera::disableOrtho()
Calling disableOrtho() turns off the orthographic mode.
drawFrustum(...)
void ofCamera::drawFrustum(const ofRectangle &viewport)
Documentation from code comments
Draw a visual representation of the camera's frustum \note This will only be visible when the camera drawing its frustum is viewed through another camera.
enableOrtho()
void ofCamera::enableOrtho()
Orthographic, or parallel, projections consist of those that involve no perspective correction. There is no adjustment for distance from the camera made in these projections, meaning objects on the screen will appear the same size no matter how close or far away they are. Calling enableOrtho() sets the ofCamera to orthographic mode.
end()
void ofCamera::end()
This removes the cameras view and projection matrix transformations from the stack so that draw calls performed afterward will not be viewed from the perspective of the camera. This is equivalent to performing an openGL PopMatrix call.
Documentation from code comments
Ends rendering with the camera.
getAspectRatio()
float ofCamera::getAspectRatio()
Documentation from code comments
Get the aspect ratio of this camera's viewport.
Returns the aspect ratio of this camera's viewport. Usually this will be the ratio of the width to height of your display. Intended for perspective cameras.
Returns: The aspect ratio of this camera's viewport.
getForceAspectRatio()
bool ofCamera::getForceAspectRatio()
Documentation from code comments
Get the boolean state which indicates whether the aspect ratio of this camera is forced to a non-default setting.
Returns: A boolean: whether or not this camera's aspect ratio is set to a non-default value.
getFov()
float ofCamera::getFov()
Documentation from code comments
Get the camera's field of view, in degrees.
Get the camera's vertical field of view, in degrees. This is only meaningful for perspective cameras.
Returns: The camera's field of view, in degrees.
getImagePlaneDistance(...)
float ofCamera::getImagePlaneDistance(const ofRectangle &viewport)
This allows you to get the image plane distance from any viewport passed in. By default this is the current viewport, but it can be whatever you find useful.
getLensOffset()
glm::vec2 ofCamera::getLensOffset()
Documentation from code comments
Get the "lens offset" applied to this camera, encoded as an ofVec2f.
Ordinarily, the camera is pointed straight down the center of its view frustum. However, it is possible to orient the camera towards a location offset from the center of its frustum. This is called an "asymetric frustum" and is used (for example) in stereo views. It is acheived by applying an offset to the center of projection. This function returns the offset that has been applied, as an ofVec2f. For more information see http://www.orthostereo.com/geometryopengl.html.
Returns: The "lens offset" applied to this camera, encoded in an ofVec2f.
getModelViewMatrix()
glm::mat4 ofCamera::getModelViewMatrix()
Access to the projection matrix.
Documentation from code comments
Access the model view matrix.
Returns: the current 4x4 model view matrix.
getModelViewProjectionMatrix()
glm::mat4 ofCamera::getModelViewProjectionMatrix()
Access to the projection ModelViewProjectionMatrix.
getModelViewProjectionMatrix(...)
glm::mat4 ofCamera::getModelViewProjectionMatrix(const ofRectangle &viewport)
Access to the projection ModelViewProjectionMatrix.
Documentation from code comments
\todo getModelViewProjectionMatrix()
getProjectionMatrix()
glm::mat4 ofCamera::getProjectionMatrix()
Access to the projection matrix.
Documentation from code comments
Access the projection matrix.
Returns: the current 4x4 projection matrix.
getProjectionMatrix(...)
glm::mat4 ofCamera::getProjectionMatrix(const ofRectangle &viewport)
Access to the projection matrix.
screenToWorld(...)
glm::vec3 ofCamera::screenToWorld(glm::vec3 ScreenXYZ)
When you have a position in screen coordinates you can get what it would be in world coordinates, transforming it using the ofCamera.
screenToWorld(...)
glm::vec3 ofCamera::screenToWorld(glm::vec3 ScreenXYZ, const ofRectangle &viewport)
When you have a position in screen coordinates you can get what it would be in world coordinates, transforming it using the ofCamera.
Documentation from code comments
Obtain the coordinates, in the 3D world, of a 2D point presumed to be on your screen.
Takes a pixel location on your screen, encoded in an ofVec3f, and returns (also as an ofVec3f) the 3D world coordinates of that point. You'll also need to specify a Z value when providing your screen point. This Z value is interpreted as a distance into or away from the screen.
Parameters:
ScreenXYZ A point on your screen, whose 3D world coordinates you wish to know.
setAspectRatio(...)
void ofCamera::setAspectRatio(float aspectRatio)
Documentation from code comments
Set the recommended aspect ratio for a perspective camera.
Sets the aspect ratio of the camera to the desired float, and forces the use of aspect ratio calculations. Currently only used with perspective cameras. The default value (and the value used with orthographic cameras) is the ratio of the viewport's width to the viewport's height.
Parameters:
aspectRatio The desired aspect ratio, e.g. 1.3333, 1.6, etc.
setForceAspectRatio(...)
void ofCamera::setForceAspectRatio(bool forceAspectRatio)
Documentation from code comments
Set whether or not the aspect ratio of this camera is forced to a non-default setting.
The camera's aspect ratio, by default, is the aspect ratio of your viewport. If you have set a non-default value (with ofCamera::setAspectRatio()), you can toggle whether or not this value is applied.
Parameters:
forceAspectRatio Whether or not this camera should use an aspect ratio you have set yourself.
setFov(...)
void ofCamera::setFov(float f)
Here you can set the field of view of the camera.
Documentation from code comments
Set the field of view for a perspective camera.
This sets the vertical field of view for the camera, in degrees. This only operates with perspective cameras, and will have no effect with cameras in orthographic mode.
Parameters:
f The desired field of view for the camera, in degrees.
setLensOffset(...)
void ofCamera::setLensOffset(const glm::vec2 &lensOffset)
Documentation from code comments
Set the "lens offset" applied to this camera.
Ordinarily, the camera is pointed straight down the center of its view frustum. However, it is possible to orient the camera towards a location offset from the center of its frustum. This is called an "assymetric frustum" and is used (for example) in stereo views. It is acheived by applying an offset to the center of projection. This function sets this offset from an ofVec2f argument. For more information see http://www.orthostereo.com/geometryopengl.html.
Parameters:
lensOffset The "lens offset" to apply to this camera, encoded in an ofVec2f.
setRenderer(...)
void ofCamera::setRenderer(shared_ptr< ofBaseRenderer > renderer)
Documentation from code comments
} \name Renderer {
setupOffAxisViewPortal(...)
void ofCamera::setupOffAxisViewPortal(const glm::vec3 &topLeft, const glm::vec3 &bottomLeft, const glm::vec3 &bottomRight)
setupPerspective(...)
void ofCamera::setupPerspective(bool vFlip=true, float fov, float nearDist, float farDist, const glm::vec2 &lensOffset)
Documentation from code comments
} \name OpenGL Setup {
worldToCamera(...)
glm::vec3 ofCamera::worldToCamera(glm::vec3 WorldXYZ)
When you have a position in world coordinates you can get what it would be in camera coordinates, transforming it using the ofCamera.
worldToCamera(...)
glm::vec3 ofCamera::worldToCamera(glm::vec3 WorldXYZ, const ofRectangle &viewport)
When you have a position in world coordinates you can get what it would be in camera coordinates, transforming it using the ofCamera.
Documentation from code comments
\todo worldToCamera()
worldToScreen(...)
glm::vec3 ofCamera::worldToScreen(glm::vec3 WorldXYZ)
When you have a position in world coordinates you can get what it would be in screen coordinates, transforming it using the ofCamera.
worldToScreen(...)
glm::vec3 ofCamera::worldToScreen(glm::vec3 WorldXYZ, const ofRectangle &viewport)
When you have a position in world coordinates you can get what it would be in screen coordinates, transforming it using the ofCamera.
Documentation from code comments
Obtain the screen coordinates of a point in the 3D world.
Takes an (X,Y,Z) point in your 3D world, encoded as an ofVec3f, and returns the location (also as an ofVec3f) where this point would appear on your (two-dimensional) display. The screen position's "Z coordinate" is set to be the same as your camera's.
Parameters:
WorldXYZ A 3D point in the world, whose screen coordinates you wish to know.
viewport (Optional) A viewport. The default is ofGetCurrentViewport().
Returns: An ofVec3f containing the screen coordinates of your 3D point of interest.
Last updated 화요일, 19 11월 2024 17:24:06 UTC - 2537ee49f6d46d5fe98e408849448314fd1f180e
If you have any doubt about the usage of this module you can ask in the forum.
If you want to contribute better documentation or start documenting this section you can do so here
If you find anything wrong with this docs you can report any error by opening an issue