00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "config_physics.h"
00016 #include "linearCylinderVortexForce.h"
00017 #include "nearly_zero.h"
00018 #include "cmath.h"
00019
00020 TypeHandle LinearCylinderVortexForce::_type_handle;
00021
00022
00023
00024
00025
00026
00027 LinearCylinderVortexForce::
00028 LinearCylinderVortexForce(PN_stdfloat radius, PN_stdfloat length, PN_stdfloat coef,
00029 PN_stdfloat a, bool md) :
00030 LinearForce(a, md),
00031 _radius(radius), _length(length), _coef(coef) {
00032 }
00033
00034
00035
00036
00037
00038
00039 LinearCylinderVortexForce::
00040 LinearCylinderVortexForce(const LinearCylinderVortexForce ©) :
00041 LinearForce(copy) {
00042 _radius = copy._radius;
00043 _length = copy._length;
00044 _coef = copy._coef;
00045 }
00046
00047
00048
00049
00050
00051
00052 LinearCylinderVortexForce::
00053 ~LinearCylinderVortexForce() {
00054 }
00055
00056
00057
00058
00059
00060
00061 LinearForce *LinearCylinderVortexForce::
00062 make_copy() {
00063 return new LinearCylinderVortexForce(*this);
00064 }
00065
00066
00067
00068
00069
00070
00071
00072 LVector3 LinearCylinderVortexForce::
00073 get_child_vector(const PhysicsObject *po) {
00074
00075
00076
00077
00078 LVector3 force_vec(0.0f, 0.0f, 0.0f);
00079
00080
00081 LPoint3 point = po->get_position();
00082
00083
00084 if (point[2] < 0.0f || point[2] > _length)
00085 return force_vec;
00086
00087
00088 PN_stdfloat x_squared = point[0] * point[0];
00089 PN_stdfloat y_squared = point[1] * point[1];
00090 PN_stdfloat dist_squared = x_squared + y_squared;
00091 PN_stdfloat radius_squared = _radius * _radius;
00092
00093
00094
00095 if (dist_squared > radius_squared)
00096 return force_vec;
00097
00098 if IS_NEARLY_ZERO(dist_squared)
00099 return force_vec;
00100
00101 PN_stdfloat r = csqrt(dist_squared);
00102
00103 if IS_NEARLY_ZERO(r)
00104 return force_vec;
00105
00106 LVector3 tangential = point;
00107 tangential[2] = 0.0f;
00108 tangential.normalize();
00109 tangential = tangential.cross(LVector3(0,0,1));
00110
00111 LVector3 centripetal = -point;
00112 centripetal[2] = 0.0f;
00113 centripetal.normalize();
00114
00115 LVector3 combined = tangential + centripetal;
00116 combined.normalize();
00117
00118
00119
00120
00121
00122 centripetal = combined * _coef * po->get_velocity().length();
00123
00124
00125
00126
00127 return centripetal;
00128 }
00129
00130
00131
00132
00133
00134
00135
00136 void LinearCylinderVortexForce::
00137 output(ostream &out) const {
00138 #ifndef NDEBUG //[
00139 out<<"LinearCylinderVortexForce";
00140 #endif //] NDEBUG
00141 }
00142
00143
00144
00145
00146
00147
00148
00149 void LinearCylinderVortexForce::
00150 write(ostream &out, unsigned int indent) const {
00151 #ifndef NDEBUG //[
00152 out.width(indent); out<<""; out<<"LinearCylinderVortexForce:\n";
00153 LinearForce::write(out, indent+2);
00154 #endif //] NDEBUG
00155 }