Quick Links
  • Homepage
        - Overview
        - Download
        - Screenshots
        - Community
  • Code Sample Pack
  • Reference Guide
  • Changelog
  • Overview of GLSL Hacker
  • Live Coding
  • Hack your first GLSL Code
  • Moon3D




  • GLSL Hacker Articles

    > Compute shaders on Radeon
    > Distance functions in GLSL
    > GLSL Interpolation Qualifiers
    > Tessellation Spacing Modes
    > Normal Visualizer with GS
    > 3D Surface Plots
    > Normal Mapping
    > Circle and Disc in GLSL
    > PhysX 3 Flag Demo
    > GLSL Hacker on Raspberry Pi
    GLSL Hacker

    Reference Guide
    Host-API Lua / Python



    Back to Homepage
    Back to Developer's 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: 19

    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.

    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)

    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

    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_position

    Description
    Gets the camera position.

    Languages: Lua - Python

    Parameters
  • camera [INTEGER]: camera identifier.

    Return Values
  • camera [x, y, z]: camera identifier

    Code sample :

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


    gh_camera.get_view

    Description
    Gets the camera direction (z axis).

    Languages: Lua - Python

    Parameters
  • camera [INTEGER]: camera identifier.

    Return Values
  • camera [x, y, z]: camera identifier

    Code sample :

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


    gh_camera.set_lookat

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

    Languages: Lua - Python

    Alias: setlookat

    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

    Code sample :

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


    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.

    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.

    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.

    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.

    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.

    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.

    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.

    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.

    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.

    Code sample :

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





  • (C)2012-2014 Geeks3D