goat3d

view src/node.cc @ 75:76dea247f75c

in progress
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 08 May 2014 00:50:16 +0300
parents 99715321ad6d
children 9785847d52d4
line source
1 /*
2 goat3d - 3D scene, character, and animation file format library.
3 Copyright (C) 2013-2014 John Tsiombikas <nuclear@member.fsf.org>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #include <algorithm>
19 #include <string.h>
20 #include "node.h"
22 using namespace g3dimpl;
24 Node::Node()
25 {
26 obj = 0;
27 bbox_valid = false;
28 }
30 void Node::set_object(Object *obj)
31 {
32 this->obj = obj;
33 bbox_valid = false;
34 }
36 Object *Node::get_object()
37 {
38 bbox_valid = false;
39 return obj;
40 }
42 const Object *Node::get_object() const
43 {
44 return obj;
45 }
47 const AABox &Node::get_bounds() const
48 {
49 if(!bbox_valid) {
50 bbox = obj ? obj->get_bounds() : AABox();
52 for(int i=0; i<get_children_count(); i++) {
53 bbox = aabox_union(bbox, ((Node*)get_child(i))->get_bounds());
54 }
55 bbox_valid = true;
56 }
58 return bbox;
59 }
61 void g3dimpl::delete_node_tree(Node *n)
62 {
63 if(!n) return;
65 for(int i=0; i<n->get_children_count(); i++) {
66 delete_node_tree((Node*)n->get_child(i));
67 }
68 delete n;
69 }