POV-Ray : Newsgroups : povray.general : Trace(): help required : Re: Trace(): help required Server Time
1 Aug 2024 02:15:31 EDT (-0400)
  Re: Trace(): help required  
From: Warp
Date: 18 May 2006 16:17:42
Message: <446cd665@news.povray.org>
Sven Littkowski <sve### [at] jamaica-focuscom> wrote:
> Maybe a small very simple sample scene could help me, with some truly 
> explaining words.

// Declare an object you want to trace:
#declare AnObject =
  torus { 1, .5 pigment { rgb x } finish { specular .5 } };

// Let's "drop" cylinders on this object from above.
// First let's define the area inside which to "drop" cylinders
// (this covers the entire torus above viewed from above):
#declare MinX = -1.5;
#declare MaxX = 1.5;
#declare MinZ = -1.5;
#declare MaxZ = 1.5;
#declare DropHeight = 2;
#declare CylinderRadius = .015;
#declare NormalScale = .1;

// Now let's loop through all that area using regular steps:
#declare Normal = <0,0,0>;
#declare Step = .1;
#declare IndX = MinX;
#while(IndX <= MaxX)
  #declare IndZ = MinZ;
  #while(IndZ <= MaxZ)

    // Now let's "drop" a cylinder onto the torus:
    #declare Intersection =
      trace(AnObject, <IndX, DropHeight, IndZ>, -y, Normal);
    // The first parameter is the object to trace (ie. our torus).
    // The second parameter is the starting point for the trace
    // (like the point from which we "drop" our cylinder).
    // The third parameter is the direction towards which we trace
    // (ie. the direction towards which we "drop" the cyliner)
    // The last parameter is the normal vector at the intersection point
    // (this has two uses, as seen below).

    // Now, a normal vector <0,0,0> is invalid and thus trace() uses that
    // value to indicate that it did not intersect the object at all.
    // Thus we have to check that it is not <0,0,0> before we crate the
    // cylinder:
    #if(vlength(Normal) > 0)
      // Now we can create the cylinder at the intersection point.
      // To keep things interesting, let's orientate the cylinder in
      // the direction of the normal vector:
      cylinder
      { Intersection, Intersection+Normal*NormalScale, CylinderRadius
        pigment { rgb y }
        finish { specular .5 }
      }
    #end

    #declare IndZ = IndZ + Step;
  #end
  #declare IndX = IndX + Step;
#end


camera { location <0, 5, -5> look_at 0 angle 35 }
light_source { <100, 200, 0>, 1 }
object { AnObject }


Post a reply to this message

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