POV-Ray : Newsgroups : povray.advanced-users : trace macro misunderstanding ? : Re: trace macro misunderstanding ? Server Time
1 Jul 2024 05:31:34 EDT (-0400)
  Re: trace macro misunderstanding ?  
From: Tim Attwood
Date: 9 Oct 2009 00:08:07
Message: <4aceb727$1@news.povray.org>
>I would like to find when and where a ray hits a specified object.
> The hit could take place after one or more reflections on other objects.
> I thought the trace macro would help, but it seems that trace() pays no
> attention to auxiliary objects, finding the way of the ray in straight 
> line....

I think the better question would be why? What are you trying to do?
When is a tricky question, do you mean the frame number of an
animation? Do you mean how many reflective bounces will
be checked?  Do you mean distance?

> Am i missing something ?

It seems so.
A ray is half of a line, it starts at some point in space and
travels (or is "cast") in some direction.
Trace() calculates the nearest intersection between a ray and
a given object (if it hits it) and returns the location and surface
normal at that point.
Rays do not reflect... in the rendering process new rays are
cast from the intersection point, a ray is cast at every light,
and a ray is cast in the reflection direction if the surface is reflective.

Given a ray R1, (with a starting point P1, and a direction DIR1) ,
and an object O1 then

#declare NORM = <0,0,0>;
#declare HIT = trace(O1,P1,DIR1,NORM);

will return HIT and NORM vectors, if the length of the NORM
vector is zero, then there is no intersection of the ray R1 with
object O1, otherwise HIT contains the intersection point, and
NORM contains the surface normal of O1 at the intersection
point.

So to create a ray R2 which is a reflection of ray R1 at HIT,
you start at the location P2 and travel in the direction DIR2,
where
P2 = HIT
DIR2 = -vaxis_rotate(DIR1,NORM,180)

Rinse and repeat for every object of intrest and every bounce.


Post a reply to this message

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