Panda3D
|
00001 // Filename: linearIntegrator.cxx 00002 // Created by: charles (02Aug00) 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 "linearIntegrator.h" 00016 #include "config_physics.h" 00017 #include "physicalNode.h" 00018 #include "forceNode.h" 00019 00020 ConfigVariableDouble LinearIntegrator::_max_linear_dt 00021 ("default_max_linear_dt", 1.0f / 30.0f); 00022 00023 00024 //////////////////////////////////////////////////////////////////// 00025 // Function : BaseLinearIntegrator 00026 // Access : Protected 00027 // Description : constructor 00028 //////////////////////////////////////////////////////////////////// 00029 LinearIntegrator:: 00030 LinearIntegrator() { 00031 } 00032 00033 //////////////////////////////////////////////////////////////////// 00034 // Function : ~LinearIntegrator 00035 // Access : public, virtual 00036 // Description : destructor 00037 //////////////////////////////////////////////////////////////////// 00038 LinearIntegrator:: 00039 ~LinearIntegrator() { 00040 } 00041 00042 //////////////////////////////////////////////////////////////////// 00043 // Function : integrate 00044 // Access : public 00045 // Description : parent integration routine, hands off to child 00046 // virtual. 00047 //////////////////////////////////////////////////////////////////// 00048 void LinearIntegrator:: 00049 integrate(Physical *physical, LinearForceVector &forces, 00050 PN_stdfloat dt) { 00051 /* <-- darren, 2000.10.06 00052 // cap dt so physics don't go flying off on lags 00053 if (dt > _max_linear_dt) 00054 dt = _max_linear_dt; 00055 */ 00056 00057 PhysicsObject::Vector::const_iterator current_object_iter; 00058 current_object_iter = physical->get_object_vector().begin(); 00059 for (; current_object_iter != physical->get_object_vector().end(); 00060 ++current_object_iter) { 00061 PhysicsObject *current_object = *current_object_iter; 00062 00063 // bail out if this object doesn't exist or doesn't want to be 00064 // processed. 00065 if (current_object == (PhysicsObject *) NULL) { 00066 continue; 00067 } 00068 00069 // set the object's last position to its current position before we move it 00070 current_object->set_last_position(current_object->get_position()); 00071 } 00072 child_integrate(physical, forces, dt); 00073 } 00074 00075 //////////////////////////////////////////////////////////////////// 00076 // Function : output 00077 // Access : Public 00078 // Description : Write a string representation of this instance to 00079 // <out>. 00080 //////////////////////////////////////////////////////////////////// 00081 void LinearIntegrator:: 00082 output(ostream &out) const { 00083 #ifndef NDEBUG //[ 00084 out<<"LinearIntegrator"; 00085 #endif //] NDEBUG 00086 } 00087 00088 //////////////////////////////////////////////////////////////////// 00089 // Function : write 00090 // Access : Public 00091 // Description : Write a string representation of this instance to 00092 // <out>. 00093 //////////////////////////////////////////////////////////////////// 00094 void LinearIntegrator:: 00095 write(ostream &out, unsigned int indent) const { 00096 #ifndef NDEBUG //[ 00097 out.width(indent); out<<""; out<<"LinearIntegrator:\n"; 00098 out.width(indent+2); out<<""; out<<"_max_linear_dt "<<_max_linear_dt<<" (class static)\n"; 00099 BaseIntegrator::write(out, indent+2); 00100 #endif //] NDEBUG 00101 }