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/>.
23 #ifndef __C3OBJECT_H___
24 #define __C3OBJECT_H___
27 #include "c3transform.h"
28 #include "c3geometry.h"
32 DECLARE_C_ARRAY(struct c3object_t*, c3object_array, 4);
34 //! c3object is a container for child object, and geometry
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.
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)
46 typedef struct c3object_t {
47 str_p name; //! optional name
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
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;
60 //! Allocates and initialize an emty object, attaches it to parent 'o'
63 c3object_p o /* = NULL */);
64 //! Disposes of everything under this object
68 //! Clears every sub-object, geometry, and transform, but do not dispose of o
72 //! Initializes 'o' as a new object, attaches it to parent (optional)
76 c3object_p parent /* = NULL */);
77 //! sets the dirty bit for 'o' and related tree
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
88 //! Adds a new geometry g to object o
90 c3object_add_geometry(
93 //! Adds a new sub-object sub to object o
98 //! Adds a new transform matrix, initialized as identity
100 c3object_add_transform(
102 //! Iterates all the sub-objects and collects all the geometries
104 * This call iterates the sub-objects and collects all their 'projected'
105 * geometry, and add them to the array
108 c3object_get_geometry(
110 c3geometry_array_p array );
111 //! Project object 'o' using it's own transformations, relative to matrix 'm'
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.
122 IMPLEMENT_C_ARRAY(c3object_array);
124 #endif /* __C3OBJECT_H___ */