POV-Ray : Newsgroups : povray.advanced-users : Can I apply the camera transform matrix to objects? Server Time
26 Dec 2024 01:41:59 EST (-0500)
  Can I apply the camera transform matrix to objects? (Message 1 to 9 of 9)  
From: zachrahan
Subject: Can I apply the camera transform matrix to objects?
Date: 6 Sep 2005 14:45:00
Message: <web.431de37ea8436e23a205a1b30@news.povray.org>
I'm trying to figure out a way to get some objects to always "point" at the
camera, no matter where I move it. (Imagine an array of solar mirrors
mounted on gimbals so that they always point at the sun.)

Anyhow, I can see two ways I might do this in povray:

(1) If there were some way I could obtain the camera-to-world transform
(that is, the inverse of the world-to-camera transform, unless I've gotten
the two backwards) and apply that to objects in the scene, then this would
have the effect of "undoing" any camera motion so the objects always
"point" at the camera in the same orientation.

(2) If there were some way to specify the orientation of objects via
"lookat" and "sky" parameters, as you can with the camera, I could just set
the camera and the objects to look at each other, with a common sky vector.

Option 2 is neat because it's more general -- you could have objects all
point at any arbitrary thing. However, I don't see anything like that in
the documentation, so I assume that it's probably option 1 or nothing?

Now, I know the math needed to convert lookat and sky vectors to real
transform matrices, so I could do this outside of POV and just directly
enter a matrix transform for the objects, but that's a little more brittle
and prone to bugs and (more importantly) slight mismatches in how I apply
the math versus how povray does it which could lead to jitters in
animations. If this were possible to do within povray, I'd prefer to do it
that way.

Thanks,
Zach


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: Can I apply the camera transform matrix to objects?
Date: 6 Sep 2005 15:10:01
Message: <web.431de8479d3b692f52d573c20@news.povray.org>
"zachrahan" <nomail@nomail> wrote:
> I'm trying to figure out a way to get some objects to always "point" at the
> camera, no matter where I move it. (Imagine an array of solar mirrors
> mounted on gimbals so that they always point at the sun.)
>
> Anyhow, I can see two ways I might do this in povray:
>
> (1) If there were some way I could obtain the camera-to-world transform
> (that is, the inverse of the world-to-camera transform, unless I've gotten
> the two backwards) and apply that to objects in the scene, then this would
> have the effect of "undoing" any camera motion so the objects always
> "point" at the camera in the same orientation.

Yes there is, but I don't have time to explain now. Sorry.
(Hopefully someone else will have time to explain.)


> (2) If there were some way to specify the orientation of objects via
> "lookat" and "sky" parameters, as you can with the camera, I could just set
> the camera and the objects to look at each other, with a common sky vector.
>
> Option 2 is neat because it's more general -- you could have objects all
> point at any arbitrary thing. However, I don't see anything like that in
> the documentation, so I assume that it's probably option 1 or nothing?

I'm not sure what you mean, but you might find some answers in my replies in
this thread:

http://news.povray.org/povray.advanced-users/thread/%3Cweb.43022440433cdf6544365ed70%40news.povray.org%3E/

From: Mike C
Subject: "Point at a vector; angles for rotation on axes X and Y /w nonzero
origin"
Date: 16 Aug 2005

--
Tor Olav
http://subcube.com


Post a reply to this message

From: zachrahan
Subject: Re: Can I apply the camera transform matrix to objects?
Date: 6 Sep 2005 16:20:01
Message: <web.431df8319d3b692fa205a1b30@news.povray.org>
"Tor Olav Kristensen" <tor### [at] REMOVETHISgmailcom> wrote:

Thanks for your reply, Tor.

