POV-Ray : Newsgroups : povray.general : Objects on a slope Server Time
2 Nov 2024 16:54:47 EDT (-0400)
  Objects on a slope (Message 1 to 9 of 9)  
From: Jim Holsenback
Subject: Objects on a slope
Date: 12 Mar 2007 07:43:50
Message: <45f54b06@news.povray.org>
Hello,

I trying to place objects on the slope of a height_field. From the 
documentation I was able to figure out how to get the "Y" direction problem 
solved by using the trace command to place the objects, but now another 
issue has cropped up. Some of the objects are partically covered (see 
attached image). I'm wondering if if vrotate (A,B) A being the camera 
location, and B.z or B.x is would fix this. I'm having a problem figuring 
how to intergrate that into what I've already done. Pointers appreciated 
better than an actual solution as I'll end up understanding it better.

Thanks Jim
----

#macro PlaceDBs (Target, Location, Object)

  #local Dither = 1;
  #while (Dither)
    #local DFactor = 1 * rand(Rand);
    #if (DFactor >= 0.75 & DFactor <= 1)
      #local Dither = 0;
    #end
  #end

  #local Norm = <0, 0, 0>;
  #local Start = <0, 10, 0>;
  #local Intercept = trace (Target, Start, Location-Start ,Norm);

  #if (vlength(Norm) != 0)
    object {Object rotate y*(360 * DFactor) scale (0.1 * DFactor) translate 
Intercept}
  #end

#end

// -----

#declare NumberOfObjects = 50;
#declare Collision = 0.6;
#declare ObjectBox = <-5,0,-5>;
#declare Locations = array[NumberOfObjects];
#declare Rand = seed(49+16+80+87+33+5);

#declare i = 0;

#while (i < NumberOfObjects)
  #declare Locations[i] = (<rand(Rand),rand(Rand),rand(Rand)> - 0.5) * 
ObjectBox;
  #declare TooClose = 0;
  #declare j = 0;

  #while (j < i)
    #if (vlength(Locations[i] - Locations[j]) < Collision)
      #declare TooClose = 1;
      #declare j = i;
    #end
    #declare j = j + 1;
  #end

  #if (TooClose = 0)
    PlaceDBs (Terrain, Locations[i], DogBerries)
    #declare i = i + 1;
  #end
#end


Post a reply to this message


Attachments:
Download 'scratch.jpg' (42 KB)

Preview of image 'scratch.jpg'
scratch.jpg


 

From: Warp
Subject: Re: Objects on a slope
Date: 12 Mar 2007 08:12:13
Message: <45f551ad@news.povray.org>
If you want the objects to be aligned to the heightfield (instead of
all of them being purely vertical), the solution to this is to take the
normal vector returned by trace() and then use Reorient_Trans() from
transforms.inc to rotate the object.

-- 
                                                          - Warp


Post a reply to this message

