POV-Ray : Newsgroups : povray.binaries.images : Sci-Fi Scene Assets : Re: Sci-Fi Scene Assets Server Time
5 May 2024 21:42:17 EDT (-0400)
  Re: Sci-Fi Scene Assets  
From: Tor Olav Kristensen
Date: 16 Apr 2021 23:55:00
Message: <web.607a5b71a906d8e38e52cc8789db30a9@news.povray.org>
"Kenneth" <kdw### [at] gmailcom> wrote:
> "Bald Eagle" <cre### [at] netscapenet> wrote:
> > "Kenneth" <kdw### [at] gmailcom> wrote:
> >
> > > ... but there's possibly *some* kind of problem (maybe 'problem'
> > > is not the right word) for how trace creates its normal in the first
> > > place. But I haven't exactly narrowed the problem down to trace itself;
> > > it may be in how the normal is being 'processed' by other POV-ray tools..
> > >
> >
> > POV-Ray "measures" the normal of the surface that the ray intersects.
> > I'm pretty sure that there's no problem there.
> >
> > Clearly understanding what those other macros actually do is probably
> > where the problem lies.
> >
>
> Yeah, I think you're right on both counts. For some strange reason, I've always
> had a half-baked belief that trace's normal (or *any* normal) has a preferred
> 'handedness' when it comes to applying an object along that normal... meaning,
> the normal ITSELF might somehow be *rotating* the object to a new orientation,
> depending on which direction the normal faces into the x/y/z universe.  But
> that's silly: a normal is *just a vector direction*. And I have to finally
> dispel my mythical thinking. ;-) Thanks for waking up my tired ol' brain.
>
> The object rotational problems I see when using the Point_At_Trans and
> Reorient_Trans macros are specific to those tools, I agree. I've tried mightily
> to 'correct' the resulting 'unexpected' object rotations (which DO result from
> the normal's direction into space), but it's all quite mathematically
> complicated.
>
> Try tracing a simple sphere from random directions with thousands of greeble
> objects applied, while using the found normals and those alignment macros to
> place them, and you'll see what I mean.
>
> Here's an example using the Point_At_Trans macro, applying typical pre-made
> objects. Note the delineated 'diamond' rotational patches.


Hi Kenneth

You can try this:

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

#version 3.7;

#include "colors.inc"

global_settings { assumed_gamma 1.0 }

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

#macro OrientToNorth(vN, pL)

    #local vC = vnormalize(vN);
    #local vB = vnormalize(vcross(vC, y));
    #local vA = vcross(vB, vC);

    transform {
        matrix <
            vA.x, vA.y, vA.z,
            vB.x, vB.y, vB.z,
            vC.x, vC.y, vC.z,
            pL.x, pL.y, pL.z
        >
    }

#end // macro OrientToNorth


#declare pCenter = <0, 3, 0>;
#declare Radius = 2;

#declare Sphere = sphere { pCenter, Radius }

union {
    object { Sphere }
    cylinder {
        -(Radius + 1)*y, +(Radius + 1)*y, 0.05
        translate pCenter
    }
    pigment { color White }
}

#declare Box = box { -<7, 2, 1>, +<7, 2, 1> }

#declare TraceDistance = 2*Radius;
#declare S1 = seed(27814);
#declare S2 = seed(12259);
#for (I, 1, 1000)
    #declare vRandom = <1, 1, 1> - 2*<rand(S1), rand(S1), rand(S1)>;
    #declare pTraceOrigin = pCenter + TraceDistance*vnormalize(vRandom);
    #declare vTraceDirection = pCenter - pTraceOrigin;
    #if (vTraceDirection.x != 0 & vTraceDirection.z != 0)
        #declare vSurfaceNormal = <0, 0, 0>;
        #declare pSurface =
            trace(Sphere, pTraceOrigin, vTraceDirection, vSurfaceNormal);
        #if (vlength(vSurfaceNormal) > 0)
            object {
                Box
                scale <1, 1, 1>/100
                pigment { color srgb <rand(S2), rand(S2), rand(S2)> }
                OrientToNorth(vSurfaceNormal, pSurface)
            }
        #end // if
    #end // if
#end // for

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

light_source {
    100*<2, 5, 0>
    color White
}

camera {
    location <2, 3, 6>
    look_at <0, 0, 0>
    translate pCenter
}

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7


Note that this code will not attempt to place any objects exactly at the
"poles", since their desired orientation there is unknown.

Also see my recent reply to Bill in this thread.

--
Tor Olav
http://subcube.com
https://github.com/t-o-k


Post a reply to this message


Attachments:
Download 'orienttonorth.png' (101 KB)

Preview of image 'orienttonorth.png'
orienttonorth.png


 

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