[vtkusers] Question on manual configuration of VTK camera

David Gobbi david.gobbi at gmail.com
Tue Aug 25 18:39:54 EDT 2015


Hi Naimul,

Be careful, you're not using the same definitions as one ones that I gave
in my email.

I defined the Z axis as pointing out the back of the camera, not out the
front.  That is the way the camera's local coordinate system is defined for
VTK (and for OpenGL).  So:

1) Given my definition of the zvec, the equation for the focal point should
be the following:

  camera.SetFocalPoint(pos[0] - d * zvec[0], pos[1] - d * zvec[1], pos[2] -
d * zvec[2]);

2) for the Aurora tool, if the tool's local Z axis is pointing out towards
the "focal point", then you actually want to rotate the tool's coordinate
system by 180 degrees around the tool's Y axis in order to generate local
coordinate system for the camera.

I know this is pedantic (since you end up with two 180 degree rotations
that cancel each other out), but this can be important if you want to do
any operations within the camera's coordinate system.

 - David


On Tue, Aug 25, 2015 at 2:54 PM, Naimul Khan <naim.13 at gmail.com> wrote:

> That worked, thank you so much! For anyone looking at this thread, this is
> the right solution. To add to David, in my case,  I wanted the focal point
> always at a certain distance along the camera's local Z axis. To compute
> that, just do the following in addition to what David did:
>
> camera.SetFocalPoint(pos[0] + d * zvec[0], pos[1] + d * zvec[1], pos[2] +
> d * zvec[2]);
>
> where d is the distance.
>
>
> Regards
> Naimul Mefraz Khan
>
> On Thu, Aug 20, 2015 at 11:55 AM, David Gobbi <david.gobbi at gmail.com>
> wrote:
>
>> On Thu, Aug 20, 2015 at 7:47 AM, naimulkhan <naim.13 at gmail.com> wrote:
>>
>>> hi David,
>>>
>>> I am in the same boat as the opener of this thread. I am trying to use an
>>> external tracker (NDI Aurora) to control the vtkCamera (basically "look
>>> through" the position and orientation of the tracker). I can set the
>>> position through vtkCamera::SetPosition() easily, but I am not sure what
>>> parameters SetViewUp() and SetFocusPoint() should be called with. Any
>>> help
>>> would be greatly appreciated, thanks!
>>>
>>
>> Consider: any frame of reference can be described by a point and two unit
>> vectors.  The "point" is easy, it's the camera's Position.
>>
>> The first unit vector that we will use is the camera's local Z axis,
>> which points _away_ from the focal point, i.e. it points out the back of
>> the camera.  In other words, its direction is from the FocalPoint to the
>> Position.
>>
>> The second unit vector that we will use is the camera's local Y axis.
>> This is just the ViewUp direction.
>>
>> I advise taking a look at Figure 3.9 on this web page:
>> http://www.glprogramming.com/red/chapter03.html
>>
>> So, let's say that you have a vtkTransform that describes where you want
>> to place the camera.  How can you get the position and the two vectors?
>> Easy, just apply the transform to the origin, to a unit z vector, and to a
>> unit y vector:
>>
>> double pos[3] = { 0.0, 0.0, 0.0 };
>> double zvec[3] = { 0.0, 0.0, 1.0 };
>> double yvec[3] = { 0.0, 1.0, 0.0 };
>>
>> transform->TransformPoint(pos, pos);
>> transform->TransformVector(zvec, zvec);
>> transform->TransformVector(yvec, yvec);
>>
>> That's as far as I'll go, you should be able to figure out the math for
>> computing the FocalPoint from the Position, the zvec, and the Distance from
>> the camera to the object it is looking at.
>>
>>  - David
>>
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20150825/88b250ca/attachment.html>


More information about the vtkusers mailing list