Panda3D
|
00001 // Filename: linearForce.cxx 00002 // Created by: charles (14Jun00) 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 "datagram.h" 00016 #include "datagramIterator.h" 00017 #include "bamReader.h" 00018 #include "bamWriter.h" 00019 00020 #include "linearForce.h" 00021 00022 TypeHandle LinearForce::_type_handle; 00023 00024 //////////////////////////////////////////////////////////////////// 00025 // Function : LinearForce 00026 // Access : Protected 00027 // Description : Default/component-based constructor 00028 //////////////////////////////////////////////////////////////////// 00029 LinearForce:: 00030 LinearForce(PN_stdfloat a, bool mass) : 00031 BaseForce(true), 00032 _amplitude(a), _mass_dependent(mass), 00033 _x_mask(true), _y_mask(true), _z_mask(true) { 00034 } 00035 00036 //////////////////////////////////////////////////////////////////// 00037 // Function : LinearForce 00038 // Access : Protected 00039 // Description : copy constructor 00040 //////////////////////////////////////////////////////////////////// 00041 LinearForce:: 00042 LinearForce(const LinearForce& copy) : 00043 BaseForce(copy) { 00044 _amplitude = copy._amplitude; 00045 _mass_dependent = copy._mass_dependent; 00046 _x_mask = copy._x_mask; 00047 _y_mask = copy._y_mask; 00048 _z_mask = copy._z_mask; 00049 } 00050 00051 //////////////////////////////////////////////////////////////////// 00052 // Function : ~LinearForce 00053 // Access : Public 00054 // Description : Destructor 00055 //////////////////////////////////////////////////////////////////// 00056 LinearForce:: 00057 ~LinearForce() { 00058 } 00059 00060 //////////////////////////////////////////////////////////////////// 00061 // Function : get_vector 00062 // Access : Public 00063 //////////////////////////////////////////////////////////////////// 00064 LVector3 LinearForce:: 00065 get_vector(const PhysicsObject *po) { 00066 LVector3 child_vector = get_child_vector(po) * _amplitude; 00067 nassertr(!child_vector.is_nan(), LVector3::zero()); 00068 00069 if (_x_mask == false) 00070 child_vector[0] = 0.0f; 00071 00072 if (_y_mask == false) 00073 child_vector[1] = 0.0f; 00074 00075 if (_z_mask == false) 00076 child_vector[2] = 0.0f; 00077 00078 return child_vector; 00079 } 00080 00081 //////////////////////////////////////////////////////////////////// 00082 // Function : is_linear 00083 // Access : Public 00084 //////////////////////////////////////////////////////////////////// 00085 bool LinearForce:: 00086 is_linear() const { 00087 return true; 00088 } 00089 00090 //////////////////////////////////////////////////////////////////// 00091 // Function : output 00092 // Access : Public 00093 // Description : Write a string representation of this instance to 00094 // <out>. 00095 //////////////////////////////////////////////////////////////////// 00096 void LinearForce:: 00097 output(ostream &out) const { 00098 #ifndef NDEBUG //[ 00099 out<<"LinearForce (id "<<this<<")"; 00100 #endif //] NDEBUG 00101 } 00102 00103 //////////////////////////////////////////////////////////////////// 00104 // Function : write 00105 // Access : Public 00106 // Description : Write a string representation of this instance to 00107 // <out>. 00108 //////////////////////////////////////////////////////////////////// 00109 void LinearForce:: 00110 write(ostream &out, unsigned int indent) const { 00111 #ifndef NDEBUG //[ 00112 out.width(indent); out<<""; out<<"LinearForce (id "<<this<<")\n"; 00113 out.width(indent+2); out<<""; out<<"_amplitude "<<_amplitude<<"\n"; 00114 out.width(indent+2); out<<""; out<<"_mass_dependent "<<_mass_dependent<<"\n"; 00115 out.width(indent+2); out<<""; out<<"_x_mask "<<_x_mask<<"\n"; 00116 out.width(indent+2); out<<""; out<<"_y_mask "<<_y_mask<<"\n"; 00117 out.width(indent+2); out<<""; out<<"_z_mask "<<_z_mask<<"\n"; 00118 BaseForce::write(out, indent+2); 00119 #endif //] NDEBUG 00120 }