reprap: Deleted example board
[simavr] / examples / shared / libc3 / src / c3object.h
1 /*
2         c3object.h
3
4         Copyright 2008-2012 Michel Pollet <buserror@gmail.com>
5
6         This file is part of libc3.
7
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.
12
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.
17
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/>.
20  */
21
22
23 #ifndef __C3OBJECT_H___
24 #define __C3OBJECT_H___
25
26 #include <stdbool.h>
27 #include "c3transform.h"
28 #include "c3geometry.h"
29
30 struct c3object_t;
31
32 DECLARE_C_ARRAY(struct c3object_t*, c3object_array, 4);
33
34 //! c3object is a container for child object, and geometry
35 /*!
36  * a c3object is a node in a c3object tree, it contains sub-objects and/or
37  * geometry. It also contains it's own list of transform matrices, so can
38  * be seen as a "anchor" that can be moved around and where you can
39  * attach other objects or geometry.
40  *
41  * An object has a notion of 'dirty bit' -- something that signals that
42  * something has changed and deserved reprojection. the dirty bit
43  * is propagated upward when 1 (up to the root object) and downward when 0
44  * (to allow clearing the bit on a subtree)
45  */
46 typedef struct c3object_t {
47         str_p                           name;   //! optional name
48         int                                     dirty : 1, 
49                                                 hidden : 8 /* hidden bit mask, related to c3context's views */;
50         struct c3context_t * context; //! context this object is attached to
51         struct c3object_t * parent;             //! Parent object
52         const struct c3driver_object_t ** driver;       //! Driver stack
53
54         c3mat4                          world;          // calculated world coordinates
55         c3transform_array_t     transform;
56         c3object_array_t        objects;        //! child object list
57         c3geometry_array_t      geometry;       //! Object geometri(es)
58 } c3object_t, *c3object_p;
59
60 //! Allocates and initialize an emty object, attaches it to parent 'o'
61 c3object_p
62 c3object_new(
63                 c3object_p o /* = NULL */);
64 //! Disposes of everything under this object
65 void
66 c3object_dispose(
67                 c3object_p o);
68 //! Clears every sub-object, geometry, and transform, but do not dispose of o
69 void
70 c3object_clear(
71                 c3object_p o);
72 //! Initializes 'o' as a new object, attaches it to parent (optional)
73 c3object_p
74 c3object_init(
75                 c3object_p o,
76                 c3object_p parent /* = NULL */);
77 //! sets the dirty bit for 'o' and related tree
78 /*!
79  * When dirty is 1, sets the dirty bit of this object and all the parent
80  * objects up to the root object.
81  * When dirty is 0, clear the dirty bit of this object, and all the
82  * sub objects.
83  */
84 void
85 c3object_set_dirty(
86                 c3object_p o,
87                 bool dirty);
88 //! Adds a new geometry g to object o
89 void
90 c3object_add_geometry(
91                 c3object_p o,
92                 c3geometry_p g);
93 //! Adds a new sub-object sub to object o
94 void
95 c3object_add_object(
96                 c3object_p o,
97                 c3object_p sub);
98 //! Adds a new transform matrix, initialized as identity
99 c3transform_p
100 c3object_add_transform(
101                 c3object_p o );
102 //! Iterates all the sub-objects and collects all the geometries
103 /*!
104  * This call iterates the sub-objects and collects all their 'projected'
105  * geometry, and add them to the array
106  */
107 void
108 c3object_get_geometry(
109                 c3object_p o,
110                 c3geometry_array_p array );
111 //! Project object 'o' using it's own transformations, relative to matrix 'm'
112 /*!
113  * Multiply this objects transformation(s) to matrix 'm' and calls
114  * reprojects the geometries using that matrix as an anchor. also call
115  * recursively to sub-objects to follow the projection down.
116  */
117 void
118 c3object_project(
119                 c3object_p o,
120                 const c3mat4p m);
121
122 IMPLEMENT_C_ARRAY(c3object_array);
123
124 #endif /* __C3OBJECT_H___ */