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