00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include <stdlib.h>
00016 #include <math.h>
00017
00018 #include "linearNoiseForce.h"
00019
00020
00021
00022 ConfigVariableInt LinearNoiseForce::_random_seed
00023 ("default_noise_force_seed", 665);
00024
00025 bool LinearNoiseForce::_initialized = false;
00026 unsigned char LinearNoiseForce::_prn_table[256];
00027 LVector3 LinearNoiseForce::_gradient_table[256];
00028
00029 TypeHandle LinearNoiseForce::_type_handle;
00030
00031
00032
00033
00034
00035
00036
00037 void LinearNoiseForce::
00038 init_noise_tables() {
00039
00040
00041 srand(_random_seed);
00042
00043 LVector3 *gtable = _gradient_table;
00044 for (int i = 0; i < 256; ++i) {
00045
00046 _prn_table[i] = rand() & 255;
00047
00048
00049 *gtable++ = random_unit_vector();
00050 }
00051 }
00052
00053
00054
00055
00056
00057
00058 LinearNoiseForce::
00059 LinearNoiseForce(PN_stdfloat a, bool mass) :
00060 LinearRandomForce(a, mass) {
00061 if (_initialized == false) {
00062 init_noise_tables();
00063 _initialized = true;
00064 }
00065 }
00066
00067
00068
00069
00070
00071
00072 LinearNoiseForce::
00073 LinearNoiseForce(const LinearNoiseForce ©) :
00074 LinearRandomForce(copy) {
00075 }
00076
00077
00078
00079
00080
00081
00082 LinearNoiseForce::
00083 ~LinearNoiseForce() {
00084 }
00085
00086
00087
00088
00089
00090
00091 LinearForce *LinearNoiseForce::
00092 make_copy() {
00093 return new LinearNoiseForce(*this);
00094 }
00095
00096
00097
00098
00099
00100
00101
00102 LVector3 LinearNoiseForce::
00103 get_child_vector(const PhysicsObject *po) {
00104 LPoint3 p = po->get_position();
00105
00106
00107 int int_x, int_y, int_z;
00108 PN_stdfloat frac_x, frac_y, frac_z;
00109
00110 int_x = (int) p[0];
00111 frac_x = p[0] - int_x;
00112
00113 int_y = (int) p[1];
00114 frac_y = p[1] - int_y;
00115
00116 int_z = (int) p[2];
00117 frac_z = p[2] - int_z;
00118
00119
00120 PN_stdfloat cubic_x, cubic_y, cubic_z;
00121
00122 cubic_x = cubic_step(frac_x);
00123 cubic_y = cubic_step(frac_y);
00124 cubic_z = cubic_step(frac_z);
00125
00126
00127 LVector3 temp0, temp1, temp2, temp3;
00128
00129
00130 temp0 = vlerp(cubic_x, get_lattice_entry(p),
00131 get_lattice_entry(p[0] + 1.0f, p[1], p[2]));
00132
00133 temp1 = vlerp(cubic_x, get_lattice_entry(p[0], p[1], p[2] + 1.0f),
00134 get_lattice_entry(p[0] + 1.0f, p[1], p[2] + 1.0f));
00135
00136 temp2 = vlerp(cubic_x, get_lattice_entry(p[0], p[1] + 1.0f, p[2]),
00137 get_lattice_entry(p[0] + 1.0f, p[1] + 1.0f, p[2]));
00138
00139 temp3 = vlerp(cubic_x, get_lattice_entry(p[0], p[1] + 1.0f, p[2] + 1.0f),
00140 get_lattice_entry(p[0] + 1.0f, p[1] + 1.0f, p[2] + 1.0f));
00141
00142
00143 temp0 = vlerp(cubic_z, temp0, temp1);
00144 temp1 = vlerp(cubic_z, temp2, temp3);
00145
00146
00147 return vlerp(cubic_y, temp0, temp1);
00148 }
00149
00150
00151
00152
00153
00154
00155
00156 void LinearNoiseForce::
00157 output(ostream &out) const {
00158 #ifndef NDEBUG //[
00159 out<<""<<"LinearNoiseForce";
00160 #endif //] NDEBUG
00161 }
00162
00163
00164
00165
00166
00167
00168
00169 void LinearNoiseForce::
00170 write(ostream &out, unsigned int indent) const {
00171 #ifndef NDEBUG //[
00172 out.width(indent);
00173 out<<""<<"LinearNoiseForce:";
00174 out.width(indent+2); out<<""; out<<"_random_seed"<<_random_seed<<" (class)\n";
00175 out.width(indent+2); out<<""; out<<"_initialized"<<_initialized<<" (class)\n";
00176 out.width(indent+2); out<<""; out<<"_gradient_table"<<_gradient_table<<" (class)\n";
00177 out.width(indent+2); out<<""; out<<"_prn_table"<<_prn_table<<" (class)\n";
00178 LinearRandomForce::write(out, indent+2);
00179 #endif //] NDEBUG
00180 }