4 Copyright 2008-2012 Michel Pollet <buserror@gmail.com>
6 This file is part of libc3.
8 libc3 is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 libc3 is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with libc3. If not, see <http://www.gnu.org/licenses/>.
24 #include "c3context.h"
25 #include "c3driver_geometry.h"
31 c3vertex_p vertices, // points A,B pairs
33 c3vertex_array_p v, // triangles
38 c3tex_array_clear(tex);
39 c3vertex_array_clear(v);
40 for (int l = 0; l < count; l += 2) {
41 c3vec3 a = c3mat4_mulv3(m, vertices[l]);
42 c3vec3 b = c3mat4_mulv3(m, vertices[l+1]);
44 c3vec3 e = c3vec3_mulf(c3vec3_normalize(c3vec3_sub(b, a)), lineWidth);
46 c3vec3 N = c3vec3f(-e.y, e.x, 0);
47 c3vec3 S = c3vec3_minus(N);
48 c3vec3 NE = c3vec3_add(N, e);
49 c3vec3 NW = c3vec3_sub(N, e);
50 c3vec3 SW = c3vec3_minus(NE);
51 c3vec3 SE = c3vec3_minus(NW);
53 c3vertex_array_add(v, c3vec3_add(a, SW));
54 c3vertex_array_add(v, c3vec3_add(a, NW));
55 c3vertex_array_add(v, c3vec3_add(a, S));
56 c3vertex_array_add(v, c3vec3_add(a, N));
57 c3vertex_array_add(v, c3vec3_add(b, S));
58 c3vertex_array_add(v, c3vec3_add(b, N));
59 c3vertex_array_add(v, c3vec3_add(b, SE));
60 c3vertex_array_add(v, c3vec3_add(b, NE));
65 c3vertex_array_add(v, c3vec3_add(a, SW));
66 c3vertex_array_add(v, c3vec3_add(a, S));
67 c3vertex_array_add(v, c3vec3_add(a, NW));
68 c3tex_array_add(tex, c3vec2f(ts * 0 , ts * 0 ));
69 c3tex_array_add(tex, c3vec2f(ts * 0.5, ts * 0 ));
70 c3tex_array_add(tex, c3vec2f(ts * 0 , ts * 1 ));
72 c3vertex_array_add(v, c3vec3_add(a, S));
73 c3vertex_array_add(v, c3vec3_add(a, N));
74 c3vertex_array_add(v, c3vec3_add(a, NW));
75 c3tex_array_add(tex, c3vec2f(ts * 0.5, ts * 0 ));
76 c3tex_array_add(tex, c3vec2f(ts * 0.5, ts * 1 ));
77 c3tex_array_add(tex, c3vec2f(ts * 0 , ts * 1 ));
79 c3vertex_array_add(v, c3vec3_add(a, N));
80 c3vertex_array_add(v, c3vec3_add(b, S));
81 c3vertex_array_add(v, c3vec3_add(b, N));
82 c3tex_array_add(tex, c3vec2f(ts * 0.5, ts * 1 ));
83 c3tex_array_add(tex, c3vec2f(ts * 0.5, ts * 0 ));
84 c3tex_array_add(tex, c3vec2f(ts * 0.5, ts * 1 ));
86 c3vertex_array_add(v, c3vec3_add(a, N));
87 c3vertex_array_add(v, c3vec3_add(a, S));
88 c3vertex_array_add(v, c3vec3_add(b, S));
89 c3tex_array_add(tex, c3vec2f(ts * 0.5, ts * 1 ));
90 c3tex_array_add(tex, c3vec2f(ts * 0.5, ts * 0 ));
91 c3tex_array_add(tex, c3vec2f(ts * 0.5, ts * 0 ));
93 c3vertex_array_add(v, c3vec3_add(b, N));
94 c3vertex_array_add(v, c3vec3_add(b, S));
95 c3vertex_array_add(v, c3vec3_add(b, SE));
96 c3tex_array_add(tex, c3vec2f(ts * 0.5, ts * 1 ));
97 c3tex_array_add(tex, c3vec2f(ts * 0.5, ts * 0 ));
98 c3tex_array_add(tex, c3vec2f(ts * 1 , ts * 0 ));
100 c3vertex_array_add(v, c3vec3_add(b, N));
101 c3vertex_array_add(v, c3vec3_add(b, SE));
102 c3vertex_array_add(v, c3vec3_add(b, NE));
103 c3tex_array_add(tex, c3vec2f(ts * 0.5, ts * 1 ));
104 c3tex_array_add(tex, c3vec2f(ts * 1 , ts * 0 ));
105 c3tex_array_add(tex, c3vec2f(ts * 1 , ts * 1 ));
113 c3vertex_p vertices, // points A,B pairs
117 c3mat4 i = identity3D();
118 c3lines_prepare(vertices, count, &g->vertice, &g->textures, lineWidth, &i);
119 g->type.type = C3_LINES_TYPE;
126 const struct c3driver_geometry_t *d,
129 const c3driver_geometry_t c3lines_driver = {
130 .project = _c3lines_project,
133 const c3driver_geometry_t c3geometry_driver;
135 c3geometry_set_lines(
138 static const c3driver_geometry_t * list[] = {
139 &c3lines_driver, &c3geometry_driver, NULL,