Panda3D
 All Classes Functions Variables Enumerations
baseIntegrator.cxx
00001 // Filename: baseIntegrator.cxx
00002 // Created by:  charles (11Aug00)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #include "baseIntegrator.h"
00016 #include "physicalNode.h"
00017 #include "forceNode.h"
00018 #include "nodePath.h"
00019 
00020 ////////////////////////////////////////////////////////////////////
00021 //    Function : BaseIntegrator
00022 //      Access : protected
00023 // Description : constructor
00024 ////////////////////////////////////////////////////////////////////
00025 BaseIntegrator::
00026 BaseIntegrator() {
00027 }
00028 
00029 ////////////////////////////////////////////////////////////////////
00030 //    Function : ~BaseIntegrator
00031 //      Access : public, virtual
00032 // Description : destructor
00033 ////////////////////////////////////////////////////////////////////
00034 BaseIntegrator::
00035 ~BaseIntegrator() {
00036 }
00037 
00038 ////////////////////////////////////////////////////////////////////
00039 //    Function : precompute_linear_matrices
00040 //      Access : protected
00041 // Description : effectively caches the xform matrices between
00042 //               the physical's node and every force acting on it
00043 //               so that each PhysicsObject in the set held by the
00044 //               Physical doesn't have to wrt.
00045 ////////////////////////////////////////////////////////////////////
00046 void BaseIntegrator::
00047 precompute_linear_matrices(Physical *physical,
00048                            const LinearForceVector &forces) {
00049   nassertv(physical);
00050   // make sure the physical's in the scene graph, somewhere.
00051   PhysicalNode *physical_node = physical->get_physical_node();
00052   nassertv(physical_node);
00053 
00054   // by global forces, we mean forces not contained in the physical
00055   int global_force_vec_size = forces.size();
00056 
00057   // by local forces, we mean members of the physical's force set.
00058   int local_force_vec_size = physical->get_linear_forces().size();
00059 
00060   ForceNode *force_node;
00061 
00062   // prepare the vector
00063   _precomputed_linear_matrices.clear();
00064   _precomputed_linear_matrices.reserve(
00065       global_force_vec_size + local_force_vec_size);
00066 
00067   NodePath physical_np(physical->get_physical_node_path());
00068   NodePath parent_physical_np = physical_np.get_parent();
00069 
00070   // tally the global xforms
00071   LinearForceVector::const_iterator fi;
00072   for (fi = forces.begin(); fi != forces.end(); ++fi) {
00073     //LinearForce *cur_force = *fi;
00074     force_node = (*fi)->get_force_node();
00075     nassertv(force_node != (ForceNode *) NULL);
00076 
00077     NodePath force_np = (*fi)->get_force_node_path();
00078     _precomputed_linear_matrices.push_back(
00079         force_np.get_transform(parent_physical_np)->get_mat());
00080   }
00081 
00082   // tally the local xforms
00083   const LinearForceVector &force_vector = physical->get_linear_forces();
00084   for (fi = force_vector.begin(); fi != force_vector.end(); ++fi) {
00085     force_node = (*fi)->get_force_node();
00086     nassertv(force_node != (ForceNode *) NULL);
00087 
00088     NodePath force_np = (*fi)->get_force_node_path();
00089     _precomputed_linear_matrices.push_back(
00090         force_np.get_transform(parent_physical_np)->get_mat());
00091   }
00092 }
00093 
00094 ////////////////////////////////////////////////////////////////////
00095 //    Function : precompute_angular_matrices
00096 //      Access : protected
00097 // Description : effectively caches the xform matrices between
00098 //               the physical's node and every force acting on it
00099 //               so that each PhysicsObject in the set held by the
00100 //               Physical doesn't have to wrt.
00101 ////////////////////////////////////////////////////////////////////
00102 void BaseIntegrator::
00103 precompute_angular_matrices(Physical *physical,
00104                             const AngularForceVector &forces) {
00105   nassertv(physical);
00106   // make sure the physical's in the scene graph, somewhere.
00107   PhysicalNode *physical_node = physical->get_physical_node();
00108   nassertv(physical_node != NULL);
00109 
00110   // by global forces, we mean forces not contained in the physical
00111   int global_force_vec_size = forces.size();
00112 
00113   // by local forces, we mean members of the physical's force set.
00114   int local_force_vec_size = physical->get_angular_forces().size();
00115 
00116   ForceNode *force_node;
00117 
00118   // prepare the vector
00119   _precomputed_angular_matrices.clear();
00120   _precomputed_angular_matrices.reserve(
00121       global_force_vec_size + local_force_vec_size);
00122 
00123   NodePath physical_np(physical->get_physical_node_path());
00124   NodePath parent_physical_np = physical_np.get_parent();
00125 
00126   // tally the global xforms
00127   AngularForceVector::const_iterator fi;
00128   for (fi = forces.begin(); fi != forces.end(); ++fi) {
00129     force_node = (*fi)->get_force_node();
00130     nassertv(force_node != (ForceNode *) NULL);
00131 
00132     NodePath force_np = (*fi)->get_force_node_path();
00133     _precomputed_angular_matrices.push_back(
00134         force_np.get_transform(parent_physical_np)->get_mat());
00135   }
00136 
00137   // tally the local xforms
00138   const AngularForceVector &force_vector = physical->get_angular_forces();
00139   for (fi = force_vector.begin(); fi != force_vector.end(); ++fi) {
00140     force_node = (*fi)->get_force_node();
00141     nassertv(force_node != (ForceNode *) NULL);
00142 
00143     NodePath force_np = (*fi)->get_force_node_path();
00144     _precomputed_angular_matrices.push_back(
00145         force_np.get_transform(parent_physical_np)->get_mat());
00146   }
00147 }
00148 
00149 ////////////////////////////////////////////////////////////////////
00150 //     Function : output
00151 //       Access : Public
00152 //  Description : Write a string representation of this instance to
00153 //                <out>.
00154 ////////////////////////////////////////////////////////////////////
00155 void BaseIntegrator::
00156 output(ostream &out) const {
00157   #ifndef NDEBUG //[
00158   out<<"BaseIntegrator (id "<<this<<")";
00159   #endif //] NDEBUG
00160 }
00161 
00162 ////////////////////////////////////////////////////////////////////
00163 //     Function : write_precomputed_linear_matrices
00164 //       Access : Public
00165 //  Description : Write a string representation of this instance to
00166 //                <out>.
00167 ////////////////////////////////////////////////////////////////////
00168 void BaseIntegrator::
00169 write_precomputed_linear_matrices(ostream &out, unsigned int indent) const {
00170   #ifndef NDEBUG //[
00171   out.width(indent);
00172   out<<""<<"_precomputed_linear_matrices\n";
00173   for (MatrixVector::const_iterator i=_precomputed_linear_matrices.begin();
00174        i != _precomputed_linear_matrices.end();
00175        ++i) {
00176     out.width(indent+2); out<<""; (*i).output(out); out<<"\n";
00177   }
00178   #endif //] NDEBUG
00179 }
00180 
00181 ////////////////////////////////////////////////////////////////////
00182 //     Function : write_precomputed_angular_matrices
00183 //       Access : Public
00184 //  Description : Write a string representation of this instance to
00185 //                <out>.
00186 ////////////////////////////////////////////////////////////////////
00187 void BaseIntegrator::
00188 write_precomputed_angular_matrices(ostream &out, unsigned int indent) const {
00189   #ifndef NDEBUG //[
00190   out.width(indent);
00191   out<<""<<"_precomputed_angular_matrices\n";
00192   for (MatrixVector::const_iterator i=_precomputed_angular_matrices.begin();
00193        i != _precomputed_angular_matrices.end();
00194        ++i) {
00195     out.width(indent+2); out<<""; (*i).output(out); out<<"\n";
00196   }
00197   #endif //] NDEBUG
00198 }
00199 
00200 ////////////////////////////////////////////////////////////////////
00201 //     Function : write
00202 //       Access : Public
00203 //  Description : Write a string representation of this instance to
00204 //                <out>.
00205 ////////////////////////////////////////////////////////////////////
00206 void BaseIntegrator::
00207 write(ostream &out, unsigned int indent) const {
00208   #ifndef NDEBUG //[
00209   out.width(indent); out<<""; out<<"BaseIntegrator:\n";
00210   write_precomputed_linear_matrices(out, indent+2);
00211   write_precomputed_angular_matrices(out, indent+2);
00212   #endif //] NDEBUG
00213 }
 All Classes Functions Variables Enumerations