POV-Ray : Newsgroups : povray.general : Macro: rounded boxes: P1 P2 format, any radius and size. Server Time
27 Nov 2024 03:38:32 EST (-0500)
  Macro: rounded boxes: P1 P2 format, any radius and size. (Message 1 to 1 of 1)  
From: MessyBlob
Subject: Macro: rounded boxes: P1 P2 format, any radius and size.
Date: 10 Apr 2009 19:30:01
Message: <web.49dfd5554aa07af3addfbead0@news.povray.org>
You might find this useful... a wrapper macro for f_rounded_box, which allows
you to specify its shape in box {} coordinates, and ignore the 0..1 value
limits on all parameters (or automatically work around default clipping).

There's probably a simple way of condensing seperate x,y,z element calculations
into a single vector calculation, but the ones I tried returned errors.

This uses a global variable, Simpleboxes, which speeds up rendering of drafts
when set. If you want clean code with good scope, then just add this is the
parameters of the macro. Would benefit from check on the max() term to protect
against division by zero.

A more general-purpose version would encapsulate this in an object{} and remove
the material requirement. What you see here is the form that I used.

POV-Ray SDL code:

#macro RBox(R, P1, P2, M)
  /* Rounded Box macro, any size and radius.
     By John Valentine, http://johnvalentine.co.uk

     Overcomes the limitation of 0..1 as values in f_rounded_box,
     with positions in the same format as "box { P1, P2 }"

     Parameters:
       R   Radius of curvature for corners
       P1  Corner of box, same as for "box { P1, P2 }"
       P2  "
       M   Material for the object

     Globals:
       SimpleBoxes  Speeds up rendering of drafts when set.
  */

  #local DX = P2.x-P1.x;
  #local DY = P2.y-P1.y;
  #local DZ = P2.z-P1.z;
  #local SF = 1 / max( R, DX, DY, DZ );
  #if (SimpleBoxes)
    box { P1, P2
  #else
  isosurface {
    function {
      f_rounded_box(x,y,z, R*SF, DX*SF, DY*SF, DZ*SF)
    }
    scale 0.5/SF // <PX-PXo, BlockH, PZ-PZo>*SF
    translate 0.5*<DX,DY,DZ>
    translate P1
  #end
    material {M}
  }
#end


Post a reply to this message

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