Reputation: 3143
Let A
be MATLAB's 4x4 view matrix, obtained from the view function by:
A = view;
A(1:3,1:3)
should correspond to rotation and scaling,
A(1:3,4)
should correspond to translation, and
A(4,:)
should simply be [0 0 0 1]
.
When setting the camera parameters to the following simple scenario:
camproj('orthographic')
set(gca, 'CameraPosition', [0,0,0])
set(gca, 'CameraTarget', [0,0,1])
set(gca, 'CameraUpVector', [0,1,1])
I get that A = view
is:
-1 0 0 0.5
0 1 0 -0.5
0 0 1 -0.5
0 0 0 1
Now I can't figure our where the 0.5's are coming from. Note that I set the camera position to [0,0,0] so there should be no translation.
Another peculiarity, setting the camera position to [0,0,10] by:
set(gca, 'CameraPosition', [0,0,10])
results in the A:=view matrix becoming
1 0 0 -0.5
0 1 0 -0.5
0 0 -1 5.5
0 0 0 1
So I've noticed the -0.5 has changed to 5.5 in A(3,4)
and this somehow has to do with 5 = 10 / 2.
That is, changing the camera position to [0,0,a] changes the view matrix at A(3,4)
by roughly a / 2
.
This is... weird? Peculiar? Odd?
Update: Yet another pecularity is that the determinant of A(1:3,1:3) is -1 although for a rotation matrix it should be 1. When it's -1 it means that it's not only rotation but also reflection. Why would we need reflection?
Upvotes: 12
Views: 1620
Reputation: 41
Try the same in Matlab 2013a .. you will find the results matching the expectation ...I don't know which version of Matlab you are using .. but it is certainly fixed in version 8.1
Upvotes: 1
Reputation: 5068
Not familiar with matlab, but: In 3d graphics you always distinguish between projection and camera matrices.
Projection goes from "camera space" where the camera is at zero to projective space. After the projective matrix is applied screen coordinates are computed as x' = x/w etc. So under perspective all the projective matrix does is to move z into w. In orthographic is might add z to x instead.
But it also often includes window transforms. In camera space, the camera is at 0 and looking down z, so coordinates are more -1..1. But window coordinates are 0..1, thus often a *.5, +.5 or negate etc.
The weirdness you see is by mixing camera and projection. I am sure matlab has both. Use the camera matrix to move and rotate the camera. Use the projection only for window coordinates and perspective effects.
Upvotes: 0
Reputation: 1409
My educated guess is that matlab lets you set the it as if the pixel coordinates are in the range of (-0.5*viewport size, 0.5*viewport size), but internally uses the more common pixel coordinates system in which the coordinate of each pixel is in the range of (0, viewport size).
Upvotes: 0