osg.Camera

class osg.Camera
Represents

c++ class

Wraps

osg::Camera

Bases

osg.Transform, osg.CullSettings

osg.Camera - is a subclass of osg.Transform which represents encapsulates the settings of a Camera.

-- Example of Camera positioning.

-- Setting one of view matrices from viewMatrix table to change camera's
-- position every <period> seconds.
-- Camera's 'center' is coordinate system origin and 'up' is aligned with z axis.

-- Getting default main camera
local mainCamera = viewer:getCamera()

local distance  = 0.3   -- metres
local altitude  = 0.2   -- metres
local center    = osg.Vec3(0.0, 0.0, 0.0)
local up        = osg.Vec3(0.0, 0.0, 1.0)

local viewMatrix = {
    osg.Matrix.lookAt(osg.Vec3(0.0, -distance, altitude), center, up),  -- Front
    osg.Matrix.lookAt(osg.Vec3(-distance, 0.0, altitude), center, up),  -- Left
    osg.Matrix.lookAt(osg.Vec3(0.0, distance, altitude), center, up),   -- Back
    osg.Matrix.lookAt(osg.Vec3(distance, 0.0, altitude), center, up),   -- Rigth
}

local period        = 2.0   -- seconds
local currentMatrix = 1

local timer = reactorController:getReactorByName("timer") -- must be presented in the project
timer:subscribeEvent("onAlarm", function()
    currentMatrix = currentMatrix % #viewMatrix + 1
    mainCamera:setViewMatrix(viewMatrix[currentMatrix])
end)

mainCamera:setClearColor(osg.Vec4(163/255.0, 182/255.0, 1.0, 1.0))  -- change clear color for convenience
mainCamera:setViewMatrix(viewMatrix[currentMatrix]) -- initial positioning
timer:start(period, timer.Mode.LOOP)

There is also more complex example of render-to-texture (RTT) camera creation.

Constructors:

osg.Camera()

Construct a camera.

Methods:

:setAllowEventFocus(bool allow)

Set whether this osg.Camera allows events to be generated by the associated graphics window to be associated with this osg.Camera.

Параметры

allow (bool) – Must be true to allow focus, false otherwise.

:getAllowEventFocus()

Get whether this osg.Camera allows events to be generated by the associated graphics window to be associated with this osg.Camera.

Тип результата

bool

:setClearMask(unsigned mask)

Параметры

mask (unsigned) –

:getClearMask()

Тип результата

unsigned

:setClearColor(osg.Vec4 color)

Set the clear color used in glClearColor() (https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glClearColor.xml).

Параметры

color (osg.Vec4) – Clear color.

:getClearColor()

Get the clear color.

Тип результата

osg.Vec4

:setClearAccum(osg.Vec4 color)

Set the clear accum used in glClearAccum() (https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glClearAccum.xml). glClearAcumm is only called if mask & GL_ACCUM_BUFFER_BIT is true.

Параметры

color (osg.Vec4) –

:getClearAccum()

Get the clear accum value.

Тип результата

osg.Vec4

:setClearDepth(double depth)

Set the clear depth used in glClearDepth() (https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glClearDepth.xml). Defaults to 1.0; glClearDepth is only called if mask & GL_DEPTH_BUFFER_BIT is true.

Параметры

depth (double) –

:getClearDepth()

Get the clear depth value.

Тип результата

double

:setClearStencil(int depth)

Set the clear stencil value used in glClearStencil() (https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glClearStencil.xml). Defaults to 0; glClearStencil is only called if mask & GL_STENCIL_BUFFER_BIT is true.

Параметры

depth (int) –

:getClearStencil()

Get the clear stencil value.

Тип результата

int

:setColorMask(bool r, bool g, bool b, bool a)

Set the color mask of the osg.Camera to specified values.

Параметры
  • r (bool) –

  • g (bool) –

  • b (bool) –

  • a (bool) –

:setViewport(int x, int y, int width, int height)

Set the viewport of the osg.Camera to specified dimensions.

