reprap: Delete mongoose
[simavr] / examples / board_reprap / src / c3 / c3context.c
1 /*
2         c3context.c
3
4         Copyright 2008-2012 Michel Pollet <buserror@gmail.com>
5
6         This file is part of simavr.
7
8         simavr 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.
12
13         simavr 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.
17
18         You should have received a copy of the GNU General Public License
19         along with simavr.  If not, see <http://www.gnu.org/licenses/>.
20  */
21
22
23 #include "c3/c3context.h"
24 #include "c3/c3object.h"
25 #include "c3/c3driver_context.h"
26
27 c3context_p
28 c3context_new(
29                 int w,
30                 int h)
31 {
32         c3context_p res = malloc(sizeof(*res));
33         return c3context_init(res, w, h);
34 }
35
36 c3context_p
37 c3context_init(
38                 c3context_p c,
39                 int w,
40                 int h)
41 {
42         memset(c, 0, sizeof(*c));
43         c->size.x = w;
44         c->size.y = h;
45         c->root = c3object_new(NULL);
46         c->root->context = c;
47         return c;
48 }
49
50 void
51 c3context_dispose(
52                 c3context_p c)
53 {
54         c3object_dispose(c->root);
55         c3geometry_array_free(&c->projected);
56         free(c);
57 }
58
59 void
60 c3context_project(
61                 c3context_p c)
62 {
63         if (!c->root || !c->root->dirty)
64                 return;
65
66         c3mat4 m = identity3D();
67         c3object_project(c->root, &m);
68         c3geometry_array_clear(&c->projected);
69         c3object_get_geometry(c->root, &c->projected);
70 }
71
72 void
73 c3context_draw(
74                 c3context_p c)
75 {
76         c3context_project(c);
77         for (int gi = 0; gi < c->projected.count; gi++) {
78                 c3geometry_p g = c->projected.e[gi];
79                 c3geometry_draw(g);
80         }
81 }