> > (2) If there were some way to specify the orientation of objects via
> > "lookat" and "sky" parameters, as you can with the camera, I could just set
> > the camera and the objects to look at each other, with a common sky vector.
> >
> > Option 2 is neat because it's more general -- you could have objects all
> > point at any arbitrary thing. However, I don't see anything like that in
> > the documentation, so I assume that it's probably option 1 or nothing?
>
> I'm not sure what you mean, but you might find some answers in my replies in
> this thread:
>
>
http://news.povray.org/povray.advanced-users/thread/%3Cweb.43022440433cdf6544365ed70%40news.povray.org%3E/

Thanks for the pointer. Let me try to clarify, if I can. One of the povray
camera positioning modes allows you to specify a "look at" point and a
"sky" vector: the camera then looks down the line between the camera
position and the look-at point, and rotates about that axis such that the
"sky" vector is parallel (in the camera plane) with the camera "up"
direction. I would like to apply a transform parameterized in this way to
an object.

The gluLookAt man page has a concise description of the math for this:
http://developer.apple.com/documentation/Darwin/Reference/ManPages/man3/gluLookAt.3.html
Given that definition I see now that this can clearly be implemented
as a simple macro within povray.

I am still interested in learning how to get at the camera transform
matrix, because for my specific application that would be a lot more direct.
if anyone has any further details on how to get at this, I would really like
to know it.

Thanks,
Zach


Post a reply to this message

From: Florian Brucker
Subject: Re: Can I apply the camera transform matrix to objects?
Date: 7 Sep 2005 13:11:08
Message: <431f1f2c$1@news.povray.org>
> I am still interested in learning how to get at the camera transform
> matrix, because for my specific application that would be a lot more direct.
> if anyone has any further details on how to get at this, I would really like
> to know it.

You'll have to compute it yourself, as there's no built-in feature to 
obtain it.


Florian


Post a reply to this message

From: zachrahan
Subject: Re: Can I apply the camera transform matrix to objects?
Date: 7 Sep 2005 14:25:00
Message: <web.431f2f759d3b692fb4adc67b0@news.povray.org>
Florian Brucker <tor### [at] torfboldcom> wrote:
> > I am still interested in learning how to get at the camera transform
> > matrix, because for my specific application that would be a lot more direct.
> > if anyone has any further details on how to get at this, I would really like
> > to know it.
>
> You'll have to compute it yourself, as there's no built-in feature to
> obtain it.
>
>
> Florian

That's what I initially thought after looking carefully through the
documentation...

