POV-Ray : Newsgroups : povray.binaries.images : Seascape ... Help! : Re: Seascape ... Help! Server Time
12 Aug 2024 11:24:08 EDT (-0400)
  Re: Seascape ... Help!  
From: Mike Williams
Date: 23 Aug 2003 05:12:09
Message: <CEuM$BAD+yR$Ewtt@econym.demon.co.uk>
Wasn't it Aaron Gillies who wrote:
>Inspired by fiddling around with height fields tonight.
>
>My question is ...
>
>Can someone help me figure out how to use trace and the normal
>vector that is set by the function to place my trees only in those
>places that are at a certain level of flatness?
>
>Is such a thing possible?

The normal is a unit vector. A perfectly flat place would have a normal
of <0,1,0>. The steeper the slope is at a given point, the lower is its
y component. So you can just test to see if Normal.y is greater than
some value. [I reckon Normal.y is the cosine of the angle at which the
ground is tilted, but you're probably going to want to try various
values to see what looks good, rather than pre-calculate what angle of
tilt is acceptable for a tree.]

#declare Mountain = height_field { . . . }

object {Mountain}

#declare Tree = . . . 

#declare Number_of_trees = 2000;
#declare Flatness = 0.95;
#declare RR=seed(1234);
#declare Normal=<0,0,0>;                // force Normal to be a vector

#declare N=0;
#while (N < Number_of_trees)
  #declare X=rand(RR)-0.5;              // or whatever gives a random
  #declare Z=rand(RR)-0.5;              // cover of your Mountain object
  #declare Position = trace(Mountain,<X,1000,Z>,-y,Normal);
  #if (Normal.y > Flatness)
    object {Tree translate Position}
    #declare N=N+1;
  #end
#end

[I've not bothered to explicitly test for the normal being <0,0,0>
(which means that the trace missed the object completely) since such a
point would be rejected by the flatness test.]


Post a reply to this message

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