5. Some hasty vector functions

Some quick and dirty vector function operations have been created. This makes some of the code cleaner to look at, and also to better match the original shader code. These will only be used internally.

5.1. vec2 struct

<<structs>>=
typedef struct {
    float x, y;
} vec2;

5.2. mkvec2

mkvec2 creates and returns a new vector.

<<static_funcdefs>>=
static vec2 mkvec2(float x, float y);
<<funcs>>=
static vec2 mkvec2(float x, float y)
{
    vec2 v;
    v.x = x;
    v.y = y;
    return v;
}

5.3. dot

dot computes the dot product between two vectors.

<<static_funcdefs>>=
static float dot(vec2 a, vec2 b);
<<funcs>>=
static float dot(vec2 a, vec2 b)
{
    return a.x*b.x + a.y*b.y;
}

5.4. muls

muls computes a multiply operation between a vector and a scalar value.

<<static_funcdefs>>=
static vec2 muls(vec2 a, float s);
<<funcs>>=
static vec2 muls(vec2 a, float s)
{
    vec2 out;
    out.x = a.x * s;
    out.y = a.y * s;
    return out;
}

5.5. mul

mul computes a multiply operation between a two vectors.

<<static_funcdefs>>=
static vec2 mul(vec2 a, vec2 b);
<<funcs>>=
static vec2 mul(vec2 a, vec2 b)
{
    vec2 out;
    out.x = a.x * b.x;
    out.y = a.y * b.y;
    return out;
}

5.6. add

add adds two vectors together.

<<static_funcdefs>>=
static vec2 add(vec2 a, vec2 b);
<<funcs>>=
static vec2 add(vec2 a, vec2 b)
{
    vec2 out;

    out.x = a.x + b.x;
    out.y = a.y + b.y;

    return out;
}

5.7. adds

adds performs an addition operation between a vector and a scalar.

<<static_funcdefs>>=
static vec2 adds(vec2 a, float s);
<<funcs>>=
static vec2 adds(vec2 a, float s)
{
    vec2 out;

    out.x = a.x + s;
    out.y = a.y + s;

    return out;
}



prev | home | next