GLSL Hacker
FEATURES DOWNLOAD GALLERY BLOG LEARN



» Back to Reference Guide Index

gh_camera Library

Description

gh_camera is the module that manages cameras: creation, destruction, setting the parameters (position, filed of view, etc.).

Number of functions: 23



gh_camera.bind

Description

Bind the camera to the renderer: the viewport and projection/view matrices are applied. This function is useful in conjunction with the gh_object.render() function.

Languages

Lua - Python

Parameters

  • camera [INTEGER]: camera identifier.

    Return Values

    This function has no return value(s).

    Code sample


    gh_camera.bind(camera)



    gh_camera.bind_v2

    Description

    Bind the camera to the renderer: the viewport and projection/view matrices are applied. This function is useful in conjunction with the gh_object.render() function.

    Languages

    Lua - Python

    Parameters

  • camera [INTEGER]: camera identifier.
  • update_viewport [INTEGER]: updates (1) or not (0) the viewport.
  • update_scissor [INTEGER]: updates (1) or not (0) the scissor rectangle (same size than the viewport).
  • update_proj_mat [INTEGER]: updates (1) or not (0) the projection matrix.
  • update_view_mat [INTEGER]: updates (1) or not (0) the view matrix.
  • update_fixed_pipeline [INTEGER]: updates (1) or not (0) the fixed pipeline (so you will have access to gl_ModelViewProjectionMatrix in a vertex shader for example)

    Return Values

    This function has no return value(s).

    Code sample


    local update_viewport = 1
    local update_scissor = 0
    local update_proj_mat = 1
    local update_view_mat = 1
    local update_fixed_pipeline = 0
    gh_camera.bind_v2(camera, update_viewport, update_scissor, update_proj_mat, update_view_mat, update_fixed_pipeline)



    gh_camera.create_ortho

    Description

    Creates an orthographic camera.

    Languages

    Lua - Python

    Parameters

  • left [REAL]: left clipping plane.
  • right [REAL]: right clipping plane.
  • bottom [REAL]: bottom clipping plane.
  • top [REAL]: top clipping plane.
  • znear [REAL]: near clipping plane.
  • zfar [REAL]: far clipping plane.

    Return Values

  • camera [INTEGER]: camera identifier

    Code sample


    w = screen_width
    h = screen_height
    camera = gh_camera.create_ortho(-w/2, w/2, -h/2, h/2, -1.0, 1.0)



    gh_camera.create_orthographic

    Description

    Creates an orthographic camera with default values: left, right, top, bottom are derived from the window size.

    Languages

    Lua - Python

    Parameters

    This function has no input parameter(s).

    Return Values

  • camera [INTEGER]: camera identifier

    Code sample


    camera = gh_camera.create_orthographic()



    gh_camera.create_persp

    Description

    Creates a perspective camera.

    Languages

    Lua - Python

    Parameters

  • fov [REAL]: field of view in degres.
  • aspect [REAL]: aspect ration (usually screen_width / screen_height).
  • znear [REAL]: near clipping plane.
  • zfar [REAL]: far clipping plane.

    Return Values

  • camera [INTEGER]: camera identifier

    Code sample


    camera = gh_camera.create_persp(60, 1.333, 0.1, 1000.0)



    gh_camera.create_persp_v2

    Description

    Creates a perspective camera.

    Languages

    Lua - Python

    Parameters

  • fov [REAL]: field of view in degres.
  • is_vertical_fov [INTEGER]: vertical fov (1) or horizontal fov (0).
  • aspect [REAL]: aspect ration (usually screen_width / screen_height).
  • znear [REAL]: near clipping plane.
  • zfar [REAL]: far clipping plane.

    Return Values

  • camera [INTEGER]: camera identifier

    Code sample


    camera = gh_camera.create_persp_v2(60, 1, 1.333, 0.1, 1000.0)



    gh_camera.create_perspective

    Description

    Creates a perspective camera with default values (fov=60, znear=1, zfar=1000, aspect=win_width/win/height).

    Languages

    Lua - Python

    Parameters

  • pos_x, pos_y, pos_z [REAL]: position of the camera.
  • lookat_x, lookat_y, lookat_z [REAL]: look at point of the camera.

    Return Values

  • camera [INTEGER]: camera identifier

    Code sample


    camera = gh_camera.create_perspective(0, 20, 0, 0, 0, 0)



    gh_camera.get_fov

    Description

    Gets the camera field of view (fov).

    Languages

    Lua - Python

    Parameters

  • camera [INTEGER]: camera identifier.

    Return Values

  • fov [REAL]: vertical field of view in degrees.

    Code sample


    fov = gh_camera.get_fov(camera)



    gh_camera.get_position

    Description

    Gets the camera position.

    Languages

    Lua - Python

    Parameters

  • camera [INTEGER]: camera identifier.

    Return Values

  • x, y, z [REAL]: position

    Code sample


    x, y, z = gh_camera.get_position(camera)



    gh_camera.get_view

    Description

    Gets the camera direction (z axis or view vector).

    Languages

    Lua - Python

    Parameters

  • camera [INTEGER]: camera identifier.

    Return Values

  • x, y, z [REAL]: view vector

    Code sample


    x, y, z = gh_camera.get_view(camera)



    gh_camera.get_up_vector

    Description

    Gets the camera up vector (y axis).

    Languages

    Lua - Python

    Parameters

  • camera [INTEGER]: camera identifier.

    Return Values

  • x, y, z [REAL]: up vector

    Code sample


    x, y, z = gh_camera.get_up_vector(camera)



    gh_camera.set_fov

    Description

    Sets the camera field of view (fov).

    Languages

    Lua - Python

    Parameters

  • camera [INTEGER]: camera identifier.
  • fov [REAL]: vertical field of view in degrees.

    Return Values

    This function has no return value(s).

    Code sample


    gh_camera.set_fov(camera, 90)



    gh_camera.set_lookat

    Description

    Sets the camera look at point (what point in space the camera is looking).

    Languages

    Lua - Python

    Parameters

  • camera [INTEGER]: camera identifier.
  • x, y, z, w [REAL]: 4D position of that target point. If w=1, target is a point, otherwise target is a direction

    Return Values

    This function has no return value(s).

    Code sample


    -- Look at the center of the scene:
    gh_camera.set_lookat(camera, 0, 0, 0, 1)



    gh_camera.set_orientation_cubemap

    Description

    Sets the camera orientation according to a cubemap face.

    Languages

    Lua - Python

    Parameters

  • camera [INTEGER]: camera identifier.
  • face [INTEGER]: cubemap face (0 to 5).

    Return Values

    This function has no return value(s).

    Code sample


    for face=0, 5 do
    gh_camera.set_orientation_cubemap(camera, face)
    ...
    end



    gh_camera.set_pitch

    Description

    Sets the camera pitch angle (x axis).

    Languages

    Lua - Python

    Parameters

  • camera [INTEGER]: camera identifier.
  • pitch [REAL]: pitch in degrees.

    Return Values

    This function has no return value(s).

    Code sample


    gh_camera.set_pitch(camera, pitch)



    gh_camera.set_position

    Description

    Sets the camera position.

    Languages

    Lua - Python

    Parameters

  • camera [INTEGER]: camera identifier.
  • x, y, z [REAL]: 3D position of the camera.

    Return Values

    This function has no return value(s).

    Code sample


    gh_camera.set_position(camera, 0, 10, 20)



    gh_camera.set_roll

    Description

    Sets the camera roll angle (z axis).

    Languages

    Lua - Python

    Parameters

  • camera [INTEGER]: camera identifier.
  • roll [REAL]: roll in degrees.

    Return Values

    This function has no return value(s).

    Code sample


    gh_camera.set_roll(camera, roll)



    gh_camera.set_upvec

    Description

    Sets the camera up vector.

    Languages

    Lua - Python

    Parameters

  • camera [INTEGER]: camera identifier.
  • x, y, z [REAL]: direction of the up vector.

    Return Values

    This function has no return value(s).

    Code sample


    -- Th up vector is the unit Y axis.
    gh_camera.set_upvec(camera, 0, 1, 0)



    gh_camera.set_viewport

    Description

    Sets the camera viewport.

    Languages

    Lua - Python

    Parameters

  • camera [INTEGER]: camera identifier.
  • x [REAL]: x offset - default: 0.
  • y [REAL]: y offset - default: 0.
  • width [REAL]: width of the viewport.
  • height [REAL]: height of the viewport.

    Return Values

    This function has no return value(s).

    Code sample


    gh_camera.set_viewport(camera, 0, 0, screen_width, screen_height)



    gh_camera.set_yaw

    Description

    Sets the camera yaw angle (y axis).

    Languages

    Lua - Python

    Parameters

  • camera [INTEGER]: camera identifier.
  • yaw [REAL]: yaw in degrees.

    Return Values

    This function has no return value(s).

    Code sample


    gh_camera.set_yaw(camera, yaw)



    gh_camera.update_ortho

    Description

    Updates an orthographic camera.

    Languages

    Lua - Python

    Parameters

  • camera [INTEGER]: camera identifier.
  • left [REAL]: left clipping plane.
  • right [REAL]: right clipping plane.
  • bottom [REAL]: bottom clipping plane.
  • top [REAL]: top clipping plane.
  • znear [REAL]: near clipping plane.
  • zfar [REAL]: far clipping plane.

    Return Values

    This function has no return value(s).

    Code sample


    w = screen_width
    h = screen_height
    gh_camera.update_ortho(camera, -w/2, w/2, -h/2, h/2, 1.0, -1.0)



    gh_camera.update_persp

    Description

    Updates a perspective camera.

    Languages

    Lua - Python

    Parameters

  • camera [INTEGER]: camera identifier.
  • fov [REAL]: field of view in degres.
  • aspect [REAL]: aspect ration (usually screen_width / screen_height).
  • znear [REAL]: near clipping plane.
  • zfar [REAL]: far clipping plane.

    Return Values

    This function has no return value(s).

    Code sample


    gh_camera.update_persp(camera, 60, 1.333, 0.1, 1000.0)



    gh_camera.update_persp_v2

    Description

    Updates a perspective camera.

    Languages

    Lua - Python

    Parameters

  • camera [INTEGER]: camera identifier.
  • fov [REAL]: field of view in degres.
  • is_vertical_fov [INTEGER]: vertical fov (1) or horizontal fov (0).
  • aspect [REAL]: aspect ration (usually screen_width / screen_height).
  • znear [REAL]: near clipping plane.
  • zfar [REAL]: far clipping plane.

    Return Values

    This function has no return value(s).

    Code sample


    local is_vertical_fov = 1
    gh_camera.update_persp_v2(camera, 60, is_vertical_fov, 1.333, 0.1, 1000.0)





    2013-2015 Geeks3D. All Rights Reserved.

    .:- G3D Network -:.