Panda3D
linearFrictionForce.cxx
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file linearFrictionForce.cxx
10  * @author charles
11  * @date 2000-06-23
12  */
13 
14 #include "linearFrictionForce.h"
15 #include "config_physics.h"
16 
17 TypeHandle LinearFrictionForce::_type_handle;
18 
19 /**
20  * Constructor
21  */
23 LinearFrictionForce(PN_stdfloat coef, PN_stdfloat a, bool m) :
24  LinearForce(a, m) {
25  set_coef(coef);
26 }
27 
28 /**
29  * copy constructor
30  */
33  LinearForce(copy) {
34  _coef = copy._coef;
35 }
36 
37 /**
38  * destructor
39  */
42 }
43 
44 /**
45  * copier
46  */
47 LinearForce *LinearFrictionForce::
48 make_copy() {
49  return new LinearFrictionForce(*this);
50 }
51 
52 /**
53  * Constructor
54  */
55 LVector3 LinearFrictionForce::
56 get_child_vector(const PhysicsObject* po) {
57  LVector3 v = po->get_velocity();
58  assert(_coef>=0.0f && _coef<=1.0f);
59  // Create a force vector in the opposite direction of v:
60  LVector3 friction = v * -_coef;
61  physics_debug(" v "<<v<<" len "<<v.length()
62  <<" friction "<<friction<<" len "<<friction.length()
63  <<" dot "<<(normalize(v).dot(normalize(friction))));
64  assert(friction.almost_equal(LVector3::zero())
65  || IS_NEARLY_EQUAL(normalize(v).dot(normalize(friction)), -1.0f));
66  // cary said to cap this at zero so that friction can't reverse your
67  // direction, but it seems to me that if you're computing: v + (-v * _coef),
68  // _coef in [0, 1] that this will always be greater than or equal to zero.
69  return friction;
70 }
71 
72 /**
73  * Write a string representation of this instance to <out>.
74  */
76 output(std::ostream &out) const {
77  #ifndef NDEBUG //[
78  out<<"LinearFrictionForce";
79  #endif //] NDEBUG
80 }
81 
82 /**
83  * Write a string representation of this instance to <out>.
84  */
86 write(std::ostream &out, int indent) const {
87  #ifndef NDEBUG //[
88  out.width(indent); out<<""; out<<"LinearFrictionForce:\n";
89  out.width(indent+2); out<<""; out<<"_coef "<<_coef<<":\n";
90  LinearForce::write(out, indent+2);
91  #endif //] NDEBUG
92 }
Friction-based drag force.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A body on which physics will be applied.
Definition: physicsObject.h:27
LinearFrictionForce(PN_stdfloat coef=1.0f, PN_stdfloat a=1.0f, bool m=false)
Constructor.
A force that acts on a PhysicsObject by way of an Integrator.
Definition: linearForce.h:23
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
Definition: indent.cxx:20
virtual void write(std::ostream &out, int indent=0) const
Write a string representation of this instance to <out>.
LVector3 get_velocity() const
Velocity Query per second.
virtual void output(std::ostream &out) const
Write a string representation of this instance to <out>.
virtual void write(std::ostream &out, int indent=0) const
Write a string representation of this instance to <out>.
Definition: linearForce.cxx:95
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual ~LinearFrictionForce()
destructor