POV-Ray : Newsgroups : povray.general : Rewrite of Doctor John's FieldCam macro Server Time
27 Dec 2024 21:17:48 EST (-0500)
  Rewrite of Doctor John's FieldCam macro (Message 1 to 4 of 4)  
From: Tor Olav Kristensen
Subject: Rewrite of Doctor John's FieldCam macro
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

From: Thomas de Groot
Subject: Re: Rewrite of Doctor John's FieldCam macro
Date: 10 Nov 2021 08:06:59
Message: <618bc3f3$1@news.povray.org>
Thank you very much indeed. I have not yet used your new version (shall 
do that soon); it is one of those unmissable little applications one 
always needs at regular times.

-- 
Thomas


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: Rewrite of Doctor John's FieldCam macro
Date: 11 Nov 2021 18:00:00
Message: <web.618d9fe5d771a4271a18378e89db30a9@news.povray.org>
Thomas de Groot <tho### [at] degrootorg> wrote:
> Thank you very much indeed. I have not yet used your new version (shall
> do that soon); it is one of those unmissable little applications one
> always needs at regular times.

No problem. Let me know if there's any problems with it.

It would be useful if we had a sample scene for testing these macros.

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


Post a reply to this message

From: Thomas de Groot
Subject: Re: Rewrite of Doctor John's FieldCam macro
Date: 14 Nov 2021 08:40:46
Message: <619111de@news.povray.org>
Op 11-11-2021 om 23:57 schreef Tor Olav Kristensen:
> Thomas de Groot <tho### [at] degrootorg> wrote:
>> Thank you very much indeed. I have not yet used your new version (shall
>> do that soon); it is one of those unmissable little applications one
>> always needs at regular times.
> 
> No problem. Let me know if there's any problems with it.
> 
> It would be useful if we had a sample scene for testing these macros.
> 

It works perfectly. I have tested the Y-up version only currently, with 
different camera position, and no glitch.

A attach an image, and the (simple) test file I have used.

-- 
Thomas


Post a reply to this message


Attachments:
Download 'dj_tok_fieldcam_test.jpg' (52 KB) Download 'dj_tok_fieldcam_test.pov.txt' (6 KB)

Preview of image 'dj_tok_fieldcam_test.jpg'
dj_tok_fieldcam_test.jpg

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