00001 // Filename: baseIntegrator.cxx 00002 // Created by: charles (11Aug00) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved 00008 // 00009 // All use of this software is subject to the terms of the Panda 3d 00010 // Software license. You should have received a copy of this license 00011 // along with this source code; you will also find a current copy of 00012 // the license at http://www.panda3d.org/license.txt . 00013 // 00014 // To contact the maintainers of this program write to 00015 // panda3d@yahoogroups.com . 00016 // 00017 //////////////////////////////////////////////////////////////////// 00018 00019 #include "baseIntegrator.h" 00020 #include "physicalNode.h" 00021 #include "forceNode.h" 00022 #include "nodePath.h" 00023 00024 //////////////////////////////////////////////////////////////////// 00025 // Function : BaseIntegrator 00026 // Access : protected 00027 // Description : constructor 00028 //////////////////////////////////////////////////////////////////// 00029 BaseIntegrator:: 00030 BaseIntegrator(void) { 00031 } 00032 00033 //////////////////////////////////////////////////////////////////// 00034 // Function : ~BaseIntegrator 00035 // Access : public, virtual 00036 // Description : destructor 00037 //////////////////////////////////////////////////////////////////// 00038 BaseIntegrator:: 00039 ~BaseIntegrator(void) { 00040 } 00041 00042 //////////////////////////////////////////////////////////////////// 00043 // Function : precompute_linear_matrices 00044 // Access : protected 00045 // Description : effectively caches the xform matrices between 00046 // the physical's node and every force acting on it 00047 // so that each PhysicsObject in the set held by the 00048 // Physical doesn't have to wrt. 00049 //////////////////////////////////////////////////////////////////// 00050 void BaseIntegrator:: 00051 precompute_linear_matrices(Physical *physical, 00052 const pvector< PT(LinearForce) > &forces) { 00053 // make sure the physical's in the scene graph, somewhere. 00054 PhysicalNode *physical_node = physical->get_physical_node(); 00055 nassertv(physical_node != NULL); 00056 00057 // by global forces, we mean forces not contained in the physical 00058 int global_force_vec_size = forces.size(); 00059 00060 // by local forces, we mean members of the physical's force set. 00061 int local_force_vec_size = physical->get_linear_forces().size(); 00062 int i; 00063 00064 ForceNode *force_node; 00065 00066 // prepare the vector 00067 _precomputed_linear_matrices.clear(); 00068 _precomputed_linear_matrices.reserve(global_force_vec_size + local_force_vec_size); 00069 00070 NodePath physical_np(physical_node); 00071 00072 // tally the global xforms 00073 for (i = 0; i < global_force_vec_size; i++) { 00074 force_node = forces[i]->get_force_node(); 00075 nassertv(force_node != (ForceNode *) NULL); 00076 00077 NodePath force_np(force_node); 00078 _precomputed_linear_matrices.push_back(physical_np.get_mat(force_node)); 00079 } 00080 00081 const pvector< PT(LinearForce) > &force_vector = 00082 physical->get_linear_forces(); 00083 00084 // tally the local xforms 00085 for (i = 0; i < local_force_vec_size; i++) { 00086 force_node = force_vector[i]->get_force_node(); 00087 nassertv(force_node != (ForceNode *) NULL); 00088 00089 NodePath force_np(force_node); 00090 _precomputed_linear_matrices.push_back(physical_np.get_mat(force_node)); 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 pvector< PT(AngularForce) > &forces) { 00105 // make sure the physical's in the scene graph, somewhere. 00106 PhysicalNode *physical_node = physical->get_physical_node(); 00107 nassertv(physical_node != NULL); 00108 00109 // by global forces, we mean forces not contained in the physical 00110 int global_force_vec_size = forces.size(); 00111 00112 // by local forces, we mean members of the physical's force set. 00113 int local_force_vec_size = physical->get_angular_forces().size(); 00114 int i; 00115 00116 ForceNode *force_node; 00117 00118 // prepare the vector 00119 _precomputed_angular_matrices.clear(); 00120 _precomputed_angular_matrices.reserve(global_force_vec_size + local_force_vec_size); 00121 00122 NodePath physical_np(physical_node); 00123 00124 // tally the global xforms 00125 for (i = 0; i < global_force_vec_size; i++) { 00126 force_node = forces[i]->get_force_node(); 00127 nassertv(force_node != (ForceNode *) NULL); 00128 00129 NodePath force_np(force_node); 00130 _precomputed_angular_matrices.push_back(physical_np.get_mat(force_node)); 00131 } 00132 00133 const pvector< PT(AngularForce) > &force_vector = 00134 physical->get_angular_forces(); 00135 00136 // tally the local xforms 00137 for (i = 0; i < local_force_vec_size; i++) { 00138 force_node = force_vector[i]->get_force_node(); 00139 nassertv(force_node != (ForceNode *) NULL); 00140 00141 NodePath force_np(force_node); 00142 _precomputed_angular_matrices.push_back(physical_np.get_mat(force_node)); 00143 } 00144 }