00001 // Filename: linearNoiseForce.I 00002 // Created by: charles (19Jun00) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved 00008 // 00009 // All use of this software is subject to the terms of the Panda 3d 00010 // Software license. You should have received a copy of this license 00011 // along with this source code; you will also find a current copy of 00012 // the license at http://www.panda3d.org/license.txt . 00013 // 00014 // To contact the maintainers of this program write to 00015 // panda3d@yahoogroups.com . 00016 // 00017 //////////////////////////////////////////////////////////////////// 00018 00019 //////////////////////////////////////////////////////////////////// 00020 // Function : prn_lookup 00021 // Access : Private 00022 // Description : Returns a valid entry in the prn table 00023 //////////////////////////////////////////////////////////////////// 00024 INLINE unsigned char LinearNoiseForce:: 00025 prn_lookup(int index) const { 00026 return _prn_table[index & 255]; 00027 } 00028 00029 //////////////////////////////////////////////////////////////////// 00030 // Function : get_prn_entry 00031 // Access : Private 00032 // Description : Hashes a point, returns a prn 00033 //////////////////////////////////////////////////////////////////// 00034 INLINE unsigned char LinearNoiseForce:: 00035 get_prn_entry(const LPoint3f& point) const { 00036 return prn_lookup((int)(point[0] + prn_lookup((int)(point[1] + prn_lookup((int)point[2]))))); 00037 } 00038 00039 //////////////////////////////////////////////////////////////////// 00040 // Function : get_prn_entry 00041 // Access : Private 00042 // Description : Hashes a point, returns a prn (piecewise) 00043 //////////////////////////////////////////////////////////////////// 00044 INLINE unsigned char LinearNoiseForce:: 00045 get_prn_entry(const float x, const float y, const float z) const { 00046 return prn_lookup((int)(x + prn_lookup((int)(y + prn_lookup((int)z))))); 00047 } 00048 00049 //////////////////////////////////////////////////////////////////// 00050 // Function : get_lattice_entry 00051 // Access : Private 00052 // Description : Hashes a point, returns a gradient vector 00053 //////////////////////////////////////////////////////////////////// 00054 INLINE LVector3f& LinearNoiseForce:: 00055 get_lattice_entry(const LPoint3f& point) { 00056 return _gradient_table[get_prn_entry(point)]; 00057 } 00058 00059 //////////////////////////////////////////////////////////////////// 00060 // Function : get_lattice_entry 00061 // Access : Private 00062 // Description : Hashes a point, returns a gradient vector (piecewise) 00063 //////////////////////////////////////////////////////////////////// 00064 INLINE LVector3f& LinearNoiseForce:: 00065 get_lattice_entry(const float x, const float y, const float z) { 00066 return _gradient_table[get_prn_entry(x, y, z)]; 00067 } 00068 00069 //////////////////////////////////////////////////////////////////// 00070 // Function : cubic_step 00071 // Access : Private 00072 // Description : Smooths a parameterized interpolation using 00073 // 2x^3 - 3x^2 00074 //////////////////////////////////////////////////////////////////// 00075 INLINE float LinearNoiseForce:: 00076 cubic_step(const float x) const { 00077 return x * x * ((2 * x) - 3); 00078 } 00079 00080 //////////////////////////////////////////////////////////////////// 00081 // Function : vlerp 00082 // Access : Private 00083 // Description : Vector linear interpolation 00084 //////////////////////////////////////////////////////////////////// 00085 INLINE LVector3f LinearNoiseForce:: 00086 vlerp(const float t, const LVector3f& v0, const LVector3f& v1) const { 00087 return v0 + ((v1 - v0) * t); 00088 }