POV-Ray : Newsgroups : povray.newusers : Problem with variables Server Time
27 Nov 2024 15:40:16 EST (-0500)
  Problem with variables (Message 1 to 6 of 6)  
From: Kaveh
Subject: Problem with variables
Date: 27 Oct 2002 07:11:43
Message: <1fkpnlf.dx0416mokegiN%kaveh@delete_this.focalimage.com>
Sorry if the subject to this posting is vague. I am not sure of the
technical term for what I am trying to do. Consider the following simple
file:

//==============================================
#declare Pigment = pigment{color rgb <1,1,1>}
#declare Ambient = 0;
#declare Diffuse = .2;
#declare Specular = .8;

sphere {
  0, 1
  pigment {Pigment}
  finish {
        ambient     Ambient
        diffuse     Diffuse
        specular    Specular
        }
       }
//==============================================

In order to get a better idea of the effect of each of this attributes,
I want to have a loop that produces a range of values of a selected
attribute. There is one place I am stuck in. I want to say something
like:

#declare variable = "Ambient";

at the beginning of the file, and the program would then use all the
other values given, but vary the value of Ambient, say 5 times, and draw
the 5 resulting spheres. 

The only way I have come up with so far is rather ugly. I would use:

#if (strcmp(variable, "Ambient") = 0)
...

But it is verbose, and also if I introduce a new variable, I have to
have a new conditional.  I really want variable to 'think' it is Ambient
from that point on.

Grateful for any hints.


-- 
Kaveh


Post a reply to this message

From: Johannes Dahlstrom
Subject: Re: Problem with variables
Date: 27 Oct 2002 08:04:24
Message: <3dbbe458@news.povray.org>
You could use an integer to represent the value you want to vary, like this:

#declare VaryAmbient = 1;
#declare VaryDiffuse = 2;
#declare VarySpecular = 3;

#declare WhichValueToVary = VaryAmbient;

#declare Variable = ... // Vary this

// ...
finish {
  ambient (WhichValueToVary == VaryAmbient) ? Variable : 0.1;
  diffuse (WhichValueToVary == VaryDiffuse) ? Variable : 0.6;
  specular (WhichValueToVary == VarySpecular) ? Variable : 1.0;
}
// ...


Post a reply to this message

From: Kaveh
Subject: Re: Problem with variables
Date: 27 Oct 2002 08:28:25
Message: <1fkprmu.h5llq52t5zpbN%kaveh@delete_this.focalimage.com>
Johannes Dahlstrom <sad### [at] tkukoulufi> wrote:

> You could use an integer to represent the value you want to vary, like this:
> 
> #declare VaryAmbient = 1;
> #declare VaryDiffuse = 2;
> #declare VarySpecular = 3;
> 
> #declare WhichValueToVary = VaryAmbient;
> 
> #declare Variable = ... // Vary this
> 
> // ...
> finish {
>   ambient (WhichValueToVary == VaryAmbient) ? Variable : 0.1;
>   diffuse (WhichValueToVary == VaryDiffuse) ? Variable : 0.6;
>   specular (WhichValueToVary == VarySpecular) ? Variable : 1.0;
> }
> // ...

Thanks Johannes. I haven't come across this construction, and can't find
it in the manual. Can you give me a hint as to where I can find more
information on this? 

-- 
Kaveh


Post a reply to this message

From: Johannes Dahlstrom
Subject: Re: Problem with variables
Date: 27 Oct 2002 08:55:18
Message: <3dbbf045@news.povray.org>
Kaveh wrote:

> Thanks Johannes. I haven't come across this construction, and can't find
> it in the manual. Can you give me a hint as to where I can find more
> information on this?
> 

You mean the ? : ternary operator? Basically, it works like a simple 
if/else construct:

 #if(<expression>) <do_this> #else <do_that> #end

is the same as:

 (<expression>) ? <do_this> : <do_that>

That is, if <expression> returns true, it executes the <do_this> part, 
otherwise the <do_that> part.

In the POV manual: 
6.1.3.3 Float Operators
http://www.povray.org/documentation/view/137/


Post a reply to this message

From: Kaveh
Subject: Re: Problem with variables
Date: 27 Oct 2002 09:55:23
Message: <1fkpvur.194ifw61yxczkeN%kaveh@delete_this.focalimage.com>
Johannes Dahlstrom <sad### [at] tkukoulufi> wrote:

> Kaveh wrote:
> 
> > Thanks Johannes. I haven't come across this construction, and can't find
> > it in the manual. Can you give me a hint as to where I can find more
> > information on this?
> > 
> 
> You mean the ? : ternary operator? Basically, it works like a simple 
> if/else construct:
> 
>  #if(<expression>) <do_this> #else <do_that> #end
> 
> is the same as:
> 
>  (<expression>) ? <do_this> : <do_that>
> 
> That is, if <expression> returns true, it executes the <do_this> part,
> otherwise the <do_that> part.
> 
> In the POV manual: 
> 6.1.3.3 Float Operators
> http://www.povray.org/documentation/view/137/

Got it. Except you had == which according to the manual should be =. I
did a search for == but couldn't find it. I would have guessed == too!

-- 
Kaveh


Post a reply to this message

From: Johannes Dahlstrom
Subject: Re: Problem with variables
Date: 27 Oct 2002 10:06:54
Message: <3dbc010e@news.povray.org>
Kaveh wrote:

> Got it. Except you had == which according to the manual should be =. I
> did a search for == but couldn't find it. I would have guessed == too!
> 

Oops, sorry... Too much C++ lately, I guess :)


Post a reply to this message

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