POV-Ray : Newsgroups : povray.general : simple syntax question Server Time
4 Nov 2024 17:32:19 EST (-0500)
  simple syntax question (Message 1 to 6 of 6)  
From: D  Stimits
Subject: simple syntax question
Date: 11 Dec 2003 15:47:14
Message: <3fd8d7d2@news.povray.org>
I'm very new to POVray, and using version 3.5 on Linux. In general, I'm 
a C and C++ programmer, and am trying to do something in POVray that 
would be a simple procedural call in C.

I'm creating a scene of a set of nodes and paths between nodes for 
creation of a picture something like the "traveling salesman" problem. A 
path is traced through a series of locations (nodes) on given paths 
(edges), finding the minimum path that visits each node exactly once. It 
looks something like a 3D chess board with selected edges being placed 
between squares, and some squares missing.

I want to declare a global variable:
#declare Node_Center = < 0.0, 0.0, 0.0 >;

And then prior to calling a macro inside of an object {} that renders a 
node icon based on location of Node_Center, I want to call another macro 
(such as "Translate_Left") that alters the value of Node_Center in one 
direction (partially desired because of different handedness of POVray 
axis and the input data axis), taking into account a scale. The problem 
is I cannot seem to find a way to actually alter the content of 
Node_Center that is not an error. I have to alter the value of 
Node_Center before calling:

object {
   Render_Node (Node_Center)
}

Then the outside application can write the scene file based on something 
like a series of:

Translate_Left ()
object {
   Render_Node (Node_Center)
}

Translate_Up ()
object {
   Render_Node (Node_Center)
}

The application itself then merely knows to go left, right, up, or down, 
and does not have to keep track of Node_Center, nor does the application 
need to understand the difference in axis handedness or scaling between 
data and POVray. Is it even possible to alter a global declaration like 
this from outside of the object? If I can only do this from inside of an 
object, how can I alter my global value prior to rendering the node's icon?


Post a reply to this message

From: Mike Williams
Subject: Re: simple syntax question
Date: 12 Dec 2003 00:40:42
Message: <$LF3+EANSV2$Ewj0@econym.demon.co.uk>
Wasn't it D. Stimits who wrote:
>I'm very new to POVray, and using version 3.5 on Linux. In general, I'm 
>a C and C++ programmer, and am trying to do something in POVray that 
>would be a simple procedural call in C.
>
>I'm creating a scene of a set of nodes and paths between nodes for 
>creation of a picture something like the "traveling salesman" problem. A 
>path is traced through a series of locations (nodes) on given paths 
>(edges), finding the minimum path that visits each node exactly once. It 
>looks something like a 3D chess board with selected edges being placed 
>between squares, and some squares missing.
>
>I want to declare a global variable:
>#declare Node_Center = < 0.0, 0.0, 0.0 >;
>
>And then prior to calling a macro inside of an object {} that renders a 
>node icon based on location of Node_Center, I want to call another macro 
>(such as "Translate_Left") that alters the value of Node_Center in one 
>direction (partially desired because of different handedness of POVray 
>axis and the input data axis), taking into account a scale. The problem 
>is I cannot seem to find a way to actually alter the content of 
>Node_Center that is not an error. I have to alter the value of 
>Node_Center before calling:
>
>object {
>   Render_Node (Node_Center)
>}
>
>Then the outside application can write the scene file based on something 
>like a series of:
>
>Translate_Left ()
>object {
>   Render_Node (Node_Center)
>}
>
>Translate_Up ()
>object {
>   Render_Node (Node_Center)
>}
>
>The application itself then merely knows to go left, right, up, or down, 
>and does not have to keep track of Node_Center, nor does the application 
>need to understand the difference in axis handedness or scaling between 
>data and POVray. Is it even possible to alter a global declaration like 
>this from outside of the object? If I can only do this from inside of an 
>object, how can I alter my global value prior to rendering the node's icon?
>

I would have thought that the following syntax would work. What errors
are you getting?

#macro Translate_Left()
  #declare Node_Center = Node_Center - x;
#end

#macro Translate_Up()
  #declare Node_Center = Node_Center +y;
#end

-- 
Mike Williams
Gentleman of Leisure


Post a reply to this message

From: D  Stimits
Subject: Re: simple syntax question
Date: 12 Dec 2003 07:31:38
Message: <3fd9b52a@news.povray.org>
Mike Williams wrote:

