POV-Ray : Newsgroups : povray.general : concat for variable identifier? Server Time
7 Nov 2024 11:33:35 EST (-0500)
  concat for variable identifier? (Message 1 to 5 of 5)  
From: Sebastian H 
Subject: concat for variable identifier?
Date: 3 Mar 2002 11:27:59
Message: <3C824F76.6050806@web.de>
Hi there
I got a question over here.

I got a database like this:

.
.
.
upper_axis = <x, y, z>;
upper_angle = a;
upper_pos = <x, y, z>

head_axis = <x, y, z>;
head_angle = a;
head_pos = <x,y,z>
.
.
.

Now I try to write a macro which only takes the argument "head" or "upper":

#macro (OBJ)
.
.
.
#end

Inside the macro should have access to OBJ_axis or OBJ_angle so I need a 
  function like *concat (OBJ, "_axis")* that does not return a string 
but the variable identifier.

Is this anyhow possible in POV?

Sebastian H.


Post a reply to this message

From: Christoph Hormann
Subject: Re: concat for variable identifier?
Date: 3 Mar 2002 11:43:49
Message: <3C8252C0.A15339EA@gmx.de>
"Sebastian H." wrote:
> 
> [...]
> 
> Inside the macro should have access to OBJ_axis or OBJ_angle so I need a
>   function like *concat (OBJ, "_axis")* that does not return a string
> but the variable identifier.
> 
> Is this anyhow possible in POV?
> 

Two possibilities:

- use arrays for your data instead of single variables
- use the Parse_String() macro (Povray 3.5, strings.inc)

Christoph

-- 
POV-Ray tutorials, IsoWood include,                 
TransSkin and more: http://www.tu-bs.de/~y0013390/  
Last updated 21 Feb. 2002 _____./\/^>_*_<^\/\.______


Post a reply to this message

From: Sebastian H 
Subject: Re: concat for variable identifier?
Date: 3 Mar 2002 11:55:05
Message: <3C8255D1.1050807@web.de>
> Two possibilities:
> 
> - use arrays for your data instead of single variables
> - use the Parse_String() macro (Povray 3.5, strings.inc)
> 
> Christoph


This macro does the job but it is *really* brute force :-))
I will look if I can use arrays...

Thanks
Sebastian


Post a reply to this message

From: bob h
Subject: Re: concat for variable identifier?
Date: 3 Mar 2002 12:55:26
Message: <3c82638e@news.povray.org>
Not sure how parsing of a declared string helps.  :-)

I was thinking you could test for the first letter of the identifiers, but
they would need to be declared or read in somehow.  array maybe, like
Christoph suggests.  Unfortunately, only way I know of is substr(ABC,1,1)
but no way to #if #else it since the string isn't possible as a conditional.
Unless you added numbers to the identifiers and used it via val().
There's also strlen() for getting a number of letters the identifier has,
instead.  Those could be used conditionally then.

In any case it might not be an extremely simple process.  If so I can't
think of it.  You still have to test for each identifier in some repetitive
way.

bob h


Post a reply to this message

From: Sebastian H 
Subject: Re: concat for variable identifier?
Date: 3 Mar 2002 16:21:55
Message: <3C82945A.7010109@web.de>
I took a look at theses functions too but the only one that does it was 
the macro Christoph Hormann suggested.


The problem comes from here:

Im writing a model converter for the .md3 format (some games use it).

Since each file contains several Meshframes I store each frame in a 
single file which is included by a macro

#macro MODELNAME_load_frame (frame)
...
#end

The vertex vectors for example are stored in an array (as the normals too)

#declare MODELNAME_vv = array[xxx] {
...
}

Now I tried to write a macro that puts spheres on every vertex (for 
testing and for coolness :-) ).

And here's the same problem I can't access the MODELNAME_vv array just 
by giving a macro just the modelname and I don't want to write the same 
macro for every model.

Using the parse_string macro could give something like that:

#declare num = 1; // Or so doesn't matter
#declare Vec =
parse_string ( concat (MODELNAME, "_vv[", str (num, 0, 0), "];") )

I didn't tried it but that should work.

Sebastian H.

P.S.: Hmm I should try it!


Post a reply to this message

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