struct hiro::draw::ProjectionParams

Overview

Projection, camera and viewport parameters. More…

#include <Scene.h>

struct ProjectionParams {
    // fields

    int32_t top;
    int32_t left;
    int32_t bottom;
    int32_t right;
    float fov_x;
    float fov_y;
    float near_distance;
    float far_distance;
    glm_ext::TransMat4 view;
    glm_ext::TransMat4 proj;
    float width;
    float height;
    float aspect;

    // methods

    glm::vec3 CastRay(const glm::vec2& clip_coords) const;
    glm::vec2 ScreenToClipCoords(float x, float y) const;
    geom::IRect GetViewport() const;
};

Detailed Documentation

Projection, camera and viewport parameters.

Fields

int32_t top

Viewport offset from the top window border. In pixels.

int32_t left

Viewport offset from the left window border. In pixels.

int32_t bottom

Viewport offset from the bottom window border. In pixels.

int32_t right

Viewport offset from the right window border. In pixels.

float fov_x

Horizontal view angle. In radians.

float fov_y

Vertical view angle, In radians.

float near_distance

Distance to near projection plane.

float far_distance

Distance to far projection plane.

glm_ext::TransMat4 view

Camera view matrix.

glm_ext::TransMat4 proj

Projection matrix.

float width

Horizontal pixel resolution of viewport.

float height

Vertical pixel resolution of viewport.

float aspect

Aspect ratio of a viewport (width/height);.

Methods

glm::vec3 CastRay(const glm::vec2& clip_coords) const

Computes the direction of a ray casted form camera at a given 2D coordinates.

clip_coords 2D coordinate in clip space used for ray generation. If you wish to convert screen coordinates to clip coordinates, see ScreenToClipCoords.

Returns:

Direction of a generated ray. A starting position of a ray is usually camera position.

glm::vec2 ScreenToClipCoords(float x, float y) const

Converts screen coordinates to clip coordinates.

Screen coordinates are in pixels and are generated for example by mouse events. Clip coordinates are in the range -1.0 and 1.0 range and relative to the viewport.

geom::IRect GetViewport() const

Returns viewport rectangle area.