Panda3D

Loading...
Searching...
No Matches
baseIntegrator.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 baseIntegrator.cxx
10 * @author charles
11 * @date 2000-08-11
12 */
13
14#include "baseIntegrator.h"
15#include "physicalNode.h"
16#include "forceNode.h"
17#include "nodePath.h"
18
19 using std::ostream;
20
21/**
22 * constructor
23 */
24BaseIntegrator::
25BaseIntegrator() {
26}
27
28/**
29 * destructor
30 */
31 BaseIntegrator::
32~BaseIntegrator() {
33}
34
35/**
36 * effectively caches the xform matrices between the physical's node and every
37 * force acting on it so that each PhysicsObject in the set held by the
38 * Physical doesn't have to wrt.
39 */
40 void BaseIntegrator::
41precompute_linear_matrices(Physical *physical,
42 const LinearForceVector &forces) {
43 nassertv(physical);
44 // make sure the physical's in the scene graph, somewhere.
45 nassertv(physical->get_physical_node() != nullptr);
46
47 // by global forces, we mean forces not contained in the physical
48 size_t global_force_vec_size = forces.size();
49
50 // by local forces, we mean members of the physical's force set.
51 size_t local_force_vec_size = physical->get_linear_forces().size();
52
53 // prepare the vector
54 _precomputed_linear_matrices.clear();
55 _precomputed_linear_matrices.reserve(
56 global_force_vec_size + local_force_vec_size);
57
58 NodePath physical_np(physical->get_physical_node_path());
59 NodePath parent_physical_np = physical_np.get_parent();
60
61 // tally the global xforms
62 LinearForceVector::const_iterator fi;
63 for (fi = forces.begin(); fi != forces.end(); ++fi) {
64 // LinearForce *cur_force = *fi;
65 nassertv((*fi)->get_force_node() != nullptr);
66
67 NodePath force_np = (*fi)->get_force_node_path();
68 _precomputed_linear_matrices.push_back(
69 force_np.get_transform(parent_physical_np)->get_mat());
70 }
71
72 // tally the local xforms
73 const LinearForceVector &force_vector = physical->get_linear_forces();
74 for (fi = force_vector.begin(); fi != force_vector.end(); ++fi) {
75 nassertv((*fi)->get_force_node() != nullptr);
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
83/**
84 * effectively caches the xform matrices between the physical's node and every
85 * force acting on it so that each PhysicsObject in the set held by the
86 * Physical doesn't have to wrt.
87 */
88 void BaseIntegrator::
89precompute_angular_matrices(Physical *physical,
90 const AngularForceVector &forces) {
91 nassertv(physical);
92 // make sure the physical's in the scene graph, somewhere.
93 nassertv(physical->get_physical_node() != nullptr);
94
95 // by global forces, we mean forces not contained in the physical
96 size_t global_force_vec_size = forces.size();
97
98 // by local forces, we mean members of the physical's force set.
99 size_t local_force_vec_size = physical->get_angular_forces().size();
100
101 // prepare the vector
102 _precomputed_angular_matrices.clear();
103 _precomputed_angular_matrices.reserve(
104 global_force_vec_size + local_force_vec_size);
105
106 NodePath physical_np(physical->get_physical_node_path());
107 NodePath parent_physical_np = physical_np.get_parent();
108
109 // tally the global xforms
110 AngularForceVector::const_iterator fi;
111 for (fi = forces.begin(); fi != forces.end(); ++fi) {
112 nassertv((*fi)->get_force_node() != nullptr);
113
114 NodePath force_np = (*fi)->get_force_node_path();
115 _precomputed_angular_matrices.push_back(
116 force_np.get_transform(parent_physical_np)->get_mat());
117 }
118
119 // tally the local xforms
120 const AngularForceVector &force_vector = physical->get_angular_forces();
121 for (fi = force_vector.begin(); fi != force_vector.end(); ++fi) {
122 nassertv((*fi)->get_force_node() != nullptr);
123
124 NodePath force_np = (*fi)->get_force_node_path();
125 _precomputed_angular_matrices.push_back(
126 force_np.get_transform(parent_physical_np)->get_mat());
127 }
128}
129
130/**
131 * Write a string representation of this instance to <out>.
132 */
133 void BaseIntegrator::
134 output(ostream &out) const {
135 #ifndef NDEBUG //[
136 out<<"BaseIntegrator (id "<<this<<")";
137 #endif //] NDEBUG
138}
139
140/**
141 * Write a string representation of this instance to <out>.
142 */
143 void BaseIntegrator::
144 write_precomputed_linear_matrices(ostream &out, int indent) const {
145 #ifndef NDEBUG //[
146 out.width(indent);
147 out<<""<<"_precomputed_linear_matrices\n";
148 for (MatrixVector::const_iterator i=_precomputed_linear_matrices.begin();
149 i != _precomputed_linear_matrices.end();
150 ++i) {
151 out.width(indent+2); out<<""; (*i).output(out); out<<"\n";
152 }
153 #endif //] NDEBUG
154}
155
156/**
157 * Write a string representation of this instance to <out>.
158 */
159 void BaseIntegrator::
160 write_precomputed_angular_matrices(ostream &out, int indent) const {
161 #ifndef NDEBUG //[
162 out.width(indent);
163 out<<""<<"_precomputed_angular_matrices\n";
164 for (MatrixVector::const_iterator i=_precomputed_angular_matrices.begin();
165 i != _precomputed_angular_matrices.end();
166 ++i) {
167 out.width(indent+2); out<<""; (*i).output(out); out<<"\n";
168 }
169 #endif //] NDEBUG
170}
171
172/**
173 * Write a string representation of this instance to <out>.
174 */
175 void BaseIntegrator::
176 write(ostream &out, int indent) const {
177 #ifndef NDEBUG //[
178 out.width(indent); out<<""; out<<"BaseIntegrator:\n";
179 write_precomputed_linear_matrices(out, indent+2);
180 write_precomputed_angular_matrices(out, indent+2);
181 #endif //] NDEBUG
182}
baseIntegrator.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
BaseIntegrator::write_precomputed_angular_matrices
virtual void write_precomputed_angular_matrices(std::ostream &out, int indent=0) const
Write a string representation of this instance to <out>.
Definition baseIntegrator.cxx:160
BaseIntegrator::write_precomputed_linear_matrices
virtual void write_precomputed_linear_matrices(std::ostream &out, int indent=0) const
Write a string representation of this instance to <out>.
Definition baseIntegrator.cxx:144
BaseIntegrator::~BaseIntegrator
virtual ~BaseIntegrator()
destructor
Definition baseIntegrator.cxx:32
BaseIntegrator::output
virtual void output(std::ostream &out) const
Write a string representation of this instance to <out>.
Definition baseIntegrator.cxx:134
BaseIntegrator::write
virtual void write(std::ostream &out, int indent=0) const
Write a string representation of this instance to <out>.
Definition baseIntegrator.cxx:176
NodePath
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition nodePath.h:159
NodePath::get_parent
get_parent
Returns the NodePath to the parent of the referenced node: that is, this NodePath,...
Definition nodePath.h:242
NodePath::get_transform
const TransformState * get_transform(Thread *current_thread=Thread::get_current_thread()) const
Returns the complete transform object set on this node.
Definition nodePath.cxx:794
Physical
Defines a set of physically modeled attributes.
Definition physical.h:37
TransformState::get_mat
get_mat
Returns the matrix that describes the transform.
Definition transformState.h:168
forceNode.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
indent
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
Definition indent.cxx:20
nodePath.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
physicalNode.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.