Update the changelog
[opencv] / filters / CalibFilter / Calib3DWindow.cpp
1 /*M///////////////////////////////////////////////////////////////////////////////////////
2 //
3 //  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4 //
5 //  By downloading, copying, installing or using the software you agree to this license.
6 //  If you do not agree to this license, do not download, install,
7 //  copy or use the software.
8 //
9 //
10 //                        Intel License Agreement
11 //                For Open Source Computer Vision Library
12 //
13 // Copyright (C) 2000, Intel Corporation, all rights reserved.
14 // Third party copyrights are property of their respective owners.
15 //
16 // Redistribution and use in source and binary forms, with or without modification,
17 // are permitted provided that the following conditions are met:
18 //
19 //   * Redistribution's of source code must retain the above copyright notice,
20 //     this list of conditions and the following disclaimer.
21 //
22 //   * Redistribution's in binary form must reproduce the above copyright notice,
23 //     this list of conditions and the following disclaimer in the documentation
24 //     and/or other materials provided with the distribution.
25 //
26 //   * The name of Intel Corporation may not be used to endorse or promote products
27 //     derived from this software without specific prior written permission.
28 //
29 // This software is provided by the copyright holders and contributors "as is" and
30 // any express or implied warranties, including, but not limited to, the implied
31 // warranties of merchantability and fitness for a particular purpose are disclaimed.
32 // In no event shall the Intel Corporation or contributors be liable for any direct,
33 // indirect, incidental, special, exemplary, or consequential damages
34 // (including, but not limited to, procurement of substitute goods or services;
35 // loss of use, data, or profits; or business interruption) however caused
36 // and on any theory of liability, whether in contract, strict liability,
37 // or tort (including negligence or otherwise) arising in any way out of
38 // the use of this software, even if advised of the possibility of such damage.
39 //
40 //M*/// Calib3DWindow.cpp: implementation of the CCalib3DWindow class.
41 //
42 //////////////////////////////////////////////////////////////////////
43
44 //#include "CalibFilterprop.h"
45 //#include "calibfilterprop.h"
46 #include "CV.h"
47 #include "Calib3DWindow.h"
48 #include <stdio.h >
49
50 #ifdef _DEBUG
51 #define new DEBUG_NEW
52 #endif
53
54 extern HINSTANCE g_hInst;
55
56 static LRESULT CALLBACK MyWindowProc( HWND m_hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
57 {
58     long data = ::GetWindowLong(m_hwnd,GWL_USERDATA);
59     if( data == 0)
60     {
61         return DefWindowProc( m_hwnd, uMsg, wParam, lParam);
62     }
63     else
64     {
65         return ((CCalib3DWindow*)data)->WindowProc( m_hwnd, uMsg, wParam, lParam);
66     }
67 }
68
69 //////////////////////////////////////////////////////////////////////
70 // Construction/Destruction
71 //////////////////////////////////////////////////////////////////////
72 static const char* _3DWindowClass = "3DWindow";
73
74 CCalib3DWindow::CCalib3DWindow()
75 {
76     /* Create window and show it */
77     m_haveParams = false;
78     m_alpha = 0;
79     m_beta = 0;
80     
81     m_baseAlpha = 0;
82     m_baseBeta = 0;
83     m_holdLMouse = 0;
84     m_holdRMouse = 0;
85
86     m_baseScale = 0.02f;
87     m_scale = 0.0;
88
89     /* Register window class */
90     WNDCLASSEX wndclass;
91
92     wndclass.cbSize         = sizeof(WNDCLASSEX);
93     wndclass.style          = CS_DBLCLKS;
94     wndclass.lpfnWndProc    = MyWindowProc; 
95     wndclass.cbClsExtra     = 0;
96     wndclass.cbWndExtra     = 0;
97     wndclass.hInstance      = g_hInst; 
98     wndclass.hIcon          = 0;
99     wndclass.hCursor        = 0;
100     wndclass.hbrBackground  = 0;
101     wndclass.lpszMenuName   = 0;
102     wndclass.lpszClassName  = _3DWindowClass; 
103     wndclass.hIconSm        = 0; 
104
105     m_hwnd = 0;
106     m_hdc = 0;
107     m_hglrc = 0;
108
109     RegisterClassEx(&wndclass);
110
111     DWORD dwStyle = WS_BORDER |
112                     WS_CAPTION |
113                     WS_MAXIMIZEBOX |
114                     WS_MINIMIZEBOX |
115                     WS_VISIBLE |
116                     WS_THICKFRAME |
117                     WS_CLIPCHILDREN |
118                     WS_CLIPSIBLINGS;
119
120     m_hwnd = CreateWindowEx(  0,              // extended window style
121                             _3DWindowClass, // pointer to registered class name
122                             "3D Window",    // pointer to window name
123                             dwStyle,        // window style
124                             100,            // horizontal position of window
125                             100,            // vertical position of window
126                             200,            // window width
127                             200,            // window height
128                             0,              // handle to parent or owner window
129                             0,              // handle to menu, or child-window identifier
130                             g_hInst,        // handle to application instance
131                             0 );            // pointer to window-creation data
132
133     if( m_hwnd == 0 )
134     {
135         int error = GetLastError();
136         char st[100];
137         sprintf(st,"Can't create window.\nError = %d",error);
138         MessageBox(0,st,"Error",MB_OK);
139     }
140     else
141     {
142     /*  Set OpenGL Formats */
143         int iPixelType = PFD_TYPE_RGBA;
144     
145         DWORD dwFlag =  PFD_DOUBLEBUFFER |
146                         PFD_SUPPORT_OPENGL |
147                         PFD_DRAW_TO_WINDOW;
148
149         PIXELFORMATDESCRIPTOR pfd;
150         memset(&pfd,0,sizeof(PIXELFORMATDESCRIPTOR));
151
152         pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
153         pfd.nVersion = 1;
154         pfd.dwFlags = dwFlag;
155         pfd.iPixelType = (uchar)iPixelType;
156
157         pfd.cColorBits = 24;
158         pfd.cAlphaBits = 32;
159         pfd.cAccumBits = 32;
160         pfd.cDepthBits = 32;
161         pfd.cStencilBits = 32;
162         pfd.iLayerType = PFD_MAIN_PLANE;
163
164         m_hdc = GetDC( m_hwnd );
165
166         int nPixelFormat = ChoosePixelFormat( m_hdc, &pfd );
167
168         if (nPixelFormat == 0) {
169             MessageBox(0,"Error Choose pixel formar","Info",MB_OK);
170         }
171
172         BOOL dResult = SetPixelFormat( m_hdc, nPixelFormat, &pfd );
173
174         if ( !dResult) {
175             MessageBox(0,"Error Set pixel formar","Info",MB_OK);
176         }
177     
178         m_hglrc = wglCreateContext( m_hdc );
179
180         if( m_hglrc == 0 ) {
181             MessageBox(0,"Error Create wgl Context","Info",MB_OK);
182         }
183
184         BOOL err = wglMakeCurrent(m_hdc,m_hglrc);
185
186         if (err==FALSE) {
187             MessageBox(0,"Error Make wgl Context","Info",MB_OK);
188         }
189         /*---------------------*/
190
191         ::SetWindowLong(m_hwnd,GWL_USERDATA,(long)this);
192     }
193 }
194
195 CCalib3DWindow::~CCalib3DWindow()
196 {
197     int result, error;
198     result = wglMakeCurrent( 0, 0 );
199     error = GetLastError();
200     result = wglDeleteContext( m_hglrc );
201     error = GetLastError();
202     result = ReleaseDC( m_hwnd, m_hdc );
203     error = GetLastError();
204     result = ShowWindow( m_hwnd, SW_HIDE );
205     error = GetLastError();
206     result = DestroyWindow( m_hwnd );
207     error = GetLastError();
208     if( !result )
209     {
210         char st[100];
211         sprintf(st,"Can't register class.\nError = %d",error);
212         MessageBox(0,st,"Error",MB_OK);
213     }
214     m_hglrc = 0;
215     m_hdc = 0;
216     m_hwnd = 0;
217 }
218
219 LRESULT CALLBACK CCalib3DWindow::WindowProc( HWND /*hwnd*/, UINT uMsg,
220                                              WPARAM wParam, LPARAM lParam )
221 {
222     int fwKeys = wParam; /* key flags */
223     CvPoint pt = cvPoint( LOWORD(lParam), HIWORD(lParam)); /* cursor position */
224         //int width  = LOWORD(lParam);
225         //int height = HIWORD(lParam);
226
227     switch( uMsg )
228     {        
229     case WM_PAINT:
230         {
231             OnPaint();
232             return 0;
233         }
234
235     case WM_SIZE:
236         {
237                         Resize();
238             ///OnPaint();
239             return 0;
240         }
241
242     case WM_LBUTTONDOWN:
243         {
244             OnLButtonDown( pt, fwKeys );
245             return 0;
246         }
247     case WM_LBUTTONUP:
248         {
249             OnLButtonUp( pt, fwKeys );
250             return 0;
251         }
252     case WM_RBUTTONDOWN:
253         {
254             OnRButtonDown( pt, fwKeys );
255             return 0;
256         }
257     case WM_RBUTTONUP:
258         {
259             OnRButtonUp( pt, fwKeys );
260             return 0;
261         }
262     case WM_MOUSEMOVE:
263         {
264             OnMouseMove( pt, fwKeys );
265             return 0;
266         }
267     case WM_CLOSE:
268         {
269             CloseWindow( m_hwnd );
270             PostQuitMessage(0);
271             return 0;
272         }
273     }
274
275     return DefWindowProc( m_hwnd, uMsg, wParam, lParam);
276 }
277
278
279 void CCalib3DWindow::SetParams( CvCameraParams* camera,
280                                 CvSize etalonSize, float squareSize )
281 {
282     if( camera )
283     {
284         m_camera = *camera;
285         m_etalonSize = etalonSize;
286         m_squareSize = squareSize;
287     }
288     m_haveParams = camera != 0;
289     
290     InvalidateRect( m_hwnd, 0, FALSE );
291     UpdateWindow( m_hwnd );
292 }
293
294 void CCalib3DWindow::OnPaint()
295 {
296     PAINTSTRUCT ps;
297
298     BeginPaint( m_hwnd, &ps );
299
300     /* 115 180 251*/
301     glClearColor(0.45f,0.705f,0.984f,1.0f);
302     glEnable(GL_DEPTH_TEST);
303     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
304
305     /* ========= Begin draw the etalon position ========= */
306     if( m_hwnd && m_haveParams && IsWindowVisible( m_hwnd ))
307     {
308         int   numX = m_etalonSize.width - 1;
309         int   numY = m_etalonSize.height - 1;
310         
311         //float minX,minY,minZ,maxZ;
312         float floorHeight = 6;
313
314 /*        minX = -20;
315         minY = -20;
316         minZ = 0;
317
318         maxX = 20;
319         maxY = 20;
320         maxZ = 80;*/
321
322         float x1,y1,z1;
323         float x2,y2,z2;
324         float x3,y3,z3;
325         float x4,y4,z4;
326         float x5,y5,z5;
327         float x6,y6,z6;
328         float x7,y7,z7;
329         float x8,y8,z8;
330         float yfloor;
331
332         float Box_W;
333         float Box_H;
334         float Box_L;
335
336         CvMat  Points = cvMat( numX * numY, 3, CV_MAT32F, 0 );
337         CvMat  objPoint = cvMat( 3, 1, CV_MAT32F, 0 );
338         CvMat  objPoints = cvMat( numX * numY, 3, CV_MAT32F, 0 );
339         CvMat  tmp3 = cvMat( 3, 1, CV_MAT32F, 0 );
340         CvMat  Point = cvMat( 3, 1, CV_MAT32F, 0 );
341         CvMat  cameraMatr = cvMat( 3, 3, CV_MAT32F, m_camera.rotMatr );
342         CvMat  transVect = cvMat( 3, 1, CV_MAT32F, m_camera.transVect );
343
344         int   t,k,index;
345         int   etalonNum;
346
347         cvmAlloc( &objPoints );
348         cvmAlloc( &Points );
349         cvmAlloc( &objPoint );
350         cvmAlloc( &tmp3 );
351         cvmAlloc( &Point );
352
353         etalonNum = numX * numY;
354         /* Fill etalon coordinates */
355         for( t = 0; t < numY; t++ )
356         {
357             for ( k = 0; k < numX; k++)
358             {
359                 index = t * numX + k;
360                 objPoints.data.fl[index * 3 + 0] = k * m_squareSize;
361                 objPoints.data.fl[index * 3 + 1] = t * m_squareSize;
362                 objPoints.data.fl[index * 3 + 2] = 0;
363             }
364         }
365         
366         Box_W = 40;
367         Box_H = 40;
368         Box_L = 80;
369         
370         x1 =  Box_W / 2;
371         y1 = -Box_H / 2;
372         z1 =  0;
373
374         x2 = -Box_W / 2;
375         y2 = -Box_H / 2;
376         z2 =  0;
377
378         x3 =  Box_W / 2;
379         y3 =  Box_H / 2;
380         z3 =  0;
381
382         x4 = -Box_W / 2;
383         y4 =  Box_H / 2;
384         z4 =  0;
385         
386         x5 =  Box_W / 2;
387         y5 = -Box_H / 2;
388         z5 =  Box_L;
389         
390         x6 = -Box_W / 2;
391         y6 = -Box_H / 2;
392         z6 =  Box_L;
393
394         x7 =  Box_W / 2;
395         y7 =  Box_H / 2;
396         z7 =  Box_L;
397         
398         x8 = -Box_W / 2;
399         y8 =  Box_H / 2;
400         z8 =  Box_L;
401
402         floorHeight = Box_H / 6;
403
404         yfloor = - Box_H /2 - floorHeight;
405
406         glMatrixMode(GL_PROJECTION);
407
408         glLoadIdentity();
409         glDepthRange(0,1.0);
410
411         glOrtho(    -1,1,
412                     -1,1,
413                     -10,10);
414
415         glRotatef(m_baseAlpha + m_alpha,0,1,0);
416         glRotatef(m_baseBeta + m_beta,1,0,0);
417         
418         float setScale;
419         setScale = m_baseScale + m_scale;
420         
421         glScalef(   setScale,
422                     setScale,
423                     setScale);
424
425         glTranslatef(0, 0,- Box_L / 2.0f);
426
427         /* Draw the room */
428         
429         glBegin(GL_LINE_STRIP);
430         glColor3f(1,0,0);
431         glVertex3f(x1,y1,z1);
432         glVertex3f(x3,y3,z3);
433         glVertex3f(x4,y4,z4);
434         glVertex3f(x2,y2,z2);
435         glVertex3f(x1,y1,z1);
436         glVertex3f(x5,y5,z5);
437         glVertex3f(x6,y6,z6);
438         glVertex3f(x8,y8,z8);
439         glVertex3f(x7,y7,z7);
440         glVertex3f(x5,y5,z5);
441         
442         glEnd();
443
444         glBegin(GL_LINES);
445
446         glVertex3f(x3,y3,z3);
447         glVertex3f(x7,y7,z7);
448         
449         glVertex3f(x4,y4,z4);
450         glVertex3f(x8,y8,z8);
451
452         glVertex3f(x2,y2,z2);
453         glVertex3f(x6,y6,z6);
454
455         glEnd();
456
457         /* Draw floor for the room */
458
459         /*  First draw the lines */
460         glBegin(GL_LINES);
461         glColor3f(0.0,1.0,0.0);
462         glVertex3f(x1,y1,z1);
463         glVertex3f(x5,y5,z5);
464
465         glVertex3f(x5,y5,z5);
466         glVertex3f(x6,y6,z6);
467
468         glVertex3f(x6,y6,z6);
469         glVertex3f(x2,y2,z2);
470
471         glVertex3f(x2,y2,z2);
472         glVertex3f(x1,y1,z1);
473
474         glVertex3f(x1,y1,z1);
475         glVertex3f(x1,yfloor,z1);
476
477         glVertex3f(x1,yfloor,z1);
478         glVertex3f(x5,yfloor,z5);
479
480         glVertex3f(x5,yfloor,z5);
481         glVertex3f(x6,yfloor,z6);
482
483         glVertex3f(x6,yfloor,z6);
484         glVertex3f(x2,yfloor,z2);
485
486         glVertex3f(x2,yfloor,z2);
487         glVertex3f(x1,yfloor,z1);
488         glVertex3f(x2,y2,z2);
489         glVertex3f(x2,yfloor,z2);
490         glVertex3f(x6,y6,z6);
491         glVertex3f(x6,yfloor,z6);
492         glVertex3f(x5,y5,z5);
493         glVertex3f(x5,yfloor,z5);
494         glEnd();
495
496         /* Draw floor under floor */
497         glBegin(GL_QUADS);
498         glColor3f(0.0f, 0.6f, 1.1f);
499
500         glVertex3f(x1,yfloor,z1);
501         glVertex3f(x5,yfloor,z5);
502         glVertex3f(x6,yfloor,z6);
503         glVertex3f(x2,yfloor,z2);
504         glEnd();
505
506         /* Draw walls under floor */
507         glBegin(GL_QUADS);
508         glColor3f(0.0f,0.3f,0.5f);
509
510         glVertex3f(x1,y1,z1);
511         glVertex3f(x5,y5,z5);
512         glVertex3f(x5,yfloor,z5);
513         glVertex3f(x1,yfloor,z1);
514
515         glVertex3f(x5,y5,z5);
516         glVertex3f(x6,y6,z6);
517         glVertex3f(x6,yfloor,z6);
518         glVertex3f(x5,yfloor,z5);
519
520         glVertex3f(x2,y2,z2);
521         glVertex3f(x6,y6,z6);
522         glVertex3f(x6,yfloor,z6);
523         glVertex3f(x2,yfloor,z2);
524
525         glVertex3f(x1,y1,z1);
526         glVertex3f(x2,y2,z2);
527         glVertex3f(x2,yfloor,z2);
528         glVertex3f(x1,yfloor,z1);
529
530         glEnd();
531
532
533         /* Draw the camera */
534         float camX0,camX1,camX2,camX3,camX4;
535         float camY0,camY1,camY2,camY3,camY4;
536         float camZ0,camZ1,camZ2,camZ3,camZ4;
537
538         camX0 =  0.0; camY0 =  0.0; camZ0 = 0.0;
539         camX1 = -1.0; camY1 =  1.0; camZ1 = 4.0;
540         camX2 =  1.0; camY2 =  1.0; camZ2 = 4.0;
541         camX3 =  1.0; camY3 = -1.0; camZ3 = 4.0;
542         camX4 = -1.0; camY4 = -1.0; camZ4 = 4.0;
543 /*
544         glBegin(GL_TRIANGLE_FAN);
545         glVertex3f(camX0,camY0,camZ0);
546         glVertex3f(camX1,camY1,camZ1);
547         glVertex3f(camX2,camY2,camZ2);
548         glVertex3f(camX3,camY3,camZ3);
549         glVertex3f(camX4,camY4,camZ4);
550         glEnd();
551 */        
552         glBegin(GL_LINE_STRIP);
553         glColor3f(1.0,0.0,0.0);
554         glVertex3f(camX0,camY0,camZ0);
555         glVertex3f(camX1,camY1,camZ1);
556         glVertex3f(camX2,camY2,camZ2);
557         glVertex3f(camX3,camY3,camZ3);
558         glVertex3f(camX4,camY4,camZ4);
559         glVertex3f(camX1,camY1,camZ1);
560         glEnd();
561         
562         glBegin(GL_LINES);
563         glVertex3f(camX0,camY0,camZ0);
564         glVertex3f(camX2,camY2,camZ2);
565         glVertex3f(camX0,camY0,camZ0);
566         glVertex3f(camX3,camY3,camZ3);
567         glVertex3f(camX0,camY0,camZ0);
568         glVertex3f(camX4,camY4,camZ4);
569         glEnd();
570
571         /* draw direct to ground */
572
573         glBegin(GL_LINES);
574         glVertex3f(0,0,0);
575         glVertex3f(0,-Box_H/2,0);
576         glEnd();
577
578         /* Draw flat ground */
579
580         glBegin(GL_QUADS);
581         glColor3f(1.0f, 0.6f, 0.1f);
582
583         //glShadeModel(GL_FLAT);
584
585         glVertex3f(x1,y1,z1);
586         glVertex3f(x5,y5,z5);
587         glVertex3f(x6,y6,z6);
588         glVertex3f(x2,y2,z2);
589         glEnd();
590         
591         /* Convert Points */
592
593         for( t = 0; t < etalonNum; t++) {
594         
595             objPoint.data.fl[0] = objPoints.data.fl[t * 3 + 0];
596             objPoint.data.fl[1] = objPoints.data.fl[t * 3 + 1];
597             objPoint.data.fl[2] = objPoints.data.fl[t * 3 + 2];
598
599             cvmMul( &cameraMatr, &objPoint, &tmp3 );
600             
601             cvmAdd( &tmp3, &transVect, &Point );
602
603             // MirrorPoints !!!
604             Points.data.fl[t*3+0] = -Point.data.fl[0];
605             Points.data.fl[t*3+1] = -Point.data.fl[1];
606             Points.data.fl[t*3+2] =  Point.data.fl[2];
607         }
608
609         
610         /* Draw Object */
611         glBegin(GL_QUADS);
612
613         /* Draw black and white quads */
614         float   xq[4];//1,xq2,xq3,xq4;
615         float   yq[4];//1,yq2,yq3,yq4;
616         float   zq[4];//,zq2,zq3,zq4;
617
618         int     inds[4];//1,ind2,ind3,ind4;
619         int     curr;
620
621         for(t = 0; t < numY - 1; t++)
622         {
623             for(k = 0; k < numX - 1; k++)
624             {
625                 inds[0] = t * numX + k;
626                 inds[1] = inds[0] + 1;
627                 inds[2] = inds[0] + numX + 1;
628                 inds[3] = inds[0] + numX;
629
630                 for( curr = 0; curr < 4; curr++ )
631                 {
632                     xq[curr] = Points.data.fl[inds[curr] * 3 + 0];
633                     yq[curr] = Points.data.fl[inds[curr] * 3 + 1];
634                     zq[curr] = Points.data.fl[inds[curr] * 3 + 2];
635                 }
636
637                 if( (t + k & 1) == 1 )
638                 {
639                     glColor3f(0.1f, 0.1f, 0.1f);
640                 }
641                 else
642                 {
643                     glColor3f(1.0f, 1.0f, 1.0f);
644                 }
645
646                 for( curr = 0; curr < 4; curr++ )
647                 {
648                     glVertex3f(xq[curr],yq[curr],zq[curr]);
649                 }
650             }
651         }
652
653         glEnd();
654
655         cvmFree(&objPoints);
656
657         cvmFree(&Points   );
658         cvmFree(&objPoint );
659         cvmFree(&tmp3     );
660         cvmFree(&Point    );
661     }
662
663     glFinish();
664     glFlush();
665     
666     SwapBuffers(m_hdc);
667
668     EndPaint( m_hwnd, &ps );
669
670 }/* OnPaint */
671
672
673 void CCalib3DWindow::OnLButtonDown( CvPoint pt, int /*fwKeys*/)
674 {
675     m_oldLPoint = pt;
676     SetCapture(m_hwnd);
677     
678     m_alpha = 0.0;
679     m_beta = 0.0;
680
681     m_holdLMouse = true;
682     InvalidateRect( m_hwnd, 0, FALSE );
683     UpdateWindow( m_hwnd );
684 }
685
686 void CCalib3DWindow::OnLButtonUp( CvPoint /*pt*/, int /*fwKeys*/)
687 {
688     ReleaseCapture();
689     m_holdLMouse = false;
690     m_baseAlpha += m_alpha;
691     m_baseBeta += m_beta;
692     m_alpha = 0.0;
693     m_beta = 0.0;
694     InvalidateRect( m_hwnd, 0, FALSE );
695     UpdateWindow( m_hwnd );
696 }
697
698 void CCalib3DWindow::OnRButtonDown( CvPoint pt, int /*fwKeys*/)
699 {
700     m_oldRPoint = pt;
701     SetCapture(m_hwnd);
702
703     m_holdRMouse = true;
704
705     m_scale = 0.0;
706     InvalidateRect( m_hwnd, 0, FALSE );
707     UpdateWindow( m_hwnd );
708 }
709
710 void CCalib3DWindow::OnRButtonUp( CvPoint /*pt*/, int /*fwKeys*/)
711 {
712     ReleaseCapture();
713     m_holdRMouse = false;
714     
715     m_baseScale += m_scale;
716     if( m_baseScale <= 0.0) m_baseScale = 0.0;
717     m_scale = 0.0;
718     InvalidateRect( m_hwnd, 0, FALSE );
719     UpdateWindow( m_hwnd );
720 }
721
722 void CCalib3DWindow::OnMouseMove( CvPoint pt, int /*fwKeys*/)
723 {
724     if( m_holdLMouse )
725     {
726         RECT rect;
727         GetClientRect( m_hwnd, &rect );
728         float width  = (float)(rect.right  - rect.left);
729         float height = (float)(rect.bottom - rect.top);
730
731         float dx = (float)( pt.x - m_oldLPoint.x );
732         float dy = (float)( pt.y - m_oldLPoint.y );
733         m_alpha = (dx / width)  * 360;
734         m_beta = (dy / height) * 360;
735     }
736
737     if( m_holdRMouse )
738     {
739         RECT rect;
740         GetClientRect( m_hwnd, &rect );
741         float height = (float)(rect.bottom - rect.top);
742         float dy = (float)(pt.y - m_oldRPoint.y);
743         m_scale = (float)((dy/height)*0.1);
744     }
745     
746     InvalidateRect( m_hwnd, 0, FALSE );
747     UpdateWindow( m_hwnd );
748 }
749
750 void CCalib3DWindow::Show( bool show )
751 {
752     ShowWindow( m_hwnd, show ? SW_SHOWNORMAL : SW_HIDE );
753 }
754
755 /* End of file. */
756
757 void CCalib3DWindow::Resize()
758 {
759     RECT rect;
760     GetClientRect( m_hwnd, &rect );
761
762         glViewport(0,0,rect.right - rect.left,rect.bottom - rect.top);
763         OnPaint();
764 }