Panda3D
 All Classes Functions Variables Enumerations
baseIntegrator.cxx
1 // Filename: baseIntegrator.cxx
2 // Created by: charles (11Aug00)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "baseIntegrator.h"
16 #include "physicalNode.h"
17 #include "forceNode.h"
18 #include "nodePath.h"
19 
20 ////////////////////////////////////////////////////////////////////
21 // Function : BaseIntegrator
22 // Access : protected
23 // Description : constructor
24 ////////////////////////////////////////////////////////////////////
25 BaseIntegrator::
26 BaseIntegrator() {
27 }
28 
29 ////////////////////////////////////////////////////////////////////
30 // Function : ~BaseIntegrator
31 // Access : public, virtual
32 // Description : destructor
33 ////////////////////////////////////////////////////////////////////
36 }
37 
38 ////////////////////////////////////////////////////////////////////
39 // Function : precompute_linear_matrices
40 // Access : protected
41 // Description : effectively caches the xform matrices between
42 // the physical's node and every force acting on it
43 // so that each PhysicsObject in the set held by the
44 // Physical doesn't have to wrt.
45 ////////////////////////////////////////////////////////////////////
46 void BaseIntegrator::
47 precompute_linear_matrices(Physical *physical,
48  const LinearForceVector &forces) {
49  nassertv(physical);
50  // make sure the physical's in the scene graph, somewhere.
51  PhysicalNode *physical_node = physical->get_physical_node();
52  nassertv(physical_node);
53 
54  // by global forces, we mean forces not contained in the physical
55  int global_force_vec_size = forces.size();
56 
57  // by local forces, we mean members of the physical's force set.
58  int local_force_vec_size = physical->get_linear_forces().size();
59 
60  ForceNode *force_node;
61 
62  // prepare the vector
63  _precomputed_linear_matrices.clear();
64  _precomputed_linear_matrices.reserve(
65  global_force_vec_size + local_force_vec_size);
66 
67  NodePath physical_np(physical->get_physical_node_path());
68  NodePath parent_physical_np = physical_np.get_parent();
69 
70  // tally the global xforms
71  LinearForceVector::const_iterator fi;
72  for (fi = forces.begin(); fi != forces.end(); ++fi) {
73  //LinearForce *cur_force = *fi;
74  force_node = (*fi)->get_force_node();
75  nassertv(force_node != (ForceNode *) NULL);
76 
77  NodePath force_np = (*fi)->get_force_node_path();
78  _precomputed_linear_matrices.push_back(
79  force_np.get_transform(parent_physical_np)->get_mat());
80  }
81 
82  // tally the local xforms
83  const LinearForceVector &force_vector = physical->get_linear_forces();
84  for (fi = force_vector.begin(); fi != force_vector.end(); ++fi) {
85  force_node = (*fi)->get_force_node();
86  nassertv(force_node != (ForceNode *) NULL);
87 
88  NodePath force_np = (*fi)->get_force_node_path();
89  _precomputed_linear_matrices.push_back(
90  force_np.get_transform(parent_physical_np)->get_mat());
91  }
92 }
93 
94 ////////////////////////////////////////////////////////////////////
95 // Function : precompute_angular_matrices
96 // Access : protected
97 // Description : effectively caches the xform matrices between
98 // the physical's node and every force acting on it
99 // so that each PhysicsObject in the set held by the
100 // Physical doesn't have to wrt.
101 ////////////////////////////////////////////////////////////////////
102 void BaseIntegrator::
103 precompute_angular_matrices(Physical *physical,
104  const AngularForceVector &forces) {
105  nassertv(physical);
106  // make sure the physical's in the scene graph, somewhere.
107  PhysicalNode *physical_node = physical->get_physical_node();
108  nassertv(physical_node != NULL);
109 
110  // by global forces, we mean forces not contained in the physical
111  int global_force_vec_size = forces.size();
112 
113  // by local forces, we mean members of the physical's force set.
114  int local_force_vec_size = physical->get_angular_forces().size();
115 
116  ForceNode *force_node;
117 
118  // prepare the vector
119  _precomputed_angular_matrices.clear();
120  _precomputed_angular_matrices.reserve(
121  global_force_vec_size + local_force_vec_size);
122 
123  NodePath physical_np(physical->get_physical_node_path());
124  NodePath parent_physical_np = physical_np.get_parent();
125 
126  // tally the global xforms
127  AngularForceVector::const_iterator fi;
128  for (fi = forces.begin(); fi != forces.end(); ++fi) {
129  force_node = (*fi)->get_force_node();
130  nassertv(force_node != (ForceNode *) NULL);
131 
132  NodePath force_np = (*fi)->get_force_node_path();
133  _precomputed_angular_matrices.push_back(
134  force_np.get_transform(parent_physical_np)->get_mat());
135  }
136 
137  // tally the local xforms
138  const AngularForceVector &force_vector = physical->get_angular_forces();
139  for (fi = force_vector.begin(); fi != force_vector.end(); ++fi) {
140  force_node = (*fi)->get_force_node();
141  nassertv(force_node != (ForceNode *) NULL);
142 
143  NodePath force_np = (*fi)->get_force_node_path();
144  _precomputed_angular_matrices.push_back(
145  force_np.get_transform(parent_physical_np)->get_mat());
146  }
147 }
148 
149 ////////////////////////////////////////////////////////////////////
150 // Function : output
151 // Access : Public
152 // Description : Write a string representation of this instance to
153 // <out>.
154 ////////////////////////////////////////////////////////////////////
155 void BaseIntegrator::
156 output(ostream &out) const {
157  #ifndef NDEBUG //[
158  out<<"BaseIntegrator (id "<<this<<")";
159  #endif //] NDEBUG
160 }
161 
162 ////////////////////////////////////////////////////////////////////
163 // Function : write_precomputed_linear_matrices
164 // Access : Public
165 // Description : Write a string representation of this instance to
166 // <out>.
167 ////////////////////////////////////////////////////////////////////
168 void BaseIntegrator::
169 write_precomputed_linear_matrices(ostream &out, unsigned int indent) const {
170  #ifndef NDEBUG //[
171  out.width(indent);
172  out<<""<<"_precomputed_linear_matrices\n";
173  for (MatrixVector::const_iterator i=_precomputed_linear_matrices.begin();
174  i != _precomputed_linear_matrices.end();
175  ++i) {
176  out.width(indent+2); out<<""; (*i).output(out); out<<"\n";
177  }
178  #endif //] NDEBUG
179 }
180 
181 ////////////////////////////////////////////////////////////////////
182 // Function : write_precomputed_angular_matrices
183 // Access : Public
184 // Description : Write a string representation of this instance to
185 // <out>.
186 ////////////////////////////////////////////////////////////////////
187 void BaseIntegrator::
188 write_precomputed_angular_matrices(ostream &out, unsigned int indent) const {
189  #ifndef NDEBUG //[
190  out.width(indent);
191  out<<""<<"_precomputed_angular_matrices\n";
192  for (MatrixVector::const_iterator i=_precomputed_angular_matrices.begin();
193  i != _precomputed_angular_matrices.end();
194  ++i) {
195  out.width(indent+2); out<<""; (*i).output(out); out<<"\n";
196  }
197  #endif //] NDEBUG
198 }
199 
200 ////////////////////////////////////////////////////////////////////
201 // Function : write
202 // Access : Public
203 // Description : Write a string representation of this instance to
204 // <out>.
205 ////////////////////////////////////////////////////////////////////
206 void BaseIntegrator::
207 write(ostream &out, unsigned int indent) const {
208  #ifndef NDEBUG //[
209  out.width(indent); out<<""; out<<"BaseIntegrator:\n";
210  write_precomputed_linear_matrices(out, indent+2);
211  write_precomputed_angular_matrices(out, indent+2);
212  #endif //] NDEBUG
213 }
NodePath get_parent(Thread *current_thread=Thread::get_current_thread()) const
Returns the NodePath to the parent of the referenced node: that is, this NodePath, shortened by one node.
Definition: nodePath.I:460
A force that lives in the scene graph and is therefore subject to local coordinate systems...
Definition: forceNode.h:30
const TransformState * get_transform(Thread *current_thread=Thread::get_current_thread()) const
Returns the complete transform object set on this node.
Definition: nodePath.cxx:925
Graph node that encapsulated a series of physical objects.
Definition: physicalNode.h:31
virtual void output(ostream &out) const
Write a string representation of this instance to &lt;out&gt;.
virtual void write_precomputed_angular_matrices(ostream &out, unsigned int indent=0) const
Write a string representation of this instance to &lt;out&gt;.
virtual void write_precomputed_linear_matrices(ostream &out, unsigned int indent=0) const
Write a string representation of this instance to &lt;out&gt;.
Defines a set of physically modeled attributes.
Definition: physical.h:40
virtual ~BaseIntegrator()
destructor
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:165
virtual void write(ostream &out, unsigned int indent=0) const
Write a string representation of this instance to &lt;out&gt;.