POV-Ray : Newsgroups : povray.advanced-users : My first grass. Server Time
29 Jul 2024 10:22:46 EDT (-0400)
  My first grass. (Message 7 to 16 of 16)  
<<< Previous 6 Messages Goto Initial 10 Messages
From: Corey Woodworth
Subject: Re: My first grass.
Date: 2 Oct 2002 19:23:19
Message: <3d9b7fe7@news.povray.org>
> The easiest is usually to use 'trace()'.  You can use the returned normal
> vector to determine the slope at the position.
>
> Christoph

I've seen lots of cool stuff done with trace but I've never dabbled with it
myself. I read the docs on it and I'm a bit confused. I have a heightfield
named canyon, and this is a nested loop to test for an intersection. It
should always intersect so it should always generate a sphere (I havn't the
slightest how to test for the slope yet), but it loops infinetly and I dunno
why. I'm not too good at Macros yet. =)
Here is my code, can someone point me in the right direction?

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

Corey


Post a reply to this message

From: Christopher James Huff
Subject: Re: My first grass.
Date: 2 Oct 2002 20:06:18
Message: <chrishuff-4761E3.20031102102002@netplex.aussie.org>
In article <3d9b7fe7@news.povray.org>,
 "Corey Woodworth" <cdw### [at] mpinetnet> wrote:

> I've seen lots of cool stuff done with trace but I've never dabbled with it
> myself. I read the docs on it and I'm a bit confused. I have a heightfield
> named canyon, and this is a nested loop to test for an intersection. It
> should always intersect so it should always generate a sphere (I havn't the
> slightest how to test for the slope yet), but it loops infinetly and I dunno
> why. I'm not too good at Macros yet. =)
> Here is my code, can someone point me in the right direction?

Well, your first problem is that you are testing for equality in your 
loop conditions...almost always a Bad Thing. Scalar variables in POV-Ray 
are double-precision floating point numbers, and numeric errors could 
cause them to go right past 0 without ever being exactly equal to it. 
Normally, you loop while the counter variable is higher or lower to a 
value instead of while it is not equal to a certain value.

You are also looping down, this is just odd, since usually people loop 
up unless they have a good reason, but it works, there isn't any reason 
not to.

Finally, and probably the real reason you have a problem, the trace() 
function takes a ray direction, not an end point. All your trace() calls 
are going off in a plane perpendicular to the y axis and passing through 
< 0, 2, 0>. Use "trace(Canyon, Start, -y, Norm)" instead.

Oh, and you are missing an #end...I assume this just got lost in editing 
for the post, because the code doesn't do anything without it.

-- 
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: Corey Woodworth
Subject: Re: My first grass.
Date: 4 Oct 2002 10:58:45
Message: <3d9daca5$1@news.povray.org>
> Well, your first problem is that you are testing for equality in your
> loop conditions...almost always a Bad Thing. Scalar variables in POV-Ray
> are double-precision floating point numbers, and numeric errors could
> cause them to go right past 0 without ever being exactly equal to it.
> Normally, you loop while the counter variable is higher or lower to a
> value instead of while it is not equal to a certain value.

That was code copied strait from the docs =) I didn't, and still don't
completely understand how and what trace returns. 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.

> You are also looping down, this is just odd, since usually people loop
> up unless they have a good reason, but it works, there isn't any reason
> not to.

It just seemed more intuitive to me at the time. =)

> Finally, and probably the real reason you have a problem, the trace()
> function takes a ray direction, not an end point. All your trace() calls
> are going off in a plane perpendicular to the y axis and passing through
> < 0, 2, 0>. Use "trace(Canyon, Start, -y, Norm)" instead.

Ah! That makes sense. I thought it was an endpoint. Thats why I moved End in
relation to Start.

> Oh, and you are missing an #end...I assume this just got lost in editing
> for the post, because the code doesn't do anything without it.

Whoops =)

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

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


Post a reply to this message

From: Tom Melly
Subject: Re: My first grass.
Date: 4 Oct 2002 12:10:36
Message: <3d9dbd7c$1@news.povray.org>
"Corey Woodworth" <sch### [at] hotmailcom> wrote in message
news:3d9daca5$1@news.povray.org...

>     #if (vlength(Norm)!=0)
>       sphere {
>         Inter, .5
>         texture {
>           pigment {color green 1}
>         }
>       }
>     #end

All that (vlength(Norm)!=0) is checking is that you've hit your hf (the only
time when vlength is 0 is when you've missed the object).

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:

#if(Norm.x = 0 & Norm.z = 0 & Norm.y != 0)
       sphere {
         Inter, .5
         texture {
           pigment {color green 1}
         }
       }
#end

or, with a bit more give and take...

#if(abs(Norm.x) < 0.1 & abs(Norm.z) < 0.1 & Norm.y != 0)
       sphere {
         Inter, .5
         texture {
           pigment {color green 1}
         }
       }
#end

... but wait for corrections from others (untested).


Post a reply to this message

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 6 Messages Goto Initial 10 Messages

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