## unexpected artifacts with camera transform... document.SUBSCRIPTION_OPTIONS = { "thing": "thread", "subscribed": false, "url": "subscribe", "icon": { "css": "fa fa-envelope-o" } };

Help
2009-05-22
2013-04-25
• Larry Kyrala - 2009-05-22

Hi guys, maybe someone can help me here.  I have some geometry and a camera position coming from a RH system.  My camera transform seems to be pretty messed up, but I don't really know what's wrong.

I've been struggling with: LH vs RH, rowwise vs columnwise output, and the execution order of transformations before WorldBegin (does order matter here, and/or do I need to worry about ConcatTransform instead of Transform?)

Maybe someone sees something obvious?

--------- rib file ------------------
...
FrameBegin 1

# camera transformations

Projection "perspective" "fov" 9.500000

Transform [0.798635 -0.601816 0.000000 0.000000 0.300908 0.399317 -0.866025 0.000000 0.521188 0.691638 0.500000 0.000000 -193.401300 -265.154600 -220.481900 1.000000]
Translate 193.401300 265.154600 -220.481900

WorldBegin

Scale 1.000000 1.000000 -0.900000

... geometry here ...

--------- matlab calculations --------
% these are coordinates from matlab, RH native...
target = 26    26    10
camera = -193.4013 -265.1546  220.4819
up = 0     0     1

v = target - camera;
v = v/norm(v)

% get the orthonormal basis of the projection plane (su):
s = cross(v,up);
s = s/norm(s);
u = cross(s,v);
u = u/norm(u);

% i'm still not sure what the correct homogenous 4x4 transform is, it seems every book has a slightly different variation on this... perhaps it's because opengl keeps a separate transform? anyway...
m = [s 0; u 0; -v 0; camera 1]

m =

0.7986   -0.6018         0         0
0.3009    0.3993    0.8660         0
-0.5212   -0.6916    0.5000         0
-193.4013 -265.1546  220.4819    1.0000

% convert from RH to LH coordinates...
B = eye(4);
B(3,3) = -1;
% B is it's own inverse.
m = B*m*B

m =

0.7986   -0.6018         0         0
0.3009    0.3993   -0.8660         0
0.5212    0.6916    0.5000         0
-193.4013 -265.1546 -220.4819    1.0000

• Larry Kyrala - 2009-05-23

nevermind, I figured it out.  It was one of those things that makes sense in hindsight, but could have been any number of fixes...

Some things I was doing "wrong":
- translate, but the transform was already attempting to do the translate inline... I stripped this and went with the gluLookAt man page strictly. http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/glu/lookat.html

- I wasn't sure which of row-major or column-major was the correct way to dump out the transform... turns out column-major is the way to go.

- because the source system is RH, the final matrix must be transformed as above, HOWEVER, the camera vector's z coord must also be flipped before passing it to the translate.

Once I got the transform right, then the shading artifacts disappeared.