POV-Ray : Newsgroups : povray.newusers : Image maps and heightfields Server Time
31 Oct 2024 12:18:39 EDT (-0400)
  Image maps and heightfields (Message 1 to 3 of 3)  
From: Corona688
Subject: Image maps and heightfields
Date: 21 Mar 2008 19:45:01
Message: <web.47e4547bb02d5773bebf2c990@news.povray.org>
I have an unusual problem -- image maps that are a different size and aspect
ratio than the heightfield they match.

I have precise information on where they belong relative to the heightfield, and
I can get them to fit with hardcoded values, but any sort of macro to fit it
based on the information I have has eluded me for the last week.

Hence I politely ask for help creating a macro for the translations+rotations in
the pigment section, like:

IMG_FIT(-0.5, +0.0,
        +1.0, +1.0)

where the first two coordinates are the upper left corner of the imagemap
relative to the heightfield, and the second two are the lower right.  Yes, part
of the left side of the image would miss the heightfield, that is the idea.

My silly efforts so far, just so you know I've tried:

#macro IMGMAP_FIT(XSCALE, YSCALE, XOFF, YOFF)
        rotate <90, 0, 0>           // Face up
        translate<-0.5, -0.5, -0.5> // Center
        scale <-XSCALE, 1, -YSCALE> // Resize
        translate<(XSCALE-1)/2, 0, -(YSCALE-1)/2> // Relocate
#end


Post a reply to this message

From: Alain
Subject: Re: Image maps and heightfields
Date: 21 Mar 2008 23:07:04
Message: <47e485e8$1@news.povray.org>
Corona688 nous apporta ses lumieres en ce 2008/03/21 20:43:
> I have an unusual problem -- image maps that are a different size and aspect
> ratio than the heightfield they match.
> 
> I have precise information on where they belong relative to the heightfield, and
> I can get them to fit with hardcoded values, but any sort of macro to fit it
> based on the information I have has eluded me for the last week.
> 
> Hence I politely ask for help creating a macro for the translations+rotations in
> the pigment section, like:
> 
> IMG_FIT(-0.5, +0.0,
>         +1.0, +1.0)
> 
> where the first two coordinates are the upper left corner of the imagemap
> relative to the heightfield, and the second two are the lower right.  Yes, part
> of the left side of the image would miss the heightfield, that is the idea.
The first two parameters are scaling factors.
The last two are *suposed* to be placement parameters, but not used.
> 
> My silly efforts so far, just so you know I've tried:
> 
> #macro IMGMAP_FIT(XSCALE, YSCALE, XOFF, YOFF)
>         rotate <90, 0, 0>           // Face up
>         translate<-0.5, -0.5, -0.5> // Center
>         scale <-XSCALE, 1, -YSCALE> // Resize
>         translate<(XSCALE-1)/2, 0, -(YSCALE-1)/2> // Relocate
> #end
> 
> 
> 
If you rewrite your macro with the provided values, you get:
----------------------------
rotate 90*x
translate -0.5
scale <-(-0.5),1,-0>// become: scale<0.5,1,1>
translate<(-0.5-1)/2,0,-(0-1)/2>//become: translate<-0.75,0,0.5>
-----------------------------
The net translation is: <-1.25,-0.5,0>

You want to scale the image relative to it's center. Use:
translate -0.5 //center around origin
scale<XSCALE,1,YSCALE> //scale it
translate 0.5 // return it to it's original position

Now, you want to place if acording to your offset
translate<XOFF,1,YOFF>

-- 
Alain
-------------------------------------------------
Adult, n.: One old enough to know better.


Post a reply to this message

From: Corona688
Subject: Re: Image maps and heightfields
Date: 23 Mar 2008 11:30:01
Message: <web.47e684ae5496961e0c220080@news.povray.org>
Alain <ele### [at] netscapenet> wrote:
> You want to scale the image relative to it's center. Use:
> translate -0.5 //center around origin
> scale<XSCALE,1,YSCALE> //scale it
> translate 0.5 // return it to it's original position
>
> Now, you want to place if acording to your offset
> translate<XOFF,1,YOFF>
>
> --
> Alain
> -------------------------------------------------
> Adult, n.: One old enough to know better.

Thank you so much, your help was key!  I have finally realized my goal of
placing images on heightfields algorithmically by their global coordinates
alone.

On the off chance anyone else is struggling to match Canadian Toporama imagery
to Canadian Geobase DEM data:

#macro IMGMAP_FIT(XSCALE, YSCALE, XOFF, YOFF)
        rotate <90, 0, 0>               // Face up
        translate <-0.5, -0.5, -0.5>    // Center on origin
        scale<XSCALE, 1, YSCALE>        // Scale
        translate<0.5, 0.5, 0.5>        // Move off origin
        translate<(XSCALE-1)/2, 0, -(YSCALE-1)/2>       // Position upper-left
        translate<-XOFF, 0, YOFF>       // Translate
#end

#macro DEM_FIT(DEMLAT, DEMLON, DEMH, DEMW,
        IMGLAT, IMGLON, IMGH, IMGW)
        IMGMAP_FIT(     IMGW/DEMW,              IMGH/DEMH,
                        (DEMLON-IMGLON)/DEMH,
                        (DEMLAT-IMGLAT)/DEMW)
#end

height_field
{
        tga "062L10w.tga"
        water_level 0

        /* Match the orientation of the map to screen coordinates */
        translate<-0.5, -0.5, -0.5>
                rotate <0, -90, 0>
        translate<+0.5, +0.5, +0.5>


        pigment
        {
                image_map       {       gif "062L10.gif" once   }

                // Toporama gives different aspects for different latitudes
                // of map!  A general image-fitter makes it so much tidier.
                DEM_FIT(182700, -370800, 900, 900,
                        182700, -370800, 900, 1800)
        }
}

Also note that ye olde dem2pov.c fails for Geobase DEM data, since
smaller-than-one spatial resolutions round to ZERO.  I'll find somewhere to
post fixes once I have something better than my current hack.


Post a reply to this message

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