POV-Ray : Newsgroups : povray.general : A few useful macros : A few useful macros Server Time
12 Aug 2024 23:25:11 EDT (-0400)
  A few useful macros  
From: Margus Ramst
Date: 10 Dec 1998 06:54:27
Message: <01be2433$5a4ed380$7c01a8c0@b14.sise.ebs>
Here are some little macros that have recently saved me a lot of typing. I
also submitted them to Twyst's #MacroScope (and I recommend you send your
macros there, too)
I hope you'll find these useful

Improved interpolation function
GC - global current
GS - global start
GE - global end
TS - target start
TE - target end
EXP - interpolation exponent (linear, cubic etc.)

#macro Interpolate(GC,GS,GE,TS,TE,EXP)
        (TS+(TE-TS)*pow((GC-GS)/(GE-GS),EXP))
#end

Vector debug, saves a lot of typin when generating debug streams for 3D
vectors
Requires the vector identifier

#macro v_debug(V)
concat("<",str(V.x,0,3),",",str(V.y,0,3),",",str(V.z,0,3),">")
#end

Put point at the axis defined by P1 and P2, at a specified distance from
P2; negative distance values move the point from P2 towards P1
P1 - start point
P2 - end point
Dist - distance from P2

#macro v_lineup(P1,P2,Dist)
        (P2+vnormalize(P2-P1)*Dist)
#end

Creates random number of given mean and maximum deviation, for example
rand_ext(1,0.2,Seed) gives a random number between 0.8 and 1.2
M - mean value
D - maximum deviation
Seed - (previously declared) random number seed identifier

#macro rand_ext(M,D,Seed)
        (M+(rand(Seed)-.5)*2*D)
#end


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.