Panda3D
Loading...
Searching...
No Matches
linearCylinderVortexForce.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 linearCylinderVortexForce.cxx
10 * @author charles
11 * @date 2000-07-24
12 */
13
14#include "config_physics.h"
16#include "nearly_zero.h"
17#include "cmath.h"
18
19TypeHandle LinearCylinderVortexForce::_type_handle;
20
21/**
22 * Simple Constructor
23 */
25LinearCylinderVortexForce(PN_stdfloat radius, PN_stdfloat length, PN_stdfloat coef,
26 PN_stdfloat a, bool md) :
27 LinearForce(a, md),
28 _radius(radius), _length(length), _coef(coef) {
29}
30
31/**
32 * copy Constructor
33 */
36 LinearForce(copy) {
37 _radius = copy._radius;
38 _length = copy._length;
39 _coef = copy._coef;
40}
41
42/**
43 * Destructor
44 */
48
49/**
50 * child copier
51 */
52LinearForce *LinearCylinderVortexForce::
53make_copy() {
54 return new LinearCylinderVortexForce(*this);
55}
56
57/**
58 * returns the centripetal force vector for the passed-in object
59 */
60LVector3 LinearCylinderVortexForce::
61get_child_vector(const PhysicsObject *po) {
62 // get the force-space transform- this MUST be the relative matrix from the
63 // point's local coordinate system to the attached node's local system.
64 // LMatrix4 force_space_xform = LMatrix4::ident_mat();
65 LVector3 force_vec(0.0f, 0.0f, 0.0f);
66
67 // project the point into force_space
68 LPoint3 point = po->get_position();
69
70 // clip along length
71 if (point[2] < 0.0f || point[2] > _length)
72 return force_vec;
73
74 // clip to radius
75 PN_stdfloat x_squared = point[0] * point[0];
76 PN_stdfloat y_squared = point[1] * point[1];
77 PN_stdfloat dist_squared = x_squared + y_squared;
78 PN_stdfloat radius_squared = _radius * _radius;
79
80 // squared space increases monotonically wrt linear space, so there's no
81 // need to sqrt to check insideoutside this disc.
82 if (dist_squared > radius_squared)
83 return force_vec;
84
85 if IS_NEARLY_ZERO(dist_squared)
86 return force_vec;
87
88 PN_stdfloat r = csqrt(dist_squared);
89
90 if IS_NEARLY_ZERO(r)
91 return force_vec;
92
93 LVector3 tangential = point;
94 tangential[2] = 0.0f;
95 tangential.normalize();
96 tangential = tangential.cross(LVector3(0,0,1));
97
98 LVector3 centripetal = -point;
99 centripetal[2] = 0.0f;
100 centripetal.normalize();
101
102 LVector3 combined = tangential + centripetal;
103 combined.normalize();
104
105 // a = v^2 r centripetal = centripetal * _coef *
106 // (tangential.length_squared() (r + get_nearly_zero_value(r)));
107
108 centripetal = combined * _coef * po->get_velocity().length();
109
110 // centripetal = combined * _coef * (po->get_velocity().length() (r +
111 // get_nearly_zero_value(r)));
112
113 return centripetal;
114}
115
116/**
117 * Write a string representation of this instance to <out>.
118 */
120output(std::ostream &out) const {
121 #ifndef NDEBUG //[
122 out<<"LinearCylinderVortexForce";
123 #endif //] NDEBUG
124}
125
126/**
127 * Write a string representation of this instance to <out>.
128 */
130write(std::ostream &out, int indent) const {
131 #ifndef NDEBUG //[
132 out.width(indent); out<<""; out<<"LinearCylinderVortexForce:\n";
134 #endif //] NDEBUG
135}
Defines a cylinder inside of which all forces are tangential to the theta of the particle wrt the z-a...
LinearCylinderVortexForce(PN_stdfloat radius=1.0f, PN_stdfloat length=0.0f, PN_stdfloat coef=1.0f, PN_stdfloat a=1.0f, bool md=false)
Simple Constructor.
virtual void output(std::ostream &out) const
Write a string representation of this instance to <out>.
virtual ~LinearCylinderVortexForce()
Destructor.
virtual void write(std::ostream &out, int indent=0) const
Write a string representation of this instance to <out>.
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>.
A body on which physics will be applied.
get_position
Position Query.
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.
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.