// Persistence of Vision Ray Tracer Macro Definition File // File: 8DInterp.inc // Vers: 3.1 // Desc: Interpolation routines for the 8th Day Macro Library. // Functions in this file based upon an artile on Perlin Noise at: // 'The Good-Looking Textured Light-Sourced Bouncy Fun Smart & Stretchy Page' // http://freespace.virgin.net/hugo.elias/ // Date: January, 2000 // Auth: Lonnie Ezell // Single Inclusion // this attempts to save parsing time by // limiting this file to being parsed only once // even when included in multiple files. #ifndef (ED_INTERP_INC) #declare ED_INTERP_INC = 1; //------------------------------ Includes ------------------------------// //------------------------------ Declarations --------------------------// //------------------------------ Macros --------------------------------// // Linear Interpolation // Used for the fastest interpolation, however, results // may be less than desired. // // REQUIRES: a - first of the numbers to be interpolated between (float) // b - second of the numbers to be interpolated between (float) // m_x - the ratio to base our interp on. If m_x=0, returns a // If m_x=1 returns b (float between 0 and 1) // // RETURNS: a number between v1 and v2 based upon m_x #macro ED_LinearInterpolate(a, b, m_x) ( a * (1 - m_x) + b * m_x ) #end // ED_LinearInterpolate // Cosine Interpolation // Used for a compromise between speed and results. // // REQUIRES: see Linear Interpolation // // RETURNS: a number between v1 and v2 based upon m_x #macro ED_CosineInterpolate(a, b, m_x) #local ft = m_x * 3.1415927; #local f = (1 - cos(ft)) * 0.5; ( a * (1 - f) + b * f ) #end // ED_CosineInterpolate // Cubic Interpolation // Provides the best results, though no guarantee they // will be all that much better than Cosine Interpolation // // REQUIRES: v0 - the point before a (float) // v1 - the point a (float) // v2 - the point b (float) // v3 - the point after b (float) // m_x - see Linear Interpolate (float between 0 and 1) // // RETURNS: a number between v1 and v2 based upon m_x #macro ED_CubicInterpolate(v0, v1, v2, v3, m_x) #local P = (v3 - v2) - (v0 - v1); #local Q = (v0 - v1) - P; #local R = v2 - v0; ( (P * pow(m_x, 3)) + (Q * pow(m_x,2)) + (R * X) + v1 ) #end // ED_CubicInterpolate #end // Single Inclusion Block