POV-Ray : Newsgroups : povray.binaries.images : Sci-Fi Scene Assets : Re: Sci-Fi Scene Assets Server Time
29 May 2024 06:39:39 EDT (-0400)
  Re: Sci-Fi Scene Assets  
From: Bald Eagle
Date: 1 Mar 2021 15:35:06
Message: <web.603d4fcda906d8e31f9dae300@news.povray.org>
"Kenneth" <kdw### [at] gmailcom> wrote:

> 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.

It's always complicated when we're using black-box macros and shooting in the
dark.

> 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.

Well, I tend to do things like that "by hand" using macros that I write deriving
everything from first-principles.

> Here's an example using the Point_At_Trans macro, applying typical pre-made
> objects. Note the delineated 'diamond' rotational patches.

They're not "diamonds" - they're triangles.

So let's peek into tranforms.inc:

// Similar to Reorient_Trans(), points y axis along Axis.
#macro Point_At_Trans (YAxis)
     // this is just a simple vector normalization.  No mystery.
     #local Y = vnormalize (YAxis);
     // this is a macro - I can't tell if it's a source-code thing, or a
math.inc thing. But here's where I think is what causes what you see. (* see
below)
     #local X = VPerp_To_Vector (Y);
     // vcross returns 0 when vectors are (anti-)parallel, and +/-1 when
perpendicular
     #local Z = vcross (X, Y);
     // As far as I can see, shear trans just applies a straightforward
transformation matrix, using x, y, and z.  And all those three vectors are
perpendicular, which is merely what all of the above code does.  And so the
whole object gets oriented to a "new y vector"
     Shear_Trans (X, Y, Z)
#end

* So, let's take a look at VPerp_To_Vector()
It takes a single argument.  Given a vector, find a vector perpendicular to it.
Which is ridiculous, given that I can spin a T-square around, and come up with
literally an infinite number of parallel vectors.

So let's take a look at what the macro specifically DOES.

Peeking into math.inc:

// Returns a vector perpendicular to V
// Author: Tor Olav Kristensen
#macro VPerp_To_Vector(v0)
   #if (vlength(v0) = 0)
      #local vN = <0, 0, 0>;
// Sanity check.   If you give it a/the zero vector, send it right back.

   #else
      #local Dm = min(abs(v0.x), abs(v0.y), abs(v0.z));

// And here's where we get the three-fold symmetry.  Find the smallest component
of the supplied vector.  This drives the rest of the macro results, which
computes the vector cross-product between your "new y vector" (the surface
normal), and the cardinal axis that it is "farthest away from".  What's the
center point of that 3-pronged choice tree?  The center of the triangle(s) in
your render.
Take a cardinal axis and start generating results from this macro as you rotate
it.  Eventually you will rotate it so far that a DIFFERENT cardinal axis will be
chosen by the macro to calculate the vector cross-product with.  And there are
only 3 axes, so you get triangular wedges of each octant of your sphere.

      #if (abs(v0.z) = Dm)
         #local vN = vnormalize(vcross(v0, z));
      #else
         #if (abs(v0.y) = Dm)
            #local vN = vnormalize(vcross(v0, y));
         #else
            #local vN = vnormalize(vcross(v0, x));
         #end
      #end
   #end
   vN // <--- returns one of three results
#end


So, now that we see where the problem is and why, we can formulate any number of
solutions.

The first and easiest is just write a new macro where you either use only one
dedicated axis as your second vector cross-product vector, or one where you can
choose which vector you want.  Or generate a random vector.

Second, you could take a look at which cardinal vector was used, and further
rotate your greeble based on that, to "correct" its orientation.

Maybe there are other options as well.

Maybe the POV-Ray light_source will shine its benevolent rays upon us, and TOK
will chime in with something elegant and brilliant.   :D


Post a reply to this message

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