POV-Ray : Newsgroups : povray.general : Problem with parameters : Problem with parameters Server Time
31 Jul 2024 00:28:02 EDT (-0400)
  Problem with parameters  
From: Martin
Date: 26 Feb 2008 20:07:14
Message: <47c4b7c2$1@news.povray.org>
Hello. First of all, i serched with google on this site without seeing 
any mention to my problem. So, apologies if i am repeating.

I have something wrong in the following code, but i cannot see it. It 
pretends to be a minimun sample, and its only purpose is to show the 
problem. It occurs in a bigger file that i'm working on. At first, i 
tried to isolate the error there, but it was impossible to me (i am not 
a programmer :). Finally i could find what seems to be wrong.

//pov version: 3.6.1c.icl8.win32
//-------------------------------------------------------------
default{ pigment{rgb <1,1,0>} }

//this is ok, for control purposes
#macro Wave_Ctrl(N,Fr,A,Fs,L)
   #local C=0;
   #while(C < N)
     sphere{z*L*C/N+y*A*sin(2*pi*Fr*C/N+Fs) 0.05 pigment{red 1}}
     #local C= C+1;
   #end
#end
//Here starts the problem
//let's say i need some macros with parameters passed both, per value 
//and reference
#macro WavePt(pZ,pY)
   DoCalc(pZ,pY,cC,+cN) sphere{z*pZ+y*pY 0.05 }
#end

#macro DoCalc(pZ,pY,I,N) //function arbitrarily choosen
   #local pY= y*cA*sin(2*pi*cFr*I/N+cFs);
   #local pZ= z*L*I/N;
#end
//
#macro WrongWave(cN,Fr,A,Fs,L)
   #local cA= A; #local cFr= Fr; #local cFs= Fs;
   #local cC=0; #local pY=0*y; #local pZ=0*z;
   #while(cC < cN) WavePt(pY,pZ) #local cC= cC+1; #end
#end

#declare cN= 500;
#declare Freq= 5; #declare Amp= 0.5; #declare Phase=0; #declare L=10;

//#debug "doesn't matter what\n" //(1)
#declare Ctrl= no;
#local I=0; #local T= 50; #local cRt= 360/T;
#while(I < T)
   union{
     #if(!Ctrl)
       WrongWave(cN,Freq,Amp,Phase,L)
     #else
       Wave_Ctrl(cN,Freq,Amp,Phase,L)
     #end
     rotate y*cRt*I
   }
   #local I=I+1;
#end

The problem: while in the Wave_Ctrl() macro all the spheres are placed 
correctly, in the WrongWave() one, that it's supposed to do the same, 
some spheres are out of place. At first i thought in a rounding error, 
but as i never have faced one, i don't know what it looks like :/.

But if it is a rounding error, why Wave_Ctrl is rendering properly? and 
Why typing a debug line affects the resulting image (with WrongWave())? 
Uncomment the line (1) and probably the wrong placed spheres will 
change. Anyway, here i am not adding  or performing further operations 
with the resulting calculations, the counter is integer...

Maybe the sample seems a bit silly, but this problem ruins a scene where 
the objects has been calculated previously in size and position.

Thank you very much in advance

Martin


Post a reply to this message

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