-
Notifications
You must be signed in to change notification settings - Fork 110
/
Copy pathAttachNode.cpp
65 lines (55 loc) · 1.25 KB
/
AttachNode.cpp
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
#include "AttachNode.h"
#include "C3DNode.h"
#include "C3DLayer.h"
#include "C3DScene.h"
namespace cocos3d
{
AttachNode::AttachNode( C3DNode* pNode, C3DNode* pOwner )
{
_node = pNode;
_owner = pOwner;
}
AttachNode::~AttachNode()
{
_node = NULL;
_owner = NULL;
}
void AttachNode::attach( C3DNode* pAttachment )
{
pAttachment->scale(1.0f/_owner->getScaleX(),1.0f/_owner->getScaleY(),1.0f/_owner->getScaleZ());
_node->addChild(pAttachment);
_owner->get3DScene()->removeChild(pAttachment);
_attachments.push_back(pAttachment);
}
bool AttachNode::detach( C3DNode* pAttachment )
{
std::vector<C3DNode*>::iterator nit;
for (nit = _attachments.begin(); nit != _attachments.end(); nit++)
{
if ( *nit == pAttachment )
{
pAttachment->scale(_owner->getScaleX(),_owner->getScaleY(),_owner->getScaleZ());
_owner->get3DScene()->addChild(pAttachment);
_attachments.erase(nit);
return true;
}
}
return false;
}
void AttachNode::update(long elapsedTime)
{
std::vector<C3DNode*>::iterator nit;
for (nit = _attachments.begin(); nit != _attachments.end(); nit++)
{
(*nit)->update(elapsedTime);
}
}
void AttachNode::draw()
{
std::vector<C3DNode*>::iterator nit;
for (nit = _attachments.begin(); nit != _attachments.end(); nit++)
{
(*nit)->draw();
}
}
}