[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Implementing view
Re: Implementing view
Tue, 9 Nov 2010 08:24:36 +0000
2010/11/8 Jordi Gutiérrez Hermoso <address@hidden>:
> 2010/11/8 logari81 <address@hidden>:
>> Hi, have you seen the following matlab documentation?
>> it seems quite complete.
> Yes, but they only describe in broad strokes how T is built. I'm
> trying to reverse engineer it based on what people tell me that Matlab
> does. Or do you understand why the transformation matrix includes
> translations? That page doesn't explain it.
>> If I 've understood right, the only feature
>> missing in the actual view implementation in octave is the possibility
>> of returning the transformation matrix T. Is this correct?
> It was also missing the ability to specify views by direction vectors
> instead of azimuth and elevation, but that was quite easy to
> - Jordi G. H.
The computation of the complete transformation matrix is a complex beast
and it took me a while to reverse engineer it. The current code is in
axes::properties::update_camera. I wrote this a while ago and I don't remember
all the details, but the full transformation includes:
- plot box normalization:
. translate to plot box origin
. scale x/y/z to unity
- translate to plot box center
- scale according to dataaspectratio and/or plotboxaspectratio
- translate to camera position
- apply projection (ortho or perspective)
- stretch to fit axes allocated position
- map to viewport:
. scale to viewport size
. translate to viewport origin
The full transformation is decomposed in several matrices that are
accessible as hidden properties of the axes object:
- x_normrendertransform: combination of the 3 above, mapping the unit
cube to window coordinates
- x_rendertransform: full matrix, mapping data coordinates to window coordinates
The fact that translation changes when you change axis rotation is
normal as the camera
is positioned outside the axes object (otherwise some objects would be
behind you and you
wouldn't see them). By experimentation (and luck), I determined that
the camera is automatically
positioned at 5*diag(plot box) from the plot box center (iirc), in
Hope this helps.