28 glMultMatrixd(gl_mat);
35 glEnable(GL_DEPTH_TEST);
36 glDisable(GL_CULL_FACE);
38 glColor3d(color[0], color[1], color[2]);
40 glVertex3f(-scale/2, -scale/2, 0.0);
41 glVertex3f(-scale/2, scale/2, 0.0);
43 glVertex3f(-scale/2, scale/2, 0.0);
44 glVertex3f( scale/2, scale/2, 0.0);
46 glVertex3f( scale/2, scale/2, 0.0);
47 glVertex3f( scale/2, -scale/2, 0.0);
49 glVertex3f( scale/2, -scale/2, 0.0);
50 glVertex3f(-scale/2, -scale/2, 0.0);
54 glColor3d(0.0, 0.0, 1.0);
56 glVertex3f(0.0, 0.0, 0.0);
57 glVertex3f(0.0, 0.0, scale);
60 glDisable(GL_DEPTH_TEST);
63 glColor3d(1.0, 0.0, 0.0);
65 glVertex3f(0.0, 0.0, 0.0);
66 glVertex3f(scale, 0.0, 0.0);
70 glColor3d(0.0, 1.0, 0.0);
72 glVertex3f(0.0, 0.0, 0.0);
73 glVertex3f(0.0, scale, 0.0);
83 cvInitMatHeader(&cv_mat, 4, 1, CV_64F, quat);
95 cvInitMatHeader(&cv_gl_mat, 4, 4, CV_64F, gl_mat); cvZero(&cv_gl_mat);
97 cvSet2D(&cv_gl_mat, 0, 3, cvScalar(flp*tra[0]));
98 cvSet2D(&cv_gl_mat, 1, 3, cvScalar(flp*tra[1]));
99 cvSet2D(&cv_gl_mat, 2, 3, cvScalar(flp*tra[2]));
100 cvSet2D(&cv_gl_mat, 3, 3, cvScalar(1));
102 cvTranspose(&cv_gl_mat, &cv_gl_mat);
109 cvInitMatHeader(&cv_gl_mat, 4, 4, CV_64F, gl_mat); cvSetIdentity(&cv_gl_mat);
112 double rot_mat_data[3][3];
113 CvMat rot_mat = cvMat(3, 3, CV_64F, rot_mat_data);
114 cvSetIdentity(&rot_mat);
118 cvInitMatHeader(&rod_mat, 3, 1, CV_64F, rod);
119 cvRodrigues2(&rod_mat, &rot_mat, 0);
123 cvmSet(&cv_gl_mat, 0, 0, cvmGet(&rot_mat, 0, 0));
124 cvmSet(&cv_gl_mat, 0, 1, cvmGet(&rot_mat, 0, 1));
125 cvmSet(&cv_gl_mat, 0, 2, cvmGet(&rot_mat, 0, 2));
126 cvmSet(&cv_gl_mat, 1, 0, cvmGet(&rot_mat, 1, 0));
127 cvmSet(&cv_gl_mat, 1, 1, cvmGet(&rot_mat, 1, 1));
128 cvmSet(&cv_gl_mat, 1, 2, cvmGet(&rot_mat, 1, 2));
129 cvmSet(&cv_gl_mat, 2, 0, cvmGet(&rot_mat, 2, 0));
130 cvmSet(&cv_gl_mat, 2, 1, cvmGet(&rot_mat, 2, 1));
131 cvmSet(&cv_gl_mat, 2, 2, cvmGet(&rot_mat, 2, 2));
134 cvSet2D(&cv_gl_mat, 0, 3, cvScalar(tra[0]));
135 cvSet2D(&cv_gl_mat, 1, 3, cvScalar(tra[1]));
136 cvSet2D(&cv_gl_mat, 2, 3, cvScalar(tra[2]));
139 cvTranspose(&cv_gl_mat, &cv_gl_mat);
165 double modelview_mat[16] = { 1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1 };
172 glutInitDisplayMode(GLUT_DEPTH | GLUT_RGB | GLUT_DOUBLE);
178 glutPositionWindow(0, 0);
182 glutPositionWindow(0,
height);
184 glEnable(GL_CULL_FACE);
185 glEnable(GL_DEPTH_TEST);
186 glEnable(GL_COLOR_MATERIAL);
188 glutMouseFunc(
Mouse);
240 glColor3f(0.5, 0.5, 1.0);
243 for(
int i = -20; i <= 20; i+=1)
245 glVertex3f((
float)i, 0.0
f, -20);
246 glVertex3f((
float)i, 0.0
f, 20);
247 glVertex3f(-20, 0.0
f, (
float)i);
248 glVertex3f( 20, 0.0
f, (
float)i);
260 glColor3f(1.0, 0.0, 0.0);
262 glVertex3f(0.0, 0.0, 0.0);
263 glVertex3f(scale, 0.0, 0.0);
265 glColor3f(0.0, 1.0, 0.0);
267 glVertex3f(0.0, 0.0, 0.0);
268 glVertex3f(0.0, scale, 0.0);
270 glColor3f(0.0, 0.0, 1.0);
272 glVertex3f(0.0, 0.0, 0.0);
273 glVertex3f(0.0, 0.0, scale);
279 static int oldx, oldy;
286 case GLUT_LEFT_BUTTON :
300 case GLUT_MIDDLE_BUTTON :
314 case GLUT_RIGHT_BUTTON :
333 Lock lock(&mutex_items);
334 for (
unsigned i = 0; i <
items.size(); ++i) {
343 glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
344 glClearColor(0.5, 0.2, 0.2, 1.0);
347 glMatrixMode(GL_PROJECTION);
351 glMatrixMode(GL_MODELVIEW);
355 glRotatef(-
elev, 1.0, 0.0, 0.0);
356 glRotatef(
azim, 0.0, 1.0, 0.0);
358 float pos[4] = {50, 0, 50};
359 glLightfv(GL_LIGHT0, GL_POSITION, pos);
371 glClearColor(0.2, 0.5, 0.2, 1.0);
372 glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
376 glMatrixMode(GL_PROJECTION);
379 glMatrixMode(GL_MODELVIEW);
389 memcpy(
proj_mat, p,
sizeof(
double)*16);
398 h = (h == 0 ? 1 : h);
417 Lock lock(&mutex_items);
423 Lock lock(&mutex_items);
424 items.push_back(item);
430 image = (
unsigned char*)_image->imageData;
437 glDepthMask(GL_FALSE);
438 glDisable(GL_DEPTH_TEST);
440 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
441 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
442 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
443 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
446 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 512, 512, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE,
image);
448 glEnable(GL_TEXTURE_2D);
450 glMatrixMode(GL_PROJECTION);
453 glOrtho(0, 1, 0, 1, 0, 1);
455 glMatrixMode(GL_MODELVIEW);
459 glTexCoord2d(0.0,1.0); glVertex2d(0.0,0.0);
460 glTexCoord2d(1.0,1.0); glVertex2d(1.0,0.0);
461 glTexCoord2d(1.0,0.0); glVertex2d(1.0,1.0);
462 glTexCoord2d(0.0,0.0); glVertex2d(0.0,1.0);
465 glDisable(GL_TEXTURE_2D);
466 glDepthMask(GL_TRUE);
467 glEnable(GL_DEPTH_TEST);
469 glMatrixMode(GL_PROJECTION);
Mutex for synchronizing multiple threads.
void Mouse(int button, int state, int x, int y)
void SetGLMatTraRod(double *tra, double *rod)
void DrawAxis(float scale)
Drawable(double _scale=1, double _r=1, double _g=1, double _b=1)
Threads vector for handling multiple threads.
static void * glut_thread(void *lpThreadParameter)
bool create(void *(*method)(void *), void *parameters)
Creates a new thread and returns true on success.
void KeyCallback(int key, int x, int y)
This file implements a parametrized rotation.
void SetColor(double _r=1, double _g=1, double _b=1)
void SetGlProjectionMatrix(double p[16])
void SetGlModelviewMatrix(double p[16])
Lock for simplifying mutex handling.
void Start(int argc, char **argv, int w, int h, float r=300.0)
void DrawableAdd(Drawable *item)
void SetGLMatTraQuat(double *tra, double *quat, bool flip=false)
virtual void DrawAxis(double scale, double color[3])
void Reshape(int w, int h)
void SetVideo(const IplImage *_image)
void SetScale(double _scale)
void GetMatrix(CvMat *mat) const
Returns the rotation in matrix form. 3x3 and 4x4 matrices are allowed.
Rotation structure and transformations between different parameterizations.
void SetQuaternion(CvMat *mat)
Sets the rotation from given quaternion.
void Motion(int x, int y)
vector< Drawable * > items