06-24-2008, 03:53 AM
|
#1 (permalink)
|
Model Moderator
User
Join Date: Nov 2004
Posts: 760
|
Interpolation Functions
I have shared with many these functions, but I had never posted them officially:
library Interpolation function Linear takes real a, real b, real t returns real return a + (b-a )*t endfunction// Bezier Interpolation: Bezier_[Point_number] function Bezier_3 takes real a, real b, real c, real t returns real return a + 2* (b-a )*t + (c -2*b + a )*t*t endfunction //Uses 3 points//You can use Bezier 3 to graphic perfect parabols function Bezier_4 takes real a, real b, real c, real d, real t returns real local real m = t*t return a + 3*t* (b - a ) + 3*m* (c - 2*b + a ) + m*t* (3* (b-c ) + d - a ) endfunction //Uses 4 points//Bezier_4(<Start Point>, <OutTan_of_StartPoint>, <InTan_of_EndPoint>, <EndPoint>) //Hermite Interpolation function Hermite takes real p1, real p2, real t1, real t2, real s returns real local real s2 = s*s local real h1 = 8.0*s*s2 - 9.0*s2 local real h2 = h1* (-1 ) local real h3 = s2* (s - 2.0 ) + s local real h4 = s2* (s - 1.0 ) set h1 = h1 + 1 return h1*p1 + h2*p2 + h3*t1 + h4*t2 endfunction//Hermite(<StartPoint>,<EndPoint>,<Tangent1>,<Tangent2>) function GetCardTan takes real p1, real p3 returns real return 0.5* (p3-p1 ) endfunction// TCB functions for finding the tangents among 3 points// Most modellers may know TCB from 3dsmax, in which they are used to make rotations// look very smooth.// t = tension, c = continuity, b = bias// tension is how sharply the curve makes turns.// continuity specifies the rate of change between speed and direction.// bias specifies the direction of the curve.// sidenote: specify p1 as 0, when working with 2 points.// the next function returns the intan of p2 function InTan takes real p1, real p2, real p3, real t, real c, real b returns real return (1.0-t )* (1.0-c )* (1.0+b )* (p2-p1 )/2 + (1.0-t )* (1.0+c )* (1.0-b )* (p3-p2 )/2 endfunction// the next function returns the outtan of p2 function OutTan takes real p1, real p2, real p3, real t, real c, real b returns real return (1.0-t )* (1.0+c )* (1.0+b )* (p2-p1 )/2 + (1.0-t )* (1.0-c )* (1.0-b )* (p3-p2 )/2 endfunction//These functions do conversions between 3dsmax TCB system and normal TCB//3dsmax's is a lot more linear and easier to edit than the others//Insert any value like tension, continuity or bias. function Max2TCB takes real value returns real return (value-25. )/25. endfunction function TCB2Max takes real value returns real return value*25. +25. endfunctionendlibrary
These famous functions are used by Blizzard and most game makers to interpolate among keys within models, in a very fast way.
Reminder All this functions should be use on Axis individually, which is good if you want to convine different interpolations. You can interpolate anything with these, from distances to accelerations.
|
|
|