|
|
Some years ago, I read documentation about Random number generation in the C++
Language, in particular the new C++11 (the 2011 revision of C++ for those not
familiar with this language) language revision with, new types that allow a more
convenient random number generation. A example sometimes being more meaningful,
consider this code excerpt written in C++:
----
constexpr long unsigned SEED = 1234;
std::mt19937 mersenne{ SEED };
std::uniform_int_distribution<int> integers{ 0, 20 };
----
Here, we create a generator for number starting at 0 and ending at 20 (20 being
included). Very straightforward indeed ! I'd like to see this feature in future
versions of POVRay in the SDL this time. Since POVRay is written in C++ that
might not be that hard to implement. For instance, unless I missed something,
generating pseudo random numbers, is less convenient while being not so
complicated (and if you need Random number from 0 to 1 only that even is a piece
of cake).
One handy solution I use so far for my needs is the following macro in POVRay
SDL:
----
#macro AffineSet( PointA, PointB, CurrentX )
#if( PointA.x = PointB.x )
#error "Can't render, because both x coordinates have equal values"
#end
#local DirCoef = (PointB.y - PointA.y) / ( PointB.x - PointA.x );
#local OriginOffset = PointA.y - (DirCoef * PointA.x);
(DirCoef * CurrentX) + OriginOffset;
#end
----
This macro returns the Y coordinates of a point in the given interval of point A
and B while taking care of A and B not having the same x axis coordinates.
Post a reply to this message
|
|