POV-Ray : Newsgroups : povray.general : rand2d() define Server Time
6 Nov 2024 04:16:53 EST (-0500)
  rand2d() define (Message 1 to 2 of 2)  
From: Adam
Subject: rand2d() define
Date: 28 Aug 2004 06:20:15
Message: <41305c5f@news.povray.org>
Hi everyone,
	I'm trying to understand how the following define works (render.cpp):
#define rand2d(a, b) 
jitttab[(int)(hashTable[(int)(hashTable[(int)((a)&0xfff)]^(b))&0xfff])&0xff]

I got that jitttab is an array of 256 random float ranging from -0.5 to 0.5.

hashtable is an array of 8192 unsigned short, where the first 4096 
numbers are the the growing 0..4095 scattered randomly, and the last 
4096 are just the same:

   for (i = 0; i < 4096; i++)
   {
     hashTable[i] = i;
   }

   for (i = 4095; i >= 0; i--)
   {
     j = POV_RAND() % 4096;
     temp = hashTable[i];
     hashTable[i] = hashTable[j];
     hashTable[j] = temp;
   }

   for (i = 0; i < 4096; i++)
   {
     hashTable[4096 + i] = hashTable[i];
   }

My question is: what are the and and xor mask for?

Thanxs

Adam


Post a reply to this message

From: Wolfgang Wieser
Subject: Re: rand2d() define
Date: 29 Aug 2004 11:25:07
Message: <4131f552@news.povray.org>
Adam wrote:

> Hi everyone,
> I'm trying to understand how the following define works (render.cpp):
> #define rand2d(a, b)
> jitttab[(int)(hashTable[(int)(hashTable[(int)((a)&0xfff)]^(b))&0xfff])&0xff]
> [...]
>
(1) Please do cross-posting instead of multiposting. 
     [What is it? -> http://www.blakjak.demon.co.uk/mul_crss.htm]
(2) See p.programming.

Wolfgang


Post a reply to this message

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