From: Bruno Cabasson
Subject: Re: Objects on a slope
Date: 12 Mar 2007 08:25:01
Message: <web.45f553c07100fbbdf5fba6ef0@news.povray.org>
"Jim Holsenback" <jho### [at] hotmailcom> wrote:
> Hello,
>
> I trying to place objects on the slope of a height_field. From the
> documentation I was able to figure out how to get the "Y" direction problem
> solved by using the trace command to place the objects, but now another
> issue has cropped up. Some of the objects are partically covered (see
> attached image). I'm wondering if if vrotate (A,B) A being the camera
> location, and B.z or B.x is would fix this. I'm having a problem figuring
> how to intergrate that into what I've already done. Pointers appreciated
> better than an actual solution as I'll end up understanding it better.
>
> Thanks Jim
> ----
>
> #macro PlaceDBs (Target, Location, Object)
>
>   #local Dither = 1;
>   #while (Dither)
>     #local DFactor = 1 * rand(Rand);
>     #if (DFactor >= 0.75 & DFactor <= 1)
>       #local Dither = 0;
>     #end
>   #end
>
>   #local Norm = <0, 0, 0>;
>   #local Start = <0, 10, 0>;
>   #local Intercept = trace (Target, Start, Location-Start ,Norm);
>
>   #if (vlength(Norm) != 0)
>     object {Object rotate y*(360 * DFactor) scale (0.1 * DFactor) translate
> Intercept}
>   #end
>
> #end
>
> // -----
>
> #declare NumberOfObjects = 50;
> #declare Collision = 0.6;
> #declare ObjectBox = <-5,0,-5>;
> #declare Locations = array[NumberOfObjects];
> #declare Rand = seed(49+16+80+87+33+5);
>
> #declare i = 0;
>
> #while (i < NumberOfObjects)
>   #declare Locations[i] = (<rand(Rand),rand(Rand),rand(Rand)> - 0.5) *
> ObjectBox;
>   #declare TooClose = 0;
>   #declare j = 0;
>
>   #while (j < i)
>     #if (vlength(Locations[i] - Locations[j]) < Collision)
>       #declare TooClose = 1;
>       #declare j = i;
>     #end
>     #declare j = j + 1;
>   #end
>
>   #if (TooClose = 0)
>     PlaceDBs (Terrain, Locations[i], DogBerries)
>     #declare i = i + 1;
>   #end
> #end

Hello Jim.

Before you drop your objects onto the surface, you have to align them with
the normal of the surface at the place you drop. Have a look a
transforms.inc and at the doc on the subject. The Align_Trans() macro could
be helpful. As you sure know, the trace() primitive returns the normal of
the surface encountered.

    Bruno


Post a reply to this message

From: Bruno Cabasson
Subject: Re: Objects on a slope
Date: 12 Mar 2007 08:30:02
Message: <web.45f554dc7100fbbdf5fba6ef0@news.povray.org>
Warp <war### [at] tagpovrayorg> wrote:
> If you want the objects to be aligned to the heightfield (instead of
> all of them being purely vertical), the solution to this is to take the
> normal vector returned by trace() and then use Reorient_Trans() from
> transforms.inc to rotate the object.
>
> --
>                                                           - Warp

Hello again Jim. Oooooops, Warp is right: Reorient_Trans() is correct,
Align_Trans is not for your purpose ... He answered quicker an better than
me ...

   Bruno


Post a reply to this message

From: Trevor G Quayle
Subject: Re: Objects on a slope
Date: 12 Mar 2007 10:55:02
Message: <web.45f576d27100fbbdc150d4c10@news.povray.org>
"Jim Holsenback" <jho### [at] hotmailcom> wrote:
> Hello,
>
> I trying to place objects on the slope of a height_field. From the
> documentation I was able to figure out how to get the "Y" direction problem
> solved by using the trace command to place the objects, but now another
> issue has cropped up. Some of the objects are partically covered (see
> attached image). I'm wondering if if vrotate (A,B) A being the camera
> location, and B.z or B.x is would fix this. I'm having a problem figuring
> how to intergrate that into what I've already done. Pointers appreciated
> better than an actual solution as I'll end up understanding it better.
>

To further clarify along with what the others said, vrotate(A,B) doesn't
rotate objects, it rotates vector A by degree rotation B.  What you want is
the opposite, you know the resultant vector and the rotated vector (normal,
A), you need to find the corresponding rotation B which is what the
function described by Warp does.

-tgq


Post a reply to this message

From: Jim Holsenback
Subject: Re: Objects on a slope
Date: 12 Mar 2007 15:11:15
Message: <45f5b3e3@news.povray.org>
Thanks for the pointer ..... as I was reading vrotate description it didn't 
sound exactly right for my problem.
ONWARD!!!!


Post a reply to this message

From: Jim Holsenback
Subject: Re: Objects on a slope
Date: 13 Mar 2007 09:43:40
Message: <45f6b89c@news.povray.org>
"Warp" <war### [at] tagpovrayorg> wrote in message 
news:45f551ad@news.povray.org...
>  If you want the objects to be aligned to the heightfield (instead of
> all of them being purely vertical), the solution to this is to take the
> normal vector returned by trace() and then use Reorient_Trans() from
> transforms.inc to rotate the object.

