|
![](/i/fill.gif) |
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
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
Op 11-11-2021 om 23:57 schreef Tor Olav Kristensen:
> Thomas de Groot <tho### [at] degroot org> 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](/povray.general/attachment/%3C619111de%40news.povray.org%3E/dj_tok_fieldcam_test.jpg?ttop=443780&toff=200&preview=1)
|
![](/i/fill.gif) |