4 Copyright 2008-2012 Michel Pollet <buserror@gmail.com>
6 This file is part of simavr.
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.
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.
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/>.
23 #ifndef __C3OBJECT_H___
24 #define __C3OBJECT_H___
27 #include "c3/c3transform.h"
28 #include "c3/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 visible : 1 /* TODO: Implement visible */;
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 c3transform_array_t transform;
54 c3object_array_t objects; //! child object list
55 c3geometry_array_t geometry; //! Object geometri(es)
56 } c3object_t, *c3object_p;
58 //! Allocates and initialize an emty object, attaches it to parent 'o'
61 c3object_p o /* = NULL */);
62 //! Disposes of everything under this object
66 //! Clears every sub-object, geometry, and transform, but do not dispose of o
70 //! Initializes 'o' as a new object, attaches it to parent (optional)
74 c3object_p parent /* = NULL */);
75 //! sets the dirty bit for 'o' and related tree
77 * When dirty is 1, sets the dirty bit of this object and all the parent
78 * objects up to the root object.
79 * When dirty is 0, clear the dirty bit of this object, and all the
86 //! Adds a new geometry g to object o
88 c3object_add_geometry(
91 //! Adds a new sub-object sub to object o
96 //! Adds a new transform matrix, initialized as identity
98 c3object_add_transform(
100 //! Iterates all the sub-objects and collects all the geometries
102 * This call iterates the sub-objects and collects all their 'projected'
103 * geometry, and add them to the array
106 c3object_get_geometry(
108 c3geometry_array_p array );
109 //! Project object 'o' using it's own transformations, relative to matrix 'm'
111 * Multiply this objects transformation(s) to matrix 'm' and calls
112 * reprojects the geometries using that matrix as an anchor. also call
113 * recursively to sub-objects to follow the projection down.
120 IMPLEMENT_C_ARRAY(c3object_array);
122 #endif /* __C3OBJECT_H___ */