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()) || v.dot(friction) < 0.0f);
65  // cary said to cap this at zero so that friction can't reverse your
66  // direction, but it seems to me that if you're computing: v + (-v * _coef),
67  // _coef in [0, 1] that this will always be greater than or equal to zero.
68  return friction;
69 }
70 
71 /**
72  * Write a string representation of this instance to <out>.
73  */
75 output(std::ostream &out) const {
76  #ifndef NDEBUG //[
77  out<<"LinearFrictionForce";
78  #endif //] NDEBUG
79 }
80 
81 /**
82  * Write a string representation of this instance to <out>.
83  */
85 write(std::ostream &out, int indent) const {
86  #ifndef NDEBUG //[
87  out.width(indent); out<<""; out<<"LinearFrictionForce:\n";
88  out.width(indent+2); out<<""; out<<"_coef "<<_coef<<":\n";
89  LinearForce::write(out, indent+2);
90  #endif //] NDEBUG
91 }
A force that acts on a PhysicsObject by way of an Integrator.
Definition: linearForce.h:23
virtual void write(std::ostream &out, int indent=0) const
Write a string representation of this instance to <out>.
Definition: linearForce.cxx:95
Friction-based drag force.
virtual ~LinearFrictionForce()
destructor
virtual void write(std::ostream &out, int indent=0) const
Write a string representation of this instance to <out>.
LinearFrictionForce(PN_stdfloat coef=1.0f, PN_stdfloat a=1.0f, bool m=false)
Constructor.
virtual void output(std::ostream &out) const
Write a string representation of this instance to <out>.
A body on which physics will be applied.
Definition: physicsObject.h:27
get_velocity
Velocity Query per second.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
Definition: indent.cxx:20
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.