next up previous contents
Next: The 3D Graphics Camera Up: Tina View Previous: Overlay Mode   Contents

The 2D Graphics Camera

The 2D camera determines the way 2D `world' points are mapped into pixel coordinates in the graphics window. In Tina 2D floating point positions are specified by a structure

typedef struct vec2
    Ts_id ts_id;                /* Tina structure identifier */
    float   el[2];
}       Vec2;

they can be created with calls to

Vec2 vec2(double x, double y)

of the form

Vec2 p;
p = vec2(0.0, 0.5).
(For further details on vector algebra see the Tinamath documentation).
The 2D projection function can be called explicitly as
Ipos tv_proj2(Tv *tv, Vec2 p)

Suppose we want to draw edge points from a 512 by 512 image, but the Tv is installed on a Tvtool which currently has size 256 by 256. The call

tv_camera2_image(tv, 512, 512)

computes a projection function which scales the entire image uniformly to fit centrally in the window. For example the centre point of the image can now be drawn with a call to

tv_point2(tv, vec2(256.0, 256.0));

rather than explicitly using

tv_point(tv, ipos(128, 128));

The available ways of setting up a 2D camera are described below:

void    tv_camera2_image(Tv * tv, int width, int height)
- scales the rectangle (0, 0) to (width, height) uniformly (that is equally in x and y) so as to fit centrally in the window. As its name suggests it is usually called in Tv's used to display images. The image y-axis is draw downwards.

void    tv_camera2_rect(Tv * tv, Vec2 v1, Vec2 v2)
- scales the rectangle with lower left at p1 and upper right at p2 in both x and y to fit exactly in the window. Note this draws the 2D source y-axis pointing upwards.

void    tv_camera2(Tv * tv, Vec2 centre, double radius, Vec2 down)
This uniformly scales the circle with given centre and radius to fit centrally in the window. There is also a 2D rotation to make the vector specified by down point vertically downwards in the window.

Note that once these functions are invoked any resizing of the Tvtool will automatically cause the Tv to adjust its projection function appropriately.

next up previous contents
Next: The 3D Graphics Camera Up: Tina View Previous: Overlay Mode   Contents
root 2017-09-25