However, in the second message in this thread
(http://news.povray.org/web.431de8479d3b692f52d573c20%40news.povray.org ),
Tor seemed to suggest that it was indeed possible to get at this matrix.
This must be some very obscure thing if it is available at all.

Does anyone have any idea what feature Tor was referring to?

Thanks,
Zach


Post a reply to this message

From: Rune
Subject: Re: Can I apply the camera transform matrix to objects?
Date: 7 Sep 2005 16:42:49
Message: <431f50c9$1@news.povray.org>
zachrahan wrote:
> However, in the second message in this thread
> (http://news.povray.org/web.431de8479d3b692f52d573c20%40news.povray.org
> ), Tor seemed to suggest that it was indeed possible to get at this
> matrix. This must be some very obscure thing if it is available at
> all.

Well, you *can't* obtain the transform of the camera directly.

However, if you setup your camera via the macros in screen.inc (see 3.6.20.3 
screen.inc in the POV-Ray documentation) then you can access the transform, 
which will be stored in the variable Camera_Transform. (Camera_Transform is 
not documented but you can easily see it if you open screen.inc and look at 
it yourself).

You should note though that applying the camera transform to an object will 
not make the object 'point at the camera'. Instead it will make the object 
move together with the camera. When you move the camera, the object will 
follow the movement and stay in the same position on the screen. One use of 
this is to place your signature or a logo in the corner of the image.

If you want to make an object stay in the same place in your scene, but 
point at the location where the camera is, then you don't want to use the 
camera transform at all. Instead you should look at the macros 
Reorient_Trans() or Point_At_Trans() from transforms.inc (see 3.6.18 
transforms.inc in the POV-Ray documentation). You still need to know the 
location of the camera though.

Rune
-- 
3D images and anims, include files, tutorials and more:
rune|vision:  http://runevision.com
POV-Ray Ring: http://webring.povray.co.uk


Post a reply to this message

From: zachrahan
Subject: Re: Can I apply the camera transform matrix to objects?
Date: 14 Sep 2005 22:00:01
Message: <web.4328d4c09d3b692fa205a1b30@news.povray.org>
"Rune" <new### [at] runevisioncom> wrote:

> If you want to make an object stay in the same place in your scene, but
> point at the location where the camera is, then you don't want to use the
> camera transform at all. Instead you should look at the macros
> Reorient_Trans() or Point_At_Trans() from transforms.inc (see 3.6.18
> transforms.inc in the POV-Ray documentation). You still need to know the
> location of the camera though.

Good point. I've been trying to use these two macros, but they seem a bit
under-determined for my needs. These only align a single axis of an object
to point at a certain point, but the object remains free to "spin" about
that axis. I'm trying to figure out a way to also specify an "up" vector
for an object such that when the object is pointed at a given point, that
"up" vector is parallel (in the viewing plane) to the Y-axis.

That is, I'm looking for some sort of "look_at" / "up" transform for objects
that is directly analogous to that available for the camera. I tried
writing an equivalent of gluLookAt as a SDL macro, but that doesn't seem to
quite work. Does anyone have any suggestions?

Zach


Post a reply to this message

From: Rune
Subject: Re: Can I apply the camera transform matrix to objects?
Date: 15 Sep 2005 02:30:22
Message: <432914fe$1@news.povray.org>
zachrahan wrote:
> Good point. I've been trying to use these two macros, but they seem a
> bit under-determined for my needs. These only align a single axis of
> an object to point at a certain point, but the object remains free to
> "spin" about that axis. I'm trying to figure out a way to also
> specify an "up" vector for an object such that when the object is
> pointed at a given point, that "up" vector is parallel (in the
> viewing plane) to the Y-axis.
>
> That is, I'm looking for some sort of "look_at" / "up" transform for
> objects that is directly analogous to that available for the camera.
> I tried writing an equivalent of gluLookAt as a SDL macro, but that
> doesn't seem to quite work. Does anyone have any suggestions?

This is untested code, but it should work:

#include "math.inc"
#include "transforms.inc"

#macro SetLocationAndLookAt(Location,LookAt)
   #local Z = vnormalize(Location-LookAt);
   #local Y = VPerp_Adjust(y,Z);
   #local X = vcross(Y,Z);
   Matrix_Trans(X,Y,Z,Location)
#end

Rune
-- 
3D images and anims, include files, tutorials and more:
rune|vision:  http://runevision.com
POV-Ray Ring: http://webring.povray.co.uk


Post a reply to this message

From: Kenneth
Subject: Re: Can I apply the camera transform matrix to objects?
Date: 7 Oct 2005 23:20:01
Message: <web.434739d99d3b692f1b45c0860@news.povray.org>
"zachrahan" <nomail@nomail> wrote:
> I'm trying to figure out a way to get some objects to always "point" at the
> camera, no matter where I move it. (Imagine an array of solar mirrors
> mounted on gimbals so that they always point at the sun.)
>

Hi!

I've been following this news thread with great interest. I have come up
with a way to do this, that does not use any of POV's transforms or other
more advanced features (mainly because I don't yet fully understand some of
them!)   My technique simply uses some trig equations. I've tested it quite
thoroughly, and it works flawlessly.  I haven't posted it (yet) because
right now, it works ONLY if the camera is always "in front of" the object
(more specifically, the camera always has to be positioned more negatively
in the z-direction than the object.) Which means that the object will only
rotate to follow the camera if the camera's position is restricted to ONE
hemisphere. In other words, you can't spin the camera around the vertical
axis in 360 degrees, only 180 degrees. I plan on fixing this drawback, and
will post it when done.

Ken


Post a reply to this message

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