Параметры
  • x (int) –

  • y (int) –

  • width (int) –

  • height (int) –

:getViewport()

Get the viewport.

Тип результата

osg.Viewport

:setTransformOrder(osg.Camera.TransformOrder order)

Set the transformation order for world-to-local and local-to-world transformation.

Параметры

order (osg.Camera.TransformOrder) –

:getTransformOrder()

Get the transformation order.

Тип результата

osg.Camera.TransformOrder

:setProjectionResizePolicy(osg.Camera.ProjectionResizePolicy policy)

Set the policy used to determine if and how the projection matrix should be adjusted on window resizes.

Параметры

policy (osg.Camera.ProjectionResizePolicy) –

:getProjectionResizePolicy()

Get the policy used to determine if and how the projection matrix should be adjusted on window resizes.

Тип результата

osg.Camera.ProjectionResizePolicy

:getProjectionMatrix()

Get the projection matrix.

Тип результата

osg.Matrix

:setProjectionMatrix(osg.Matrix projmat)

Set the projection matrix. Can be thought of as setting the lens of a osg.Camera.

Параметры

projmat (osg.Matrix) –

:setProjectionMatrixAsOrtho(double left, double right, double bottom, double top, double zNear, double zFar)

Set to an orthographic projection. See OpenGL glOrtho for documentation further details (https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glOrtho.xml).

Параметры
  • left (double) –

  • right (double) –

  • bottom (double) –

  • top (double) –

  • zNear (double) –

  • zFar (double) –

:setProjectionMatrixAsOrtho2D(double left, double right, double bottom, double top)

Set to a 2D orthographic projection. See OpenGL glOrtho2D documentation for further details (https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/gluOrtho2D.xml).

Параметры
  • left (double) –

  • right (double) –

  • bottom (double) –

  • top (double) –

:setProjectionMatrixAsFrustum(double left, double right, double bottom, double top, double zNear, double zFar)

Set to a perspective projection. See OpenGL glFrustum documentation for further details (https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glFrustum.xml).

Параметры
  • left (double) –

  • right (double) –

  • bottom (double) –

  • top (double) –

  • zNear (double) –

  • zFar (double) –

:setProjectionMatrixAsPerspective(double fovy, double ratio, double zNear, double zFar)

Create a symmetrical perspective projection, See OpenGL gluPerspective documentation for further details (https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/gluPerspective.xml). Aspect ratio is defined as width/height.

Параметры
  • fovy (double) –

  • ratio (double) –

  • zNear (double) –

  • zFar (double) –

:getProjectionMatrixAsPerspective()

Get the frustum setting of a symmetric perspective projection matrix. Returns false if matrix is not a perspective matrix, where parameter values are undefined. Note, if matrix is not a symmetric perspective matrix then the shear will be lost. Asymmetric matrices occur when stereo, power walls, caves and reality center display are used. In these configurations one should use the getProjectionMatrixAsFrustum method instead.

:setViewMatrix(osg.Matrix viewmat)

Set the view matrix. Can be thought of as setting the position of the world relative to the camera in camera coordinates.

Параметры

viewmat (osg.Matrix) –

:getViewMatrix()

Get the view matrix.

Тип результата

osg.Matrix

:setViewMatrixAsLookAt(osg.Vec3 eye, osg.Vec3 center, osg.Vec3 up)

Set to the position and orientation of view matrix, using the same convention as gluLookAt (https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/gluLookAt.xml).

Параметры
:getViewMatrixAsLookAt()

Helper function. Short version. getViewMatrixAsLookAt call with 1.0 as lookDistance argument.

:getViewMatrixAsLookAt(double lookDistance)

Get to the position and orientation of a modelview matrix, using the same convention as gluLookAt (https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/gluLookAt.xml). Helper function, returns 3 values: eye as osg.Vec3, center as osg.Vec3 and up as osg.Vec3.

Параметры

lookDistance (double) –

:getInverseViewMatrix()

Get the inverse view matrix.

Тип результата

osg.Matrix

:setRenderOrder(osg.Camera.RenderOrder order, int orderNum)

