18 #include "linearNoiseForce.h" 23 (
"default_noise_force_seed", 665);
25 bool LinearNoiseForce::_initialized =
false;
26 unsigned char LinearNoiseForce::_prn_table[256];
27 LVector3 LinearNoiseForce::_gradient_table[256];
44 for (
int i = 0; i < 256; ++i) {
46 _prn_table[i] = rand() & 255;
49 *gtable++ = random_unit_vector();
61 if (_initialized ==
false) {
107 int int_x, int_y, int_z;
108 PN_stdfloat frac_x, frac_y, frac_z;
111 frac_x = p[0] - int_x;
114 frac_y = p[1] - int_y;
117 frac_z = p[2] - int_z;
120 PN_stdfloat cubic_x, cubic_y, cubic_z;
122 cubic_x = cubic_step(frac_x);
123 cubic_y = cubic_step(frac_y);
124 cubic_z = cubic_step(frac_z);
127 LVector3 temp0, temp1, temp2, temp3;
130 temp0 = vlerp(cubic_x, get_lattice_entry(p),
131 get_lattice_entry(p[0] + 1.0f, p[1], p[2]));
133 temp1 = vlerp(cubic_x, get_lattice_entry(p[0], p[1], p[2] + 1.0f),
134 get_lattice_entry(p[0] + 1.0f, p[1], p[2] + 1.0f));
136 temp2 = vlerp(cubic_x, get_lattice_entry(p[0], p[1] + 1.0f, p[2]),
137 get_lattice_entry(p[0] + 1.0f, p[1] + 1.0f, p[2]));
139 temp3 = vlerp(cubic_x, get_lattice_entry(p[0], p[1] + 1.0f, p[2] + 1.0f),
140 get_lattice_entry(p[0] + 1.0f, p[1] + 1.0f, p[2] + 1.0f));
143 temp0 = vlerp(cubic_z, temp0, temp1);
144 temp1 = vlerp(cubic_z, temp2, temp3);
147 return vlerp(cubic_y, temp0, temp1);
159 out<<
""<<
"LinearNoiseForce";
170 write(ostream &out,
unsigned int indent)
const {
173 out<<
""<<
"LinearNoiseForce:";
174 out.width(indent+2); out<<
""; out<<
"_random_seed"<<_random_seed<<
" (class)\n";
175 out.width(indent+2); out<<
""; out<<
"_initialized"<<_initialized<<
" (class)\n";
176 out.width(indent+2); out<<
""; out<<
"_gradient_table"<<_gradient_table<<
" (class)\n";
177 out.width(indent+2); out<<
""; out<<
"_prn_table"<<_prn_table<<
" (class)\n";
virtual void output(ostream &out) const
Write a string representation of this instance to <out>.
virtual ~LinearNoiseForce()
destructor
virtual void write(ostream &out, unsigned int indent=0) const
Write a string representation of this instance to <out>.
Pure virtual, parent to noiseForce and jitterForce.
LinearNoiseForce(PN_stdfloat a=1.0f, bool m=false)
constructor
A body on which physics will be applied.
This is a three-component vector distance (as opposed to a three-component point, which represents a ...
virtual void write(ostream &out, unsigned int indent=0) const
Write a string representation of this instance to <out>.
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
A force that acts on a PhysicsObject by way of an Integrator.
Repeating noise force vector.
static void init_noise_tables()
One-time config function, sets up the PRN lattice.
LPoint3 get_position() const
Position Query.
This is a convenience class to specialize ConfigVariable as an integer type.
TypeHandle is the identifier used to differentiate C++ class types.