forked from panda3d/panda3d
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathactorNode.cxx
More file actions
131 lines (114 loc) · 3.18 KB
/
actorNode.cxx
File metadata and controls
131 lines (114 loc) · 3.18 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/**
* PANDA 3D SOFTWARE
* Copyright (c) Carnegie Mellon University. All rights reserved.
*
* All use of this software is subject to the terms of the revised BSD
* license. You should have received a copy of this license along
* with this source code in a file named "LICENSE."
*
* @file actorNode.cxx
* @author charles
* @date 2000-08-07
*/
#include "actorNode.h"
#include "config_physics.h"
#include "physicsObject.h"
#include "transformState.h"
TypeHandle ActorNode::_type_handle;
/**
* Constructor
*/
ActorNode::
ActorNode(const std::string &name) :
PhysicalNode(name) {
_contact_vector = LVector3::zero();
add_physical(new Physical(1, true));
_mass_center = get_physical(0)->get_phys_body();
_mass_center->set_active(true);
#ifndef NDEBUG
_mass_center->set_name(name);
#endif
_ok_to_callback = true;
_transform_limit = 0.0;
}
/**
* Copy Constructor.
*/
ActorNode::
ActorNode(const ActorNode ©) :
PhysicalNode(copy) {
_contact_vector = LVector3::zero();
_ok_to_callback = true;
_mass_center = get_physical(0)->get_phys_body();
_transform_limit = copy._transform_limit;
}
/**
* destructor
*/
ActorNode::
~ActorNode() {
}
/**
* this sets the transform generated by the contained Physical, moving the
* node and subsequent geometry. i.e. copy from PhysicsObject to PandaNode
*/
void ActorNode::
update_transform() {
LMatrix4 lcs = _mass_center->get_lcs();
// lock the callback so that this doesn't call transform_changed.
_ok_to_callback = false;
set_transform(TransformState::make_mat(lcs));
_ok_to_callback = true;
}
/**
* this tests the transform to make sure it's within the specified limits.
* It's done so we can assert to see when an invalid transform is being
* applied.
*/
void ActorNode::
test_transform(const TransformState *ts) const {
LPoint3 pos(ts->get_pos());
nassertv(pos[0] < _transform_limit);
nassertv(pos[0] > -_transform_limit);
nassertv(pos[1] < _transform_limit);
nassertv(pos[1] > -_transform_limit);
nassertv(pos[2] < _transform_limit);
nassertv(pos[2] > -_transform_limit);
}
/**
* node hook. This function handles outside (non-physics) actions on the
* actor and updates the internal representation of the node. i.e. copy from
* PandaNode to PhysicsObject
*/
void ActorNode::
transform_changed() {
PandaNode::transform_changed();
// this callback could be triggered by update_transform, BAD.
if (!_ok_to_callback) {
return;
}
// get the transform
CPT(TransformState) transform = get_transform();
if (_transform_limit > 0.0) {
test_transform(transform);
}
// extract the orientation
if (_mass_center->get_oriented() == true) {
_mass_center->set_orientation(transform->get_quat());
}
// apply
_mass_center->set_position(transform->get_pos());
}
/**
* Write a string representation of this instance to <out>.
*/
void ActorNode::
write(std::ostream &out, int indent) const {
#ifndef NDEBUG //[
out.width(indent); out<<""; out<<"ActorNode:\n";
out.width(indent+2); out<<""; out<<"_ok_to_callback "<<_ok_to_callback<<"\n";
out.width(indent+2); out<<""; out<<"_mass_center\n";
_mass_center->write(out, indent+4);
PhysicalNode::write(out, indent+2);
#endif //] NDEBUG
}