|
|
Reuben Pearse wrote:
>
> I have created a macro to create an object. I now want to randomly place the
> object in my scene (within specified boundaries!!)
> How do I get POVRay to generate random numbers?
>
First you have to declare a random number seed, like this:
#declare RandSeed = seed(N); //N is a random integer of your choice
The you can call the rand() function, with the name of the seed identifier as
the parameter, for examle like this:
#declare RandomValue=rand(RandSeed);
Each time you call rand(RandSeed) a different (pseudo)random value is returned
from the stream initialized by RandSeed.
For creating random numbers of a given mean value and maximum deviation, you can
try these macros (the first returns a float, the second depends on the first and
returns a 3D vector):
//Create random number of given mean and maximum deviation
//M - mean value
//D - maximum deviation
//Seed - (declared) random number seed identifier
#macro rand_ext(M,D,Seed)
(M+(rand(Seed)-.5)*2*D)
#end
//Give a random vector of given mean and max deviation
//M - mean (vector or float)
//D - max deviation (vector or float)
//Seed - (declared) random number seed identifier
#macro v_rand_ext(M,D,Seed)
#local MV=M+<0,0,0>;
#local DV=D+<0,0,0>;
(<rand_ext(MV.x,DV.x,Seed),
rand_ext(MV.y,DV.y,Seed),
rand_ext(MV.z,DV.z,Seed)>)
#end
--
Margus Ramst
Personal e-mail: mar### [at] peakeduee
TAG (Team Assistance Group) e-mail: mar### [at] tagpovrayorg
Home page http://www.hot.ee/margusrt
Post a reply to this message
|
|