0

I am now trying to change camera's view port under the given 4-by-4 matrix as

R11 R12 R13  transx
R21 R22 R23  transy
R31 R32 R33 transz
0    0    0     1

R is the 3-by-3 rotation matrix while transx, transy, transz are translations along x,y and z axis in 3D space.

My code is as following

eyex = transx;
eyey = transy;
eyez = transz;

atx = transx;
aty = transy;
atz = transz+1;

gluLookAt (R11*eyex + R12*eyey + R13*eyez, R21*eyex + R22*eyey + R23*eyez, R31*eyex + R32*eyey + R33*eyez, atx, aty, atz,  0.0, 1.0, 0.0);

However, I can't get the correct result. (Rotatation seems ok but problems occurs on translation)

Could someone can pick up the error in my code?

1
  • Just use glRotatef/glTranslatef to build your camera matrix. I like to think of this as doing everything in reverse/negative, such as moving the scene left to move a virtual camera right. If you already have a camera matrix, just use glLoadMatrixf, though if it's a world to camera matrix it'll need inverting first.
    – jozxyqk
    Commented Sep 14, 2014 at 13:52

1 Answer 1

0

Not really sure what you want to do, but you seem to be confusing issues. gluLookAt is a function that generate a cam-to-world matrix for you, by passing to the function, the eye position and a point you are looking at. So in short, it's either you use a gluLooAt to build you matrix, or you build your matrix yourself for the camera, and use it to set the OpenGL cam-to-world matrix.

In OpenGL4, this would be done on the CPU (building up that matrix) and then loading it in the vertex shader. At the end of you will to transform your object to world space, then transform the vertex in world space in camera space, and finally project using the perspective projection matrix.

You can find some info on this website: www.scratchapixel.com

Not the answer you're looking for? Browse other questions tagged or ask your own question.