POV-Ray : Newsgroups : povray.general : Rewrite of Doctor John's FieldCam macro Server Time 9 Dec 2021 08:41:31 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:
```
{
"@context": "https://schema.org",
"@type": "DiscussionForumPosting",
"@id": "#web.6189cefb97b1968629a3960c89db30a9%40news.povray.org",
"headline": "Rewrite of Doctor John's FieldCam macro",
"dateCreated": "2021-11-10T00:01:06+00:00",
"datePublished": "2021-11-10T00:01:06+00:00",
"author": {
"@type": "Person",
"name": "Tor Olav Kristensen"
}
}
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.

(v4.0 of it has an improvement suggested by Bald Eagle.)

There's a long discussion about it here:

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
```
 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>
```
{
"@context": "https://schema.org",
"@type": "DiscussionForumPosting",
"@id": "#618bc3f3%241%40news.povray.org",
"headline": "Re: Rewrite of Doctor John's FieldCam macro",
"dateCreated": "2021-11-10T13:06:59+00:00",
"datePublished": "2021-11-10T13:06:59+00:00",
"author": {
"@type": "Person",
"name": "Thomas de Groot"
}
}
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
```
 From: Tor Olav Kristensen Subject: Re: Rewrite of Doctor John's FieldCam macro Date: 11 Nov 2021 18:00:00 Message:
```
{
"@context": "https://schema.org",
"@type": "DiscussionForumPosting",
"@id": "#web.618d9fe5d771a4271a18378e89db30a9%40news.povray.org",
"headline": "Re: Rewrite of Doctor John's FieldCam macro",
"dateCreated": "2021-11-11T23:00:00+00:00",
"datePublished": "2021-11-11T23:00:00+00:00",
"author": {
"@type": "Person",
"name": "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.

--
Tor Olav
http://subcube.com
https://github.com/t-o-k
```
 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>
```
{
"@context": "https://schema.org",
"@type": "DiscussionForumPosting",
"@id": "#619111de%40news.povray.org",
"headline": "Re: Rewrite of Doctor John's FieldCam macro",
"dateCreated": "2021-11-14T13:40:46+00:00",
"datePublished": "2021-11-14T13:40:46+00:00",
"author": {
"@type": "Person",
"name": "Thomas de Groot"
}
}
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
```

Attachments: