Panda3D
actorNode.cxx
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file actorNode.cxx
10  * @author charles
11  * @date 2000-08-07
12  */
13 
14 #include "actorNode.h"
15 #include "config_physics.h"
16 #include "physicsObject.h"
17 
18 #include "transformState.h"
19 
20 TypeHandle ActorNode::_type_handle;
21 
22 /**
23  * Constructor
24  */
26 ActorNode(const std::string &name) :
27  PhysicalNode(name) {
28  _contact_vector = LVector3::zero();
29  add_physical(new Physical(1, true));
30  _mass_center = get_physical(0)->get_phys_body();
31  _mass_center->set_active(true);
32  #ifndef NDEBUG
33  _mass_center->set_name(name);
34  #endif
35  _ok_to_callback = true;
36  _transform_limit = 0.0;
37 }
38 
39 /**
40  * Copy Constructor.
41  */
43 ActorNode(const ActorNode &copy) :
44  PhysicalNode(copy) {
45  _contact_vector = LVector3::zero();
46  _ok_to_callback = true;
47  _mass_center = get_physical(0)->get_phys_body();
48  _transform_limit = copy._transform_limit;
49 }
50 
51 /**
52  * destructor
53  */
56 }
57 
58 /**
59  * this sets the transform generated by the contained Physical, moving the
60  * node and subsequent geometry. i.e. copy from PhysicsObject to PandaNode
61  */
62 void ActorNode::
64  LMatrix4 lcs = _mass_center->get_lcs();
65 
66  // lock the callback so that this doesn't call transform_changed.
67  _ok_to_callback = false;
68  set_transform(TransformState::make_mat(lcs));
69  _ok_to_callback = true;
70 }
71 
72 /**
73  * this tests the transform to make sure it's within the specified limits.
74  * It's done so we can assert to see when an invalid transform is being
75  * applied.
76  */
77 void ActorNode::
78 test_transform(const TransformState *ts) const {
79  LPoint3 pos(ts->get_pos());
80  nassertv(pos[0] < _transform_limit);
81  nassertv(pos[0] > -_transform_limit);
82  nassertv(pos[1] < _transform_limit);
83  nassertv(pos[1] > -_transform_limit);
84  nassertv(pos[2] < _transform_limit);
85  nassertv(pos[2] > -_transform_limit);
86 }
87 
88 /**
89  * node hook. This function handles outside (non-physics) actions on the
90  * actor and updates the internal representation of the node. i.e. copy from
91  * PandaNode to PhysicsObject
92  */
93 void ActorNode::
94 transform_changed() {
95  PandaNode::transform_changed();
96 
97  // this callback could be triggered by update_transform, BAD.
98  if (!_ok_to_callback) {
99  return;
100  }
101 
102  // get the transform
103  CPT(TransformState) transform = get_transform();
104 
105  if (_transform_limit > 0.0) {
106  test_transform(transform);
107  }
108 
109  // extract the orientation
110  if (_mass_center->get_oriented() == true) {
111  _mass_center->set_orientation(transform->get_quat());
112  }
113 
114  // apply
115  _mass_center->set_position(transform->get_pos());
116 }
117 
118 
119 /**
120  * Write a string representation of this instance to <out>.
121  */
122 void ActorNode::
123 write(std::ostream &out, int indent) const {
124  #ifndef NDEBUG //[
125  out.width(indent); out<<""; out<<"ActorNode:\n";
126  out.width(indent+2); out<<""; out<<"_ok_to_callback "<<_ok_to_callback<<"\n";
127  out.width(indent+2); out<<""; out<<"_mass_center\n";
128  _mass_center->write(out, indent+4);
129  PhysicalNode::write(out, indent+2);
130  #endif //] NDEBUG
131 }
Indicates a coordinate-system transform on vertices.
void set_position(const LPoint3 &pos)
Vector position assignment.
Definition: physicsObject.I:27
virtual void write(std::ostream &out, int indent=0) const
Write a string representation of this instance to <out>.
Definition: actorNode.cxx:123
void update_transform()
this sets the transform generated by the contained Physical, moving the node and subsequent geometry.
Definition: actorNode.cxx:63
get_quat
Returns the rotation component of the transform as a quaternion.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual void write(std::ostream &out, int indent=0) const
Write a string representation of this instance to <out>.
bool get_oriented() const
See set_oriented().
set_transform
Sets the transform that will be applied to this node and below.
Definition: pandaNode.h:183
Graph node that encapsulated a series of physical objects.
Definition: physicalNode.h:28
virtual ~ActorNode()
destructor
Definition: actorNode.cxx:55
void set_active(bool flag)
Process Flag assignment.
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
Definition: indent.cxx:20
get_pos
Returns the pos component of the transform.
Defines a set of physically modeled attributes.
Definition: physical.h:37
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual void write(std::ostream &out, int indent=0) const
Write a string representation of this instance to <out>.
ActorNode(const std::string &name="")
Constructor.
Definition: actorNode.cxx:26
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
Like a physical node, but with a little more.
Definition: actorNode.h:26
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual LMatrix4 get_lcs() const
returns a transform matrix to this object's local coordinate system.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.