Set the rendering order of this osg.Camera’s subgraph relative to any camera that this subgraph is nested within. For rendering to a texture, one typically uses osg.Camera.PRE_RENDER. For Head Up Displays, one would typically use osg.Camera.POST_RENDER from osg.Camera.RenderOrder.

Параметры
:getRenderOrder()

Get the rendering order of this osg.Camera’s subgraph relative to any camera that this subgraph is nested within.

Тип результата

osg.Camera.RenderOrder

:getRenderOrderNum()

Get the rendering order number of this camera relative to any sibling cameras in this subgraph.

Тип результата

int

:isRenderToTextureCamera()

Return true if this osg.Camera is set up as a render to texture camera, i.e. it has textures assigned to it.

Тип результата

bool

:attach(osg.Camera.BufferComponent buffer, GLenum.Value internalFormat)

Attach a buffer with specified OpenGL internal format.

Параметры
:attach(osg.Camera.BufferComponent buffer, osg.Texture texture)

Helper function. Short version. attach call with level equal to 0, face equal to 0, mipMapGeneration equal to false, multisampleSamples equal to 0 and multisampleColorSamples equal to 0.

Параметры
:attach(osg.Camera.BufferComponent buffer, osg.Texture texture, unsigned level, int face, bool mipMapGeneration, unsigned multisampleSamples, unsigned multisampleColorSamples)

Attach a osg.Texture to specified buffer component. The level parameter controls the mip map level of the texture that is attached. The face parameter controls the face of texture cube map or z level of 3d texture. The mipMapGeneration flag controls whether mipmap generation should be done for texture.

Параметры
  • buffer (osg.Camera.BufferComponent) –

  • texture (osg.Texture) –

  • level (unsigned) –

  • face (int) –

  • mipMapGeneration (bool) –

  • multisampleSamples (unsigned) –

  • multisampleColorSamples (unsigned) –

:attachImage(osg.Camera.BufferComponent buffer, osg.Image image)

Helper function. Short version. attachImage call with multisampleSamples equal to 0.0 and multisampleColorSamples equal to 0.

Параметры
:attachImage(osg.Camera.BufferComponent buffer, osg.Image image, unsigned multisampleSamples, unsigned multisampleColorSamples)

Attach a osg.Image to specified buffer component.

Параметры
:detach(osg.Camera.BufferComponent buffer)

Detach specified buffer component.

Параметры

buffer (osg.Camera.BufferComponent) –

:setGraphicsContext(osg.GraphicsContext ctx)

Set the osg.GraphicsContext that provides the mechansim for managing the OpenGL graphics context associated with this osg.Camera.

Параметры

ctx (osg.GraphicsContext) –

:getGraphicsContext()

Get the osg.GraphicsContext.

Тип результата

osg.GraphicsContext

:setRenderer(osg.GraphicsOperation renderer)

Set the Rendering object that is used to implement rendering of the subgraph.

Параметры

renderer (osg.GraphicsOperation) –

:getRenderer()

Get the Rendering object that is used to implement rendering of the subgraph.

Тип результата

osg.GraphicsOperation

:setRenderingCache(osg.Object rc)

Set the Rendering cache that is used for cached objects associated with rendering of subgraphs.

Параметры

rc (osg.Object) –

:getRenderingCache()

Get the const Rendering cache that is used for cached objects associated with rendering of subgraphs.

Тип результата

osg.Object

:setRenderTargetImplementation(osg.Camera.RenderTargetImplementation impl)

Set the render target.

Параметры

impl (osg.Camera.RenderTargetImplementation) –

:setRenderTargetImplementation(osg.Camera.RenderTargetImplementation impl, osg.Camera.RenderTargetImplementation fallback)

Set the render target and fallback that’s used if the former isn’t available.

Параметры
:getRenderTargetImplementation()

Get the render target.

Тип результата

osg.Camera.RenderTargetImplementation

:getRenderTargetFallback()

Тип результата

osg.Camera.RenderTargetImplementation

:setDrawBuffer(int buffer)

