POV-Ray : Newsgroups : povray.newusers : Aligned box? : Re: Aligned box? Server Time
29 Jul 2024 14:26:59 EDT (-0400)
  Re: Aligned box?  
From: Mike Williams
Date: 8 Sep 2005 05:22:21
Message: <wpBQEiAlE$HDFw6g@econym.demon.co.uk>
Wasn't it Slime who wrote:
>> That comes VERY close. Actually, it works as I requested, although missing
>> an implied criteria. I didn't specify it, but I need the box to maintain a
>> vertical orientation, whereas your macro induces a rotation around the
>> P1-P2 axis. I'm guessing this is an artifact of the Reorient_Trans
>
>Replace Reorient_Trans with this macro and it should work (untested code,
>let me know if it doesn't):
>
>// maps the x axis to vec while keeping "sky" as up,
>// doesn't work if vec is parallel to sky
>#macro Reorient_Trans_Sky(vec, sky)
>    #local mapxto = vec;
>    #local mapzto = vnormalize(vcross(sky, vec));
>    #local mapyto = vcross(mapxto, mapzto);
>    matrix <
>        mapxto.x, mapxto.y, mapxto.z,
>        mapyto.x, mapyto.y, mapyto.z,
>        mapzto.x, mapzto.y, mapzto.z,
>        0,0,0
>    >
>#end
>
>Use it like Reorient_Trans_Sky(P2 - P1, y)

A quick test reveals that "sky" is a reserved word, and the mapxto and
mapyto need to be vnormalized. So:

#macro Reorient_Trans_Sky(vec, Sky)
    #local mapxto = vnormalize(vec);
    #local mapzto = vnormalize(vcross(Sky, vec));
    #local mapyto = vnormalize(vcross(mapxto, mapzto));
    matrix <
        mapxto.x, mapxto.y, mapxto.z,
        mapyto.x, mapyto.y, mapyto.z,
        mapzto.x, mapzto.y, mapzto.z,
        0,0,0
    >
#end

#macro aligned_box(P1, P2, H, W)
  #local L = abs(vlength(P2-P1));
  box {<0,-H/2,-W/2><L,H/2,W/2>
    transform {Reorient_Trans_Sky(P2-P1,y)}
    translate P1
  }
#end

-- 
Mike Williams
Gentleman of Leisure


Post a reply to this message

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