File: stealth.glsl

package info (click to toggle)
python-vispy 0.14.3-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 8,840 kB
  • sloc: python: 59,436; javascript: 6,800; makefile: 69; sh: 6
file content (46 lines) | stat: -rw-r--r-- 1,254 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/**
 * Copyright (c) Vispy Development Team
 * Distributed under the (new) BSD License. See LICENSE.txt for more info.
 *
 * This file contains the code for drawing "stealth" type arrow heads.
 */

#include "arrowheads/util.glsl"


/**
 * Computes the signed distance to an stealth arrow
 *
 * Parameters:
 * -----------
 *
 * texcoord 
 *     Point to compute distance to
 * size
 *     Size of the arrow head in pixels
 * linewidth
 *     Width of the line
 * antialias
 *     Anti alias width
 *
 * Return:
 * -------
 * Signed distance to the arrow
 */
float arrow_stealth(vec2 texcoord, float size, 
                    float linewidth, float antialias)
{
    vec2 start = -vec2(size/2.0, 0.0);
    vec2 end   = +vec2(size/2.0, 0.0);
    float height = 0.5;

    // Head : 4 lines
    float d1 = line_distance(texcoord, start + size*vec2(0.0, +height), end);
    float d2 = line_distance(texcoord, start + size*vec2(0.0, +height),
                             start + size*vec2(0.3, 0.0));
    float d3 = line_distance(texcoord, start + size*vec2(0.0, -height), end);
    float d4 = line_distance(texcoord, start + size*vec2(0.0, -height),
                             start + size*vec2(0.25, 0.0));

    return max( max(-d1, d3), - max(-d2,d4));
}