> Wasn't it D. Stimits who wrote:
>
> >I'm very new to POVray, and using version 3.5 on Linux. In general, I'm
> >a C and C++ programmer, and am trying to do something in POVray that
> >would be a simple procedural call in C.
> >
> >I'm creating a scene of a set of nodes and paths between nodes for
> >creation of a picture something like the "traveling salesman" problem. A
> >path is traced through a series of locations (nodes) on given paths
> >(edges), finding the minimum path that visits each node exactly once. It
> >looks something like a 3D chess board with selected edges being placed
> >between squares, and some squares missing.
> >
> >I want to declare a global variable:
> >#declare Node_Center = < 0.0, 0.0, 0.0 >;
> >
> >And then prior to calling a macro inside of an object {} that renders a
> >node icon based on location of Node_Center, I want to call another macro
> >(such as "Translate_Left") that alters the value of Node_Center in one
> >direction (partially desired because of different handedness of POVray
> >axis and the input data axis), taking into account a scale. The problem
> >is I cannot seem to find a way to actually alter the content of
> >Node_Center that is not an error. I have to alter the value of
> >Node_Center before calling:
> >
> >object {
> >  Render_Node (Node_Center)
> >}
> >
> >Then the outside application can write the scene file based on something
> >like a series of:
> >
> >Translate_Left ()
> >object {
> >  Render_Node (Node_Center)
> >}
> >
> >Translate_Up ()
> >object {
> >  Render_Node (Node_Center)
> >}
> >
> >The application itself then merely knows to go left, right, up, or down,
> >and does not have to keep track of Node_Center, nor does the application
> >need to understand the difference in axis handedness or scaling between
> >data and POVray. Is it even possible to alter a global declaration like
> >this from outside of the object? If I can only do this from inside of an
> >object, how can I alter my global value prior to rendering the node's 
> icon?
> >
>
>
> I would have thought that the following syntax would work. What errors
> are you getting?
>
> #macro Translate_Left()
>   #declare Node_Center = Node_Center - x;
> #end
>
> #macro Translate_Up()
>   #declare Node_Center = Node_Center +y;
> #end
>
This works. Prior to this I made the mistake of not using declare after 
the variable was declared, a bit of a C-ism. But since it is really a 
macro expansion, it isn't a lot like C, the use of declare each and 
every modification of Node_Center does the job :)


Post a reply to this message

From: Christopher James Huff
Subject: Re: simple syntax question
Date: 12 Dec 2003 19:53:04
Message: <cjameshuff-1F15EF.19484412122003@netplex.aussie.org>
In article <3fd9b52a@news.povray.org>,
 "D. Stimits" <nos### [at] comcastnet> wrote:

> This works. Prior to this I made the mistake of not using declare after 
> the variable was declared, a bit of a C-ism. But since it is really a 
> macro expansion, it isn't a lot like C, the use of declare each and 
> every modification of Node_Center does the job :)

It sounds like you have a misunderstanding here. The #declare statement 
is not a macro declaration. It declares an actual variable. After 
"#declare A = 2+2;", "A" is a variable containing the value 4, not a 
macro expanding to the string "2+2".
For modifying variables, the #declare or #local is necessary. This is 
just a syntax issue, and has nothing to do with macros. (In MegaPOV, 
there is a #set keyword specifically for modifying existing variables 
without the possibility of accidentally creating a new one.)

-- 
Christopher James Huff <cja### [at] earthlinknet>
http://home.earthlink.net/~cjameshuff/
POV-Ray TAG: chr### [at] tagpovrayorg
http://tag.povray.org/


Post a reply to this message

From: D  Stimits
Subject: Re: simple syntax question
Date: 14 Dec 2003 17:30:30
Message: <3fdce486$1@news.povray.org>
Christopher James Huff wrote:

> In article <3fd9b52a@news.povray.org>,
>  "D. Stimits"  wrote:
>
>
> >This works. Prior to this I made the mistake of not using declare after
> >the variable was declared, a bit of a C-ism. But since it is really a
> >macro expansion, it isn't a lot like C, the use of declare each and
> >every modification of Node_Center does the job :)
>
>
> It sounds like you have a misunderstanding here. The #declare statement
> is not a macro declaration. It declares an actual variable. After
> "#declare A = 2+2;", "A" is a variable containing the value 4, not a
> macro expanding to the string "2+2".

Yes, you are correct, it was my C'ish background that the #declare style 
would be a macro.

>
> For modifying variables, the #declare or #local is necessary. This is
> just a syntax issue, and has nothing to do with macros. (In MegaPOV,
> there is a #set keyword specifically for modifying existing variables
> without the possibility of accidentally creating a new one.)


Not familiar with MegaPOV. However, this is where it again becomes 
non-intuitive for C/C++ background...there is no need in those languages 
to use something like #declare twice. This is why I called it a macro, 
that I have to use #declare to essentially redeclare the same thing with 
a new value. Even though it is a true variable, it seems I have to 
essentially redefine it each change, which was hanging me up.


Post a reply to this message

From: Christopher James Huff
Subject: Re: simple syntax question
Date: 15 Dec 2003 17:21:27
Message: <cjameshuff-9F18A3.17212915122003@netplex.aussie.org>
In article <3fdce486$1@news.povray.org>,
 "D. Stimits" <nos### [at] comcastnet> wrote:

> Not familiar with MegaPOV. However, this is where it again becomes 
> non-intuitive for C/C++ background...there is no need in those languages 
> to use something like #declare twice. This is why I called it a macro, 
> that I have to use #declare to essentially redeclare the same thing with 
> a new value. Even though it is a true variable, it seems I have to 
> essentially redefine it each change, which was hanging me up.

Maybe you have some misconception of what a macro is. This is simply the 
syntax POV uses...as you said, you have to redeclare a variable to 
modify it. This is unrelated to whether it is a macro or not. It is a 
variable, meaning a value of a specific type referred to by name. If you 
assign 2*2 - 1 to a variable, that variable has the *value* 3, and knows 
nothing about how you specified it.

A macro is an entirely different construct. Macros operate by text 
substitution, modifying the actual code while its being parsed. When the 
macro identifier is used in the scene, its contents replace its 
identifier at the location of its use. If you gave a macro the 
expression 2*2 - 1, its data would consist of that expression. The 
expansion of that macro would then give exactly "2*2 - 1".

-- 
Christopher James Huff <cja### [at] earthlinknet>
http://home.earthlink.net/~cjameshuff/
POV-Ray TAG: chr### [at] tagpovrayorg
http://tag.povray.org/


Post a reply to this message

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