-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathNode.cpp
More file actions
106 lines (82 loc) · 2.67 KB
/
Node.cpp
File metadata and controls
106 lines (82 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// Copyright 1996-2024 Cyberbotics Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "Node.hpp"
#include "Transform.hpp"
#include <wren/node.h>
namespace wren {
void Node::deleteNode(Node *node) {
if (!node)
return;
if (node->mParent)
node->mParent->detachChild(node);
delete node;
}
const primitive::Aabb &Node::aabb() {
if (mIsAabbDirty) {
recomputeAabb();
mIsAabbDirty = false;
}
return mAabb;
}
const primitive::Sphere &Node::boundingSphere() const {
if (mIsBoundingSphereDirty) {
recomputeBoundingSphere();
mIsBoundingSphereDirty = false;
}
return mBoundingSphere;
}
void Node::setBoundingVolumeDirty() const {
if (mIsAabbDirty && mIsBoundingSphereDirty)
return;
mIsAabbDirty = true;
mIsBoundingSphereDirty = true;
if (mParent)
mParent->setBoundingVolumeDirty();
}
Node::Node() : mIsVisible(true), mIsAabbDirty(true), mIsBoundingSphereDirty(true), mParent(NULL) {
}
Node::Node(Node *source) :
mIsVisible(source->mIsVisible),
mIsAabbDirty(source->mIsAabbDirty),
mIsBoundingSphereDirty(source->mIsBoundingSphereDirty),
mAabb(source->mAabb),
mBoundingSphere(source->mBoundingSphere),
mParent(source->mParent) {
}
void Node::recomputeAabb() const {
mAabb = primitive::Aabb(glm::vec3(0.0f), glm::vec3(0.0f));
if (mParent) {
mAabb.mBounds[0] += mParent->position();
mAabb.mBounds[1] += mParent->position();
}
}
void Node::recomputeBoundingSphere() const {
mBoundingSphere = primitive::Sphere(glm::vec3(0.0f), 0.0f);
if (mParent)
mBoundingSphere.mCenter += mParent->position();
}
} // namespace wren
// C interface implementation
void wr_node_delete(WrNode *node) {
wren::Node::deleteNode(reinterpret_cast<wren::Node *>(node));
}
WrTransform *wr_node_get_parent(WrNode *node) {
return reinterpret_cast<WrTransform *>(reinterpret_cast<wren::Node *>(node)->parent());
}
void wr_node_set_visible(WrNode *node, bool is_visible) {
reinterpret_cast<wren::Node *>(node)->setVisible(is_visible);
}
bool wr_node_is_visible(WrNode *node) {
return reinterpret_cast<wren::Node *>(node)->isVisible();
}