POV-Ray : Newsgroups : povray.general : an extraordinary rotation question : Re: an extraordinary rotation question Server Time
30 Jul 2024 14:16:49 EDT (-0400)
  Re: an extraordinary rotation question  
From: Tim Attwood
Date: 24 Jun 2009 18:17:16
Message: <4a42a5ec$1@news.povray.org>
> I got most of the macro working, only a few problems, sorry for sounding 
> really
> stupid. My previous request for a macro sample is rendered obsolete by 
> this
> post. Cause I got a macro (Chris B's sample) working even though still 
> missing
> a lot of functionality.
>
> 1- I can't pass the texture names to macro as a parameter
> 2- I need another Union inside Cabinet Union for door, the door and the 
> handle
> should be another Union inside Cabinet Union. So when we open the door the
> handle moves along. Right?
> 3- the handle may be on the right or left of the door , how do we handle 
> that?
>   thus the hinge place changes, thus the door opens to a different 
> side....
>
> that's it for now I'm working on it, these 3 are all I'm stuck on right 
> now.
>
> PS: in the future I'll need a challenging macro for angled cabinets. 
> Remember
> the angled wall, well what if it needs a cabinet placed in its angled 
> corner.
> That cabinet should be angled accordingly in 2 pieces, single door. To
> understand what I'm saying , draw a straight line 50 cm, at right side 
> draw
> another line 40 cm at 40 degrees rotated towards yourself, now make that 
> into a
> cabinet on paper.
>
> Thanks a million
>
>
> ------------ the code I got working--------improvised Chris B's code
> // How does it look?

Not bad =)

Here's a rewrite demonstrating passing values to a macro by global
variables. There's nothing wrong with using parameters and ifndef,
but if you use one of the ifndef values, then it will persist to the next
macro call, which is can cause odd behavior.

camera {location <-1, 1.2, -1> look_at <0.6,0.3,0>}
light_source {<2,20,-4> color rgb 2}

// macro to initialize default values
#macro NewCabinet()
   #declare Thickness = 0.012;
   #declare Door_OpenAngle  = 0;
   #declare HasDoor  = true;
   #declare Cabinet_Texture = pigment {image_map {jpeg "yo_toprak"}}
   #declare Door_Texture = pigment {image_map {jpeg "A366_abanoz"}}
   #declare Width = 0.5;
   #declare Height = 0.75;
   #declare Depth = 0.6;
   #declare HasHandle = false;
   #declare Handle_Object = sphere {<0,0,-0.05>,0.05};
   #declare Handle_Texture = pigment {rgb <1,1,1>};
   #declare Handle_At = <0.15,0.6,-0.02>;
#end

// build a Cabinet
#macro Cabinet()
  union {
    // case
    difference {
      box {<0,0,0><Width,Height,Depth>}
      box {<Thickness,0.15,-0.001>
           <Width,Height,Depth>-Thickness
      }
      texture {Cabinet_Texture}
    }
    // door
    #if (HasDoor)
      box {<0,0,0><Width,Height,-0.02>
        texture {Door_Texture}
        rotate y*Door_OpenAngle
      }
    #end
    // handle
    #if (HasHandle)
      object {
         Handle_Object
         texture {Handle_Texture}
         translate Handle_At
         rotate y*Door_OpenAngle
      }
    #end
  }
#end

// Add 3 cabinets to the scene by calling the macro
// Default Cabinet
NewCabinet()
#declare Cabinet_Texture = pigment {image_map {jpeg "yldz_yesiltarra"}scale 
1 }
#declare Door_Texture = pigment {image_map {jpeg "A366_abanoz"}scale 1 }
object {Cabinet() rotate y*0 translate 0.0*x translate 0.10*y
translate 0.15*z}

// Custom Cabinet
NewCabinet()
#declare Cabinet_Texture = pigment {image_map {jpeg "yo_toprak"}scale 1 }
#declare Door_Texture = pigment {image_map {jpeg "A366_abanoz"}scale 1 }
#declare Door_OpenAngle = 45;
object {Cabinet() rotate y*45 translate 0.62*x translate
0.10*y translate 0.15*z}

// Doorless Cabinet
NewCabinet()
#declare Cabinet_Texture = pigment {image_map {jpeg "yo_toprak"}scale 1 }
#declare Door_Texture = pigment {image_map {jpeg "A366_abanoz"}scale 1 }
#declare Width = 0.35;
#declare HasDoor = false;
object {Cabinet() rotate y*0 translate -0.38*x translate
0.10*y translate 0.15*z}


Post a reply to this message

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