views:

52

answers:

1
+1  Q: 

Geometry -> OpenGL

Please help! =) I can't get the correct transformation in OpleGL.

I have point3D - P(X,Y,Z), and projection matrix M, which equal to K*(R|T) where

K - camera calibration matrix

alt text

(R|T) - point (object) coordinate system transformation (R - rotation matrix, T - translation vector)

As a result we have projected point as p = M*P

I know P,K,R,T, and I wont to calculate p in OpenGl terms.

In OpenCV terms it will be look as follows (little abstraction code):

CvMat* R = cvCreateMat(4,4, CV_32F, getRotationData());    
CvMat* T = cvCreateMat(4,1, CV_32F, getTranslationData());
CvMat* K = cvCreateMat(4,4, CV_32F, getCameraCalibrationData());

// (R|T)
R->data.fl[3] = T->data.fl[0];
R->data.fl[7] = T->data.fl[1];
R->data.fl[11] = T->data.fl[2];
R->data.fl[15] = T->data.fl[3];

CvMat M = cvMat(4,4, CV_32F);
// M = R*(R|T)
cvMulMat(K, R, &M);

CvMat* P = cvCreateMat(4,1, CV_32F, getTestedPoint3D());
cvMar p = cvMat(4,1, CV_32F);  // result transformation

// p = M*P
cvMulMat(&M, P, &p);

// project
float z = p.data.fl[2];
float x = p.data.fl[0] / z;
float y = p.data.fl[1] / z;

printf("Point projection [%f,%f]", x, y);
cvDrawPonit(img, cvPoint(x,y), CV_RGB(255,0,0)); /// <- !!!!

Sombody help me to translate this logic to OpenGl! =(

How could I set GL_PROJECTION and what could i do in GL_MODELVIEW mode or some else? =(

A: 

Projection depends on your camera. Use http://www.opengl.org/sdk/docs/man/xhtml/gluPerspective.xml. FoV depends on the lens used (see the doc), aspect depends on the film (probably 4:3)

model = RxT, you already know this. It's the position of the object in world space

view = Probably what you call K, but beware it's a 4x4 matrix, not a 3x3 ! It's the position and orientation of the camera in world space.

You might ask : what is World Space ? Well, it's whatever you want, provided you can express the Camera and the Object's position in these coordinates.

then projected_point = projection x view x projection x point

MODELVIEW is view x projection.

Calvin1602