POV-Ray : Newsgroups : povray.advanced-users : My first grass. : Re: My first grass. Server Time
29 Jul 2024 12:18:23 EDT (-0400)
  Re: My first grass.  
From: Christopher James Huff
Date: 4 Oct 2002 13:52:34
Message: <chrishuff-AD64E5.13490004102002@netplex.aussie.org>
In article <3d9daca5$1@news.povray.org>,
 "Corey Woodworth" <sch### [at] hotmailcom> wrote:

> That was code copied strait from the docs =) I didn't, and still don't
> completely understand how and what trace returns.

It takes an object and the beginning point and direction of a ray, and 
optionally a variable to put the surface normal in. If the ray hits the 
object, it sets the normal variable to the surface normal at the point 
where it hit, and returns the intersection point. If it doesn't hit the 
object, it sets the normal to < 0, 0, 0> (an impossible value for a 
normal) and could return anything for the point, that value is 
unpredictable.


> What I'm aiming for is something that detects if the given point on 
> the HF is somewhat flat and if so put a sphere there.

How easy that is depends on how you define "flat"...you could check the 
y value of the normal. If it is perfectly horizontal, it will equal 1, 
perfectly vertical it will equal 0, you will probably want some 
leeway...placing spheres only if the y value is larger than 0.7, for 
example. It will be the sine of the angle to a horizontal plane, so some 
simple trig could be used to set the threshold to a specific angle if 
you want this.
This is only affected by the normal of the surface at that point 
though...it could be a bump on the side of a steep cliff, or the ground 
at that point could be extremely rough.


> Ok. Here is the updated code, but it still doesn't work.

How does it not work? It still infinitely loops? Or it just doesn't 
place the spheres?
Here's a (untested) corrected (and reformatted to be closer to the way I 
write code, just ignore that) version:

#declare Norm = <0, 0, 0>;
#declare Counter = 1000;
#declare xCount = Counter;
#declare zCount = Counter;
#while(xCount > 0)
  #while(zCount > 0)
    #declare Start = <xCount/Counter, 100, zCount/Counter>;
    #declare Inter = trace(canyon, Start, -y, Norm);
    #if(vlength(Norm) > 0.0001)
      sphere {Inter, .5
        texture {pigment {color green 1}}
      }
    #end
    #declare zCount = zCount - 1;
  #end
  #declare xCount = xCount - 1;
#end

I increased the "height" the rays are cast from to 100...I don't know 
how tall your canyon object is, if it went higher than 2 there would 
have been a problem.

-- 
Christopher James Huff <cja### [at] earthlinknet>
http://home.earthlink.net/~cjameshuff/
POV-Ray TAG: chr### [at] tagpovrayorg
http://tag.povray.org/


Post a reply to this message

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