Morning,

I've made some progress but have encountered a problem at arriving at the 
desired solution.

object {Object rotate y*(360 * DFactor) scale (0.1 * DFactor) Reorient_Trans 
(Intercept, SLoc) translate Intercept}

I'm 99% there and after some emperical testing I'm starting to think the 
second parameter for the call to Reorient_Trans can't be a fixed point. 
Here's what I've observed:  SLoc is the location of a small sphere that I'm 
using to move around the scene and indeed the objects seem to track the 
sphere. What about the objects that happen to be placed on or near the top 
of the ridge versus the objects that are placed farther down the slope. 
Conceptually the second parameter to Reorient_Trans would need to be another 
call to trace but this time the target would be scaled just slightly larger, 
but that doesn't sound very elegant. Any ideas?

Jim


Post a reply to this message


Attachments:
Download 'scratch.jpg' (29 KB)

Preview of image 'scratch.jpg'
scratch.jpg


 

From: Warp
Subject: Re: Objects on a slope
Date: 13 Mar 2007 11:02:18
Message: <45f6cb0a@news.povray.org>
Jim Holsenback <jho### [at] hotmailcom> wrote:
> object {Object rotate y*(360 * DFactor) scale (0.1 * DFactor) Reorient_Trans 
> (Intercept, SLoc) translate Intercept}

> I'm 99% there and after some emperical testing I'm starting to think the 
> second parameter for the call to Reorient_Trans can't be a fixed point. 
> Here's what I've observed:  SLoc is the location of a small sphere that I'm 
> using to move around the scene and indeed the objects seem to track the 
> sphere. What about the objects that happen to be placed on or near the top 
> of the ridge versus the objects that are placed farther down the slope. 
> Conceptually the second parameter to Reorient_Trans would need to be another 
> call to trace but this time the target would be scaled just slightly larger, 
> but that doesn't sound very elegant. Any ideas?

  I'm not exactly sure what is it that you want to to do exactly.

  I understood that you wanted to reorient the objects so that they are
parallel to the heightfield surface where they are laying on.

  When you used trace() to get the location of that point on the heightfield
where you want to place the object, you can get the normal vector of the
heightfield at that point (using the fourth parameter of trace()).

  Once you have this normal vector, and assuming that your object's "up"
is in the 'y' direction and that it's centered at the origin, you simply
do a ReorientTrans(y, TheNormalVector) before translating the object to
its place.
  The ReorientTrans will rotate the object so that what was previously
pointing towards 'y' will now be pointing in the same direction as the
normal vector.

-- 
                                                          - Warp


Post a reply to this message

From: Jim Holsenback
Subject: Re: Objects on a slope
Date: 13 Mar 2007 13:39:23
Message: <45f6efdb@news.povray.org>
"Warp" <war### [at] tagpovrayorg> wrote in message 
news:45f6cb0a@news.povray.org...
>  I'm not exactly sure what is it that you want to to do exactly.
>
>  I understood that you wanted to reorient the objects so that they are
> parallel to the heightfield surface where they are laying on.
>
>  When you used trace() to get the location of that point on the 
> heightfield
> where you want to place the object, you can get the normal vector of the
> heightfield at that point (using the fourth parameter of trace()).

Ahhhh ..... I see what I was doing wrong!!!!

#local Intercept = trace (Target, Start, Location - Start ,Norm);

I was using:
object {Object rotate y*(360 * DFactor) scale (0.1 * DFactor) Reorient_Trans 
(Intercept,SLoc) translate Intercept}
when I restated my problem ....

instead of:
object {Object rotate y*(360 * DFactor) scale (0.1 * DFactor) Reorient_Trans 
(y,Norm) translate Intercept}

I should have been using Norm (the 4th parameter of trace) .... works 
now!!!!

Sorry for the confusion!!! You've been very helpful, and I appreciate ALL 
your efforts.

Jim


Post a reply to this message

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