Panda3D
|
00001 // Filename: linearNoiseForce.I 00002 // Created by: charles (19Jun00) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 //////////////////////////////////////////////////////////////////// 00016 // Function : prn_lookup 00017 // Access : Private 00018 // Description : Returns a valid entry in the prn table 00019 //////////////////////////////////////////////////////////////////// 00020 INLINE unsigned char LinearNoiseForce:: 00021 prn_lookup(int index) const { 00022 return _prn_table[index & 255]; 00023 } 00024 00025 //////////////////////////////////////////////////////////////////// 00026 // Function : get_prn_entry 00027 // Access : Private 00028 // Description : Hashes a point, returns a prn 00029 //////////////////////////////////////////////////////////////////// 00030 INLINE unsigned char LinearNoiseForce:: 00031 get_prn_entry(const LPoint3& point) const { 00032 return prn_lookup((int)(point[0] + prn_lookup((int)(point[1] + prn_lookup((int)point[2]))))); 00033 } 00034 00035 //////////////////////////////////////////////////////////////////// 00036 // Function : get_prn_entry 00037 // Access : Private 00038 // Description : Hashes a point, returns a prn (piecewise) 00039 //////////////////////////////////////////////////////////////////// 00040 INLINE unsigned char LinearNoiseForce:: 00041 get_prn_entry(const PN_stdfloat x, const PN_stdfloat y, const PN_stdfloat z) const { 00042 return prn_lookup((int)(x + prn_lookup((int)(y + prn_lookup((int)z))))); 00043 } 00044 00045 //////////////////////////////////////////////////////////////////// 00046 // Function : get_lattice_entry 00047 // Access : Private 00048 // Description : Hashes a point, returns a gradient vector 00049 //////////////////////////////////////////////////////////////////// 00050 INLINE LVector3& LinearNoiseForce:: 00051 get_lattice_entry(const LPoint3& point) { 00052 return _gradient_table[get_prn_entry(point)]; 00053 } 00054 00055 //////////////////////////////////////////////////////////////////// 00056 // Function : get_lattice_entry 00057 // Access : Private 00058 // Description : Hashes a point, returns a gradient vector (piecewise) 00059 //////////////////////////////////////////////////////////////////// 00060 INLINE LVector3& LinearNoiseForce:: 00061 get_lattice_entry(const PN_stdfloat x, const PN_stdfloat y, const PN_stdfloat z) { 00062 return _gradient_table[get_prn_entry(x, y, z)]; 00063 } 00064 00065 //////////////////////////////////////////////////////////////////// 00066 // Function : cubic_step 00067 // Access : Private 00068 // Description : Smooths a parameterized interpolation using 00069 // 2x^3 - 3x^2 00070 //////////////////////////////////////////////////////////////////// 00071 INLINE PN_stdfloat LinearNoiseForce:: 00072 cubic_step(const PN_stdfloat x) const { 00073 return x * x * ((2 * x) - 3); 00074 } 00075 00076 //////////////////////////////////////////////////////////////////// 00077 // Function : vlerp 00078 // Access : Private 00079 // Description : Vector linear interpolation 00080 //////////////////////////////////////////////////////////////////// 00081 INLINE LVector3 LinearNoiseForce:: 00082 vlerp(const PN_stdfloat t, const LVector3& v0, const LVector3& v1) const { 00083 return v0 + ((v1 - v0) * t); 00084 }