Set the draw buffer used at the start of each frame draw. Note, a buffer value of GLenum.GL_NONE from is used to specify that the rendering back-end should choose the most appropriate buffer.

Параметры

buffer (int) –

:setReadBuffer(int buffer)

Set the read buffer for any required copy operations to use. Note, a buffer value of GLenum.GL_NONE is used to specify that the rendering back-end should choose the most appropriate buffer.

Параметры

buffer (int) –

:setProcessorAffinity(OpenThreads.Affinity affinity)

Set the process affinity hint for any Camera Threads that are/will be assigned to this osg.Camera.

Параметры

affinity (OpenThreads.Affinity) –

:getProcessorAffinity()

Тип результата

OpenThreads.Affinity

:setInitialDrawCallback(osg.Camera.DrawCallback cb)

Set the initial draw callback for custom operations to be done before the drawing of the camera’s subgraph and pre render stages.

Параметры

cb (osg.Camera.DrawCallback) –

:getInitialDrawCallback()

Get the initial draw callback.

Тип результата

osg.Camera.DrawCallback

:addInitialDrawCallback(osg.Camera.DrawCallback nc)

Convenience method that sets DrawCallback Initial callback of the node if it doesn’t exist, or nest it into the existing one.

Параметры

nc (osg.Camera.DrawCallback) –

:removeInitialDrawCallback(osg.Camera.DrawCallback nc)

Convenience method that removes a given callback from a node, even if that callback is nested. There is no error return in case the given callback is not found.

Параметры

nc (osg.Camera.DrawCallback) –

:setPreDrawCallback(osg.Camera.DrawCallback cb)

Set the pre draw callback for custom operations to be done before the drawing of the camera’s subgraph but after any pre render stages have been completed.

Параметры

cb (osg.Camera.DrawCallback) –

:getPreDrawCallback()

Get the pre draw callback.

Тип результата

osg.Camera.DrawCallback

:addPreDrawCallback(osg.Camera.DrawCallback nc)

Convenience method that sets DrawCallback Initial callback of the node if it doesn’t exist, or nest it into the existing one.

Параметры

nc (osg.Camera.DrawCallback) –

:removePreDrawCallback(osg.Camera.DrawCallback nc)

Convenience method that removes a given callback from a node, even if that callback is nested. There is no error return in case the given callback is not found.

Параметры

nc (osg.Camera.DrawCallback) –

:setPostDrawCallback(osg.Camera.DrawCallback cb)

Set the post draw callback for custom operations to be done after the drawing of the camera’s subgraph but before the any post render stages have been completed.

Параметры

cb (osg.Camera.DrawCallback) –

:getPostDrawCallback()

Get the post draw callback.

Тип результата

osg.Camera.DrawCallback

:addPostDrawCallback(osg.Camera.DrawCallback nc)

Convenience method that sets DrawCallback Initial callback of the node if it doesn’t exist, or nest it into the existing one.

Параметры

nc (osg.Camera.DrawCallback) –

:removePostDrawCallback(osg.Camera.DrawCallback nc)

Convenience method that removes a given callback from a node, even if that callback is nested. There is no error return in case the given callback is not found.

Параметры

nc (osg.Camera.DrawCallback) –

:setFinalDrawCallback(osg.Camera.DrawCallback cb)

Set the final draw callback for custom operations to be done after the drawing of the camera’s subgraph and all of the post render stages has been completed.

Параметры

cb (osg.Camera.DrawCallback) –

:getFinalDrawCallback()

Get the final draw callback.

Тип результата

osg.Camera.DrawCallback

:addFinalDrawCallback(osg.Camera.DrawCallback nc)

Convenience method that sets DrawCallback Initial callback of the node if it doesn’t exist, or nest it into the existing one.

Параметры

nc (osg.Camera.DrawCallback) – Convenience method that removes a given callback from a node, even if that callback is nested. There is no error return in case the given callback is not found.

:removeFinalDrawCallback(osg.Camera.DrawCallback nc)

Параметры

nc (osg.Camera.DrawCallback) –