00001 // Filename: linearFrictionForce.cxx 00002 // Created by: charles (23Jun00) 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 "linearFrictionForce.h" 00020 00021 TypeHandle LinearFrictionForce::_type_handle; 00022 00023 //////////////////////////////////////////////////////////////////// 00024 // Function : LinearFrictionForce 00025 // Access : Public 00026 // Description : Constructor 00027 //////////////////////////////////////////////////////////////////// 00028 LinearFrictionForce:: 00029 LinearFrictionForce(float coef, float a, bool m) : 00030 LinearForce(a, m) { 00031 00032 // friction REALLY shouldn't be outside of [0, 1] 00033 if (coef < 0.0f) 00034 coef = 0.0f; 00035 else if (coef > 1.0f) 00036 coef = 1.0f; 00037 00038 _coef = coef; 00039 } 00040 00041 //////////////////////////////////////////////////////////////////// 00042 // Function : LinearFrictionForce 00043 // Access : Public 00044 // Description : copy constructor 00045 //////////////////////////////////////////////////////////////////// 00046 LinearFrictionForce:: 00047 LinearFrictionForce(const LinearFrictionForce ©) : 00048 LinearForce(copy) { 00049 _coef = copy._coef; 00050 } 00051 00052 //////////////////////////////////////////////////////////////////// 00053 // Function : LinearFrictionForce 00054 // Access : Public 00055 // Description : destructor 00056 //////////////////////////////////////////////////////////////////// 00057 LinearFrictionForce:: 00058 ~LinearFrictionForce(void) { 00059 } 00060 00061 //////////////////////////////////////////////////////////////////// 00062 // Function : make_copy 00063 // Access : Public 00064 // Description : copier 00065 //////////////////////////////////////////////////////////////////// 00066 LinearForce *LinearFrictionForce:: 00067 make_copy(void) { 00068 return new LinearFrictionForce(*this); 00069 } 00070 00071 //////////////////////////////////////////////////////////////////// 00072 // Function : LinearFrictionForce 00073 // Access : Public 00074 // Description : Constructor 00075 //////////////////////////////////////////////////////////////////// 00076 LVector3f LinearFrictionForce:: 00077 get_child_vector(const PhysicsObject* po) { 00078 LVector3f v = po->get_velocity(); 00079 LVector3f friction = -v * (1.0f - _coef); 00080 00081 // cary said to cap this at zero so that friction can't reverse 00082 // your direction, but it seems to me that if you're computing: 00083 // v + (-v * _coef), _coef in [0, 1] 00084 // that this will always be greater than or equal to zero. 00085 return friction; 00086 }