Panda3D
linearForce.cxx
1 // Filename: linearForce.cxx
2 // Created by: charles (14Jun00)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "datagram.h"
16 #include "datagramIterator.h"
17 #include "bamReader.h"
18 #include "bamWriter.h"
19 
20 #include "linearForce.h"
21 
22 TypeHandle LinearForce::_type_handle;
23 
24 ////////////////////////////////////////////////////////////////////
25 // Function : LinearForce
26 // Access : Protected
27 // Description : Default/component-based constructor
28 ////////////////////////////////////////////////////////////////////
29 LinearForce::
30 LinearForce(PN_stdfloat a, bool mass) :
31  BaseForce(true),
32  _amplitude(a), _mass_dependent(mass),
33  _x_mask(true), _y_mask(true), _z_mask(true) {
34 }
35 
36 ////////////////////////////////////////////////////////////////////
37 // Function : LinearForce
38 // Access : Protected
39 // Description : copy constructor
40 ////////////////////////////////////////////////////////////////////
41 LinearForce::
42 LinearForce(const LinearForce& copy) :
43  BaseForce(copy) {
44  _amplitude = copy._amplitude;
45  _mass_dependent = copy._mass_dependent;
46  _x_mask = copy._x_mask;
47  _y_mask = copy._y_mask;
48  _z_mask = copy._z_mask;
49 }
50 
51 ////////////////////////////////////////////////////////////////////
52 // Function : ~LinearForce
53 // Access : Public
54 // Description : Destructor
55 ////////////////////////////////////////////////////////////////////
58 }
59 
60 ////////////////////////////////////////////////////////////////////
61 // Function : get_vector
62 // Access : Public
63 ////////////////////////////////////////////////////////////////////
64 LVector3 LinearForce::
65 get_vector(const PhysicsObject *po) {
66  LVector3 child_vector = get_child_vector(po) * _amplitude;
67  nassertr(!child_vector.is_nan(), LVector3::zero());
68 
69  if (_x_mask == false)
70  child_vector[0] = 0.0f;
71 
72  if (_y_mask == false)
73  child_vector[1] = 0.0f;
74 
75  if (_z_mask == false)
76  child_vector[2] = 0.0f;
77 
78  return child_vector;
79 }
80 
81 ////////////////////////////////////////////////////////////////////
82 // Function : is_linear
83 // Access : Public
84 ////////////////////////////////////////////////////////////////////
85 bool LinearForce::
86 is_linear() const {
87  return true;
88 }
89 
90 ////////////////////////////////////////////////////////////////////
91 // Function : output
92 // Access : Public
93 // Description : Write a string representation of this instance to
94 // <out>.
95 ////////////////////////////////////////////////////////////////////
96 void LinearForce::
97 output(ostream &out) const {
98  #ifndef NDEBUG //[
99  out<<"LinearForce (id "<<this<<")";
100  #endif //] NDEBUG
101 }
102 
103 ////////////////////////////////////////////////////////////////////
104 // Function : write
105 // Access : Public
106 // Description : Write a string representation of this instance to
107 // <out>.
108 ////////////////////////////////////////////////////////////////////
109 void LinearForce::
110 write(ostream &out, unsigned int indent) const {
111  #ifndef NDEBUG //[
112  out.width(indent); out<<""; out<<"LinearForce (id "<<this<<")\n";
113  out.width(indent+2); out<<""; out<<"_amplitude "<<_amplitude<<"\n";
114  out.width(indent+2); out<<""; out<<"_mass_dependent "<<_mass_dependent<<"\n";
115  out.width(indent+2); out<<""; out<<"_x_mask "<<_x_mask<<"\n";
116  out.width(indent+2); out<<""; out<<"_y_mask "<<_y_mask<<"\n";
117  out.width(indent+2); out<<""; out<<"_z_mask "<<_z_mask<<"\n";
118  BaseForce::write(out, indent+2);
119  #endif //] NDEBUG
120 }
~LinearForce()
Destructor.
Definition: linearForce.cxx:57
virtual void write(ostream &out, int indent_level=0) const
Write a string representation of this instance to <out>.
Definition: baseForce.cxx:72
A body on which physics will be applied.
Definition: physicsObject.h:29
static const LVector3f & zero()
Returns a zero-length vector.
Definition: lvector3.h:270
This is a three-component vector distance (as opposed to a three-component point, which represents a ...
Definition: lvector3.h:100
bool is_nan() const
Returns true if any component of the vector is not-a-number, false otherwise.
Definition: lvecBase3.h:464
A force that acts on a PhysicsObject by way of an Integrator.
Definition: linearForce.h:25
pure virtual base class for all forces that could POSSIBLY exist.
Definition: baseForce.h:32
virtual void write(ostream &out, unsigned int indent=0) const
Write a string representation of this instance to <out>.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
virtual void output(ostream &out) const
Write a string representation of this instance to <out>.
Definition: linearForce.cxx:97