POV-Ray : Newsgroups : povray.advanced-users : Enabling relative coordinate placement : Re: Enabling relative coordinate placement Server Time
3 Jul 2024 04:34:05 EDT (-0400)
  Re: Enabling relative coordinate placement  
From: Chris B
Date: 21 Sep 2009 05:49:26
Message: <4ab74c26@news.povray.org>
"Edouard" <pov### [at] edouardinfo> wrote in message 
news:web.4ab71754ba1022f62feef4220@news.povray.org...
> "Chris B" <nom### [at] nomailcom> wrote:
>>
>> POV-Ray does have some features that make this sort of thing fairly
>> straight-forward once you're familiar with the syntax and constructs....
>
> I was playing around with an idea like this a week or so ago. I was trying 
> to
> build some high level abstraction that would let me construct "objects" 
> with
> arbitrary properties, so I could then write macros that dealt with those
> objects, rather than lower level POV data.
>

I guess what I said does lead in that sort of direction, but I have gone in 
that sort of direction in the past and fallen foul of a few problems and I'd 
propose something a bit lighter.

I think there's a danger of designing a programming layer on top of the SDL 
(a sort of framework) which may solve certain problems, but which can make 
things more complicated in the end. When you come to try and share that with 
others they need to learn that framework in addition to the POV-Ray SDL, 
which I think is often too much like hard work for most people. Also there's 
a risk that people are constrained and can only do what the framework was 
designed to do (a sort of keyhole programming).

A lot of people probably want to combine elements from different sources, 
e.g. a terrain generator, a modeller and hand-coded or macro generated CSG 
objects. Constraints added as a sort of layer on top of the SDL tend to 
limit people to tools that are compatible with one paticular framework 
approach.  So, having slept on it I think I'd advocate stepping back a bit 
from that edge.

Taking the problem of relative coordinate placement in isolation for a 
moment, I believe it's possible to follow a more 'lite' approach as 
illustrated in the following examble. It's a fully functioning example, so 
you can play around with it. It just declares some transformations that can 
be used to position objects, texutres, cameras, lights, etc. relative to 
other objects. POV-Ray lets you accumulate transformations, so you can 
readily define a House datum relative to the plot of land it sits on, a 
Bathroom datum relative to the House datum and a datum for the shelf to hold 
your toothbrush relative to the Bathroom datum.

You can then add your toothbrush to the shelf without going through the 
mental trauma of calculating its position relative to a fencepost in the 
garden. Of course you still need to get your brain around the relative 
positions when you're declaring or adjusting these datums, but it should 
reduce the mental effort when working on component parts.

If you subsequently need to reorient the whole plot of land relative to the 
street that it's on (and you've used this technique reasonably consistently 
to position things), you can simply add a new datum representing the 
lamppost at the end of the street and changing the Garden datum to inherit 
it's position and orientation from that. You can even have datums whose 
positions are controlled by the clock, for example on a train passing the 
end of the garden.


// Position the plot of land relative to the origin
#declare Garden_Datum = transform {
  rotate y*25
  translate <-2,0,-5>
}
// Position the house relative to the land
#declare House_Datum = transform {
  translate <2,0,5>
  transform {Garden_Datum}
}
// Position the bathroom relative to the house
#declare Bathroom_Datum = transform {
  translate <1,2.4,2.5>
  transform {House_Datum}
}
// Position the greenhouse relative to the garden
#declare Greenhouse_Datum = transform {
  rotate y*40 translate <2.5,0,4>
  transform {Garden_Datum}
}

camera {location <0,1.5,0> look_at <0.5,1.5,1> transform {Garden_Datum}}
//camera {location <0,1.5,0> look_at <0.5,1.5,1> transform 
{Greenhouse_Datum}}
light_source {<1,50,-100> color rgb 1}

// Create a bath and move it into
// the corner of the bathroom
box {<0,0,0><0.6,0.4,1.6>
  pigment {agate}
  transform{Bathroom_Datum}
}

// Build a Greenhouse
box {<0,0,0><2,2,2.5>
  pigment {rgbt <0.6,1,0.7,0.6>}
  transform{Greenhouse_Datum}
}

// Position a plant pot relative to the corner of the greenhouse
cylinder {<0,0,0>,<0,0.3,0>,0.1
  pigment {rgb <1,0,0>}
  // Move the plant pot (relative to the greenhouse datum)
  translate <0.2,1,1.2>
  transform {Greenhouse_Datum}
}




Regards,
Chris B.


Post a reply to this message

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