POV-Ray : Newsgroups : povray.general : Rewrite of Doctor John's FieldCam macro : Rewrite of Doctor John's FieldCam macro Server Time
28 Nov 2021 15:47:52 EST (-0500)
  Rewrite of Doctor John's FieldCam macro  
From: Tor Olav Kristensen
Date: 9 Nov 2021 19:01:06
Message: <web.6189cefb97b1968629a3960c89db30a9@news.povray.org>
Some time ago I had a brief look at the FieldCam macro by Doctor John. At the
time I thought that it looked a bit overcomplicated.

Now I have had some time to try to simplify the mathematical expressions and to
rewrite the macro. I've actually split it into two macros.

The latest version of Doctors John's macro can be found here:
http://news.povray.org/povray.binaries.utilities/thread/%3C5fb777d1%241%40news.povray.org%3E/
(v4.0 of it has an improvement suggested by Bald Eagle.)

There's a long discussion about it here:
http://news.povray.org/povray.binaries.images/thread/%3C5fb22ee0%40news.povray.org%3E/

As creating and changing global variables inside macros is generally poor
programming practice, I've reintroduced parameter passing - and the macros now
"returns" the calculated transformation. Also I've made the macros fail hard
when the viewing (direction) vector is problematic, so that problems are
discovered early (when they may be easier to find and resolve).

Here's the rewritten macros:


#macro FieldCameraTransform_UpY(pLocation, pLookAt)

    #local vDirection = pLookAt - pLocation;
    #local vDirXZ = vDirection*(x + z);
    #local SqrXZ = vdot(vDirXZ, vDirXZ);
    #if (SqrXZ = 0)
        #error "The viewing vector is perpendicular to the XZ-plane.\n"
    #end // if
    #local vS = vDirection.y/SqrXZ*vDirXZ;

    transform {
        matrix <
               1,    0,    0,
            vS.x,    1, vS.z,
               0,    0,    1,
               0,    0,    0
        >
        translate -pLocation.y*vS
    }

#end // FieldCameraTransform_UpY


#macro FieldCameraTransform_UpZ(pLocation, pLookAt)

    #local vDirection = pLookAt - pLocation;
    #local vDirXY = vDirection*(x + y);
    #local SqrXY = vdot(vDirXY, vDirXY);
    #if (SqrXY = 0)
        #error "The viewing vector is perpendicular to the XY-plane.\n"
    #end
    #local vS = vDirection.z/SqrXY*vDirXY;

    transform {
        matrix <
               1,    0,    0,
               0,    1,    0,
            vS.x, vS.y,    1,
               0,    0,    0
        >
        translate -pLocation.z*vS
    }

#end // FieldCameraTransform_UpZ


// From the tests I've done so far, this code:

#declare pLocation = <10, 1, -14>;
#declare pLookAt = <-4, 6, 0>;

camera {
    perspective
    location pLocation
    FieldCameraTransform_UpY(pLocation, pLookAt)
    look_at pLookAt
}

// - seems to create the same result as this:
// (without the side effect of creating the global NoFall variable)

/*
#include "dj_fieldcam_v4.0.inc"

#declare CamPos = pLocation;
#declare CamLook = pLookAt;

FieldCam()

camera {
    perspective
    location CamPos
    transform { NoFall }
    look_at CamLook
}
*/

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


Post a reply to this message

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