POV-Ray : Newsgroups : povray.advanced-users : testing if a provided string matches strings in array : testing if a provided string matches strings in array Server Time
1 Jul 2024 05:36:06 EDT (-0400)
  testing if a provided string matches strings in array  
From: Kene
Date: 30 Sep 2009 04:25:00
Message: <web.4ac31453c0c633cf772dd76f0@news.povray.org>
I have been trying to build a macro that will help place a povray object using a
relative coordinate system. My idea is to support 3 types of objects namely
Cylinder, box and sphere. Each of these will use 3 arrays. 1 to save the
objects, 2 to save their current coordinates and 3 to save an id. Each object
has a specified format and a predictable number of vectors. Using their id in
the id array the macro should be able to determine the coordinates for each
object from the corresponding Coordinates and Objects arrays.

I have implemented this for the cylinder object i.e. creation of the cylinder
and capturing the object, coordinates and id. I plan next to have a micro that
can locate and place the cylinder in the scene and another micro that can locate
it and put it in reference to another object in the scene.

My problem is that I cannot seem to wrap my mind around testing for the cylinder
id in the Cylinder_Id array. Can somebody help me out here? I have included the
code so far. Any help will be appreciated.

Kene

----------------------
#include "colors.inc"
#include "arrays.inc"

/*+++++++++++++++ Fundamental declarations ++++++++++++++*/
#declare Floor_Surface = 0;

/*+++++++++++++++ Capturing Cylinders +++++++++++++++*/
#declare Cylinder_Loc = 7; //parameters for cylinder location properties
#declare Cylinder_Loc_I = 0; //count for adding cylinder location parameters
#declare Cylinder_Num = 1; //count for incrementing stored cylinder index
#declare Cylinder_Num_I = 0; //count for incrementing stored cylinder index
#declare Cylinder_Id = 1; //count for incrementing stored cylinder index
#declare Cylinder_Id_I = 0; //count for incrementing stored cylinder index
#declare Cylinder_Objects = array[ Cylinder_Num ] //holding cylinder objects
#declare Cylinder_Objects_Loc = array[ Cylinder_Loc ] //holding properties
#declare Cylinder_Objects_Id = array[ Cylinder_Id ] //holding id

//saving cylinder object
#macro Cylinder_Num_Incr()
  #declare Cylinder_Num_I = Cylinder_Num_I + 1;
#end

#macro Save_Cylinder( Object )
  #declare Cylinder_Objects[ Cylinder_Num_I ] = Object;
  Cylinder_Num_Incr()
  #declare Cylinder_Num = Cylinder_Num + Cylinder_Num_I;
  Resize_Array( Cylinder_Objects, Cylinder_Num )
#end

//saving cylinder location
#macro Cylinder_Loc_Incr()
  #declare Cylinder_Loc_I = Cylinder_Loc_I + 1;
#end

#macro Save_Cylinder_Loc( X1, Y1, Z1, X2, Y2, Z2, Radius )
  #declare Cylinder_Objects_Loc[ Cylinder_Loc_I ] = X1;
  Cylinder_Loc_Incr()
  #declare Cylinder_Objects_Loc[ Cylinder_Loc_I ] = Y1;
  Cylinder_Loc_Incr()
  #declare Cylinder_Objects_Loc[ Cylinder_Loc_I ] = Z1;
  Cylinder_Loc_Incr()
  #declare Cylinder_Objects_Loc[ Cylinder_Loc_I ] = X2;
  Cylinder_Loc_Incr()
  #declare Cylinder_Objects_Loc[ Cylinder_Loc_I ] = Y2;
  Cylinder_Loc_Incr()
  #declare Cylinder_Objects_Loc[ Cylinder_Loc_I ] = Z2;
  Cylinder_Loc_Incr()
  #declare Cylinder_Objects_Loc[ Cylinder_Loc_I ] = Radius;
  Cylinder_Loc_Incr()
  #declare Cylinder_Loc = Cylinder_Loc + Cylinder_Loc_I;
  Resize_Array( Cylinder_Objects_Loc, Cylinder_Loc )
#end

//saving cylinder id
#macro Cylinder_Id_Incr()
  #declare Cylinder_Id_I = Cylinder_Id_I + 1;
#end

#macro Save_Cylinder_Id( Object_Name )
  #declare Cylinder_Objects_Id[ Cylinder_Id_I ] = "Object_Name";
  Cylinder_Id_Incr()
/*  #declare Cylinder_Objects_Id[ Cylinder_Id_I ] = "Object_Description";
  Cylinder_Id_Incr()*/
  #declare Cylinder_Id = Cylinder_Id + Cylinder_Id_I;
  Resize_Array( Cylinder_Objects_Id, Cylinder_Id )
#end

/*+++++++++++++++ building a Cylinder ++++++++++++++++*/
#macro Make_Cylinder( Name, Radius, Height )
  #local Base_PointX = 0;                //x value at base of cylinder
  #local Base_PointY = Floor_Surface;    //y value at base of cylinder
  #local Base_PointZ = 0;                //z value at base of cylinder
  #local Cap_PointX = 0;                 //x value at top of cylinder
  #local Cap_PointY = Base_PointY + Height; //y value at top of cylinder
  #local Cap_PointZ = 0;                 //z value at top of cylinder
  #local Cylinder_Radius = Radius;       //radius of cylinder
  #local Base_Point = <Base_PointX, Base_PointY, Base_PointZ>;
  #local Cap_Point = <Cap_PointX, Cap_PointY, Cap_PointZ>;
  #local Cylinder_Obj = cylinder{ Base_Point, Cap_Point, Cylinder_Radius }
  Save_Cylinder( Cylinder_Obj ) //save object without any texture
  Save_Cylinder_Loc( Base_PointX, Base_PointY, Base_PointZ, Cap_PointX,
Cap_PointY, Cap_PointZ, Cylinder_Radius ) //Cylinder always needs 7 parameters
  Save_Cylinder_Id( Name ) //ID for recognizing this cylinder for recollection
#end

/*+++++++++++++++ Manupulating a Cylinder ++++++++++++++++
CAN'T FIGURE THIS FOR NOW*/
#macro Put_Cylinder( Name, XPos, YPos, ZPos )
  #local Count = 0;
  #while ( Count < Cylinder_Id )
    #if( strcmp( Cylinder_Objects_Id[ Count ], Name)=0)
      #debug Cylinder_Objects_Id[ Count ]
    #else
      #debug Cylinder_Objects_Id[ Count ]
    #end
    #declare Count = Count + 1;
  #end
#end

/*++++++++++++++++++++Start test commands+++++++++++++++++++*/
light_source{ <-20, 400, -20> color White }
camera{ location <20, 20, -30> look_at 0 }
plane{ y, 0 pigment{ color Yellow }}


Make_Cylinder( "FirstCyl", 5, 10 ) // create first cylinder
Make_Cylinder( "SecondCyl", 10, 6 ) // create second cylinder... testing
Put_Cylinder( "FirstCyl", 0, 0, 0 ) //put cylinder in scene without reference


Post a reply to this message

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