POV-Ray : Newsgroups : povray.advanced-users : My first grass. Server Time
29 Jul 2024 10:24:19 EDT (-0400)
  My first grass. (Message 11 to 16 of 16)  
<<< Previous 10 Messages Goto Initial 10 Messages
From: Christopher James Huff
Subject: Re: My first grass.
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

From: Christopher James Huff
Subject: Re: My first grass.
Date: 4 Oct 2002 13:55:02
Message: <chrishuff-653276.13514304102002@netplex.aussie.org>
In article <3d9dbd7c$1@news.povray.org>,
 "Tom Melly" <tom### [at] tomandlucouk> wrote:

> I haven't used trace for a while now, but iirc what you want to do is check
> whether Norm.x and Norm.z are under a certain range. I think the following 
> would only place a sphere if the point was perfectly flat:

Just checking y would be easier. If it is very near 1, both x and y must 
be near 0. It is equal to the sine of the angle to a horizontal plane. 
And if it is non-0, the intersection is valid, so you don't even have to 
check for < 0, 0, 0> any more.

-- 
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

From: Tom Melly
Subject: Re: My first grass.
Date: 7 Oct 2002 08:50:00
Message: <3da182f8$1@news.povray.org>
"Christopher James Huff" <chr### [at] maccom> wrote in message
news:chr### [at] netplexaussieorg...
>
> Just checking y would be easier. If it is very near 1, both x and y must
> be near 0. It is equal to the sine of the angle to a horizontal plane.

That's the bit I couldn't quite remember (i.e. whether trace could return
<1,1,1> as a vector).


Post a reply to this message

From: Christopher James Huff
Subject: Re: My first grass.
Date: 7 Oct 2002 12:20:20
Message: <chrishuff-EB8B45.12170307102002@netplex.aussie.org>
In article <3da182f8$1@news.povray.org>,
 "Tom Melly" <tom### [at] tomandlucouk> wrote:

> That's the bit I couldn't quite remember (i.e. whether trace could return
> <1,1,1> as a vector).

Well, it can't return that either, and never will...unless I am very 
wrong, it always returns either a normalized vector or < 0, 0, 0>.

-- 
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

From: Tom Melly
Subject: Re: My first grass.
Date: 8 Oct 2002 05:06:08
Message: <3da2a000$1@news.povray.org>
"Christopher James Huff" <chr### [at] maccom> wrote in message
news:chr### [at] netplexaussieorg...

> Well, it can't return that either, and never will...unless I am very
> wrong, it always returns either a normalized vector or < 0, 0, 0>.
>

Well, exactly (I think). BTW, what is the normalised vector of <1,1,1>? Oh, hang
on, there must be a function for that....

#debug vstr(3, vnormalize(<1,1,1>), ", ",2,5)


Post a reply to this message

From: Christopher James Huff
Subject: Re: My first grass.
Date: 8 Oct 2002 10:28:46
Message: <chrishuff-743246.10251008102002@netplex.aussie.org>
In article <3da2a000$1@news.povray.org>,
 "Tom Melly" <tom### [at] tomandlucouk> wrote:

> Well, exactly (I think). BTW, what is the normalised vector of <1,1,1>? Oh, 
> hang
> on, there must be a function for that....
> 
> #debug vstr(3, vnormalize(<1,1,1>), ", ",2,5)


The normalized vector is < x, y, z>/sqrt(x*x + y*y + z*z), so the result 
is < 1, 1, 1>/sqrt(3). This can't be perfectly represented in decimal or 
binary form, so you will get a lot of decimals from that #debug 
statement. You probably don't need to know this unless you are trying to 
simplify algebraic expressions.

-- 
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

<<< Previous 10 Messages Goto Initial 10 Messages

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