Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 82.33 KB | None | 0 0
  1. // OpenGLWnd.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5.  
  6. #include "OpenGLWndFaceTracker.h"
  7. #include "MainFrm.h"
  8. #include "VRMLFitToScreenTraverser.h"
  9. #include <process.h>
  10. #include <gl\glaux.h>
  11.  
  12.  
  13. #include <assert.h>
  14. #include  <math.h>
  15. #include  <stdlib.h>
  16.  
  17. #include <sys/timeb.h>
  18. #include <sys/types.h>
  19.  
  20. #include <iostream>
  21. #include <fstream>
  22.  
  23. //#include "DialogShapeManager.h"
  24. #include "DialogNew.h"
  25.  
  26. #include "glut.h"
  27.  
  28.  
  29. #ifdef _DEBUG
  30. #define new DEBUG_NEW
  31. #undef THIS_FILE
  32. static char THIS_FILE[] = __FILE__;
  33. #endif
  34.  
  35. #define ANIM_VIEW_SIZE 0.35
  36. #define SLIDER_RESOLUTION 200
  37.  
  38.  
  39. /////////////////////////////////////////////////////////////////////////////
  40. // COpenGLWnd
  41.  
  42.     // -------------------------------------------------
  43.     // My own code
  44.     // -------------------------------------------------
  45.  
  46. const int COpenGLWnd::mTIMER_RENDERING_INTERVAL = 20;
  47. const int COpenGLWnd::mTIMER_ROTATE_INTERVAL = 30;
  48.  
  49.  
  50. void COpenGLWnd::Init(VRMLModel *theModel)
  51. {
  52.     SetContext();
  53.     BaseOGLVRMLModelRenderer::Init(theModel);
  54.  
  55.     glShadeModel(GL_SMOOTH);                            // Enable Smooth Shading
  56.    
  57.     glClearColor(0.0f, 0.0f, 0.0f, 0.5f);               // Black Background
  58.     glClearDepth(1.0f);                                 // Depth Buffer Setup
  59.     glEnable(GL_DEPTH_TEST);                            // Enables Depth Testing
  60.     glDepthFunc(GL_LEQUAL);                             // The Type Of Depth Testing To Do
  61.    
  62.     // glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);   // Really Nice Perspective Calculations
  63.    
  64.     // For performance we set all of these to fastest.
  65.     glHint(GL_LINE_SMOOTH_HINT, GL_FASTEST);
  66.     glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
  67.     glHint(GL_POINT_SMOOTH_HINT, GL_FASTEST);
  68.     glHint(GL_POLYGON_SMOOTH_HINT, GL_FASTEST);
  69.    
  70.     // Can't assume that normals aren't scaled. Therefore I need this.
  71.     glEnable(GL_NORMALIZE);
  72.    
  73.     // Reset modelview matrix before getting coords.
  74.     glMatrixMode(GL_MODELVIEW);
  75.     glLoadIdentity();
  76.    
  77.     // Retrieve max and min in all axes and also the worl-transformed coordinates in a vector.
  78.     VRMLFitToScreenTraverser *tempFitter = new VRMLFitToScreenTraverser;
  79.    
  80.     tempFitter->Reset();
  81.     theModel->traverse(theModel->rootNode, tempFitter);
  82.     GLfloat sceneMinX, sceneMaxX, sceneMinY, sceneMaxY, sceneMinZ, sceneMaxZ;
  83.     tempFitter->GetCoords(sceneMinX, sceneMaxX, sceneMinY, sceneMaxY, sceneMinZ, sceneMaxZ, mMaxRadius);
  84.    
  85.     GLfloat distance = (GLfloat)((mMaxRadius / 2.0) / mVGLR_PERSPECT_TAN_FOVY);
  86.    
  87.     // Make this constant.
  88.     mFarPlane = distance * 10;
  89.    
  90.     mXTranslateFit = - (GLfloat)((sceneMinX + (abs(sceneMaxX - sceneMinX) / 2.0)));
  91.     mYTranslateFit = - (GLfloat)((sceneMinY + (abs(sceneMaxY - sceneMinY) / 2.0)));
  92.     mZTranslateFit = - (GLfloat)((distance + (abs(sceneMinZ - sceneMaxZ) / 2.0)));
  93.    
  94.     mXTranslate = mXTranslateFit;
  95.     mYTranslate = mYTranslateFit;
  96.     mZTranslate = mZTranslateFit;
  97.    
  98.     // Translate and zoom acceleration depends on size of model.
  99.     mXAccel = (GLfloat)(fabs(sceneMinX - sceneMaxX) * 0.005);
  100.     mYAccel = (GLfloat)(fabs(sceneMinX - sceneMaxX) * 0.005);
  101.     mZAccel = (GLfloat)(fabs(sceneMinZ - sceneMaxZ) * 0.005);
  102.     Accel = (GLfloat)(2 * 0.005);
  103.    
  104.     delete tempFitter;
  105.    
  106.     SetRenderingMode(mRenderingMode);
  107.    
  108.     if(mWindowWidth && mWindowHeight)
  109.         ReSizeGLScene(mWindowWidth, mWindowHeight);
  110.     SwapGLBuffers();
  111. }
  112.  
  113.  
  114. /**
  115. * Render all attached VRML models to screen using OpenGL commands.
  116. * The actual rendering is implemented in VRMLRenderer, the parent class.
  117. *
  118. * This function is called automatically by OnTimer() so only in special occassions it may
  119. * be interesting to call it directly. One such occassion is just after a textured model is loaded
  120. * in order to enforce loading of textures. In fact, when the VRMLModel is loaded from a file the
  121. * texture file names are stored but texture images are not actually loaded. This is done by the
  122. * renderer when it renders the textured model first time. That can take some time, and it may be desirable
  123. * to call RenderToScreen() and thus force the loading of textures. The function will return after the
  124. * textures are loaded and the models rendered.
  125. */
  126. void COpenGLWnd::RenderToScreen()
  127. {
  128.     static CMainFrame* pMainWnd = 0;
  129.     struct _timeb timebuffer;
  130.    
  131.     _ftime( &timebuffer );
  132.    
  133.     long current_time = 1000 * (long)timebuffer.time + timebuffer.millitm;  //CHANGED BY I.K. added explicit cast
  134.     static long last_times[50];
  135.     static int cnt = -1;
  136.  
  137.  
  138.     if(rendererBusy)   // a simple mechanism to make sure that we do not draw again before last rendering is done
  139.     {
  140.         return;
  141.     }
  142.     rendererBusy = true;
  143.  
  144.     SetContext();
  145.  
  146.    
  147.    
  148.     if(cnt == -1)
  149.     {
  150.         cnt = 0;
  151.         for(int i=0;i<10;i++)
  152.             last_times[i]=0;
  153.     }
  154.     cnt++;
  155.     if(cnt == 50) cnt = 0;
  156.    
  157.     renderingFrameRate = 50000.0f / (float)(current_time - last_times[cnt]);
  158.    
  159.     last_times[cnt] = current_time;
  160.    
  161.     glMatrixMode(GL_MODELVIEW);
  162.     if(modelViewMatrix)
  163.     {
  164.         glLoadMatrixf(modelViewMatrix);
  165.     }
  166.     else
  167.     {
  168.         glLoadIdentity();
  169.        
  170.         glTranslatef(mXTranslate, mYTranslate, mZTranslate);
  171.         glRotatef(mXRotAngle, 1.0f, 0.0f, 0.0f);
  172.         glRotatef(mYRotAngle, 0.0f, 1.0f, 0.0f);
  173.     }
  174.  
  175.     BaseOGLVRMLModelRenderer::RenderToScreen();
  176.    
  177.    
  178.     SwapGLBuffers();
  179.  
  180.     rendererBusy = false;
  181.  
  182. /*  // display the frame rate
  183.     if(!pMainWnd) pMainWnd = (CMainFrame*)AfxGetMainWnd();
  184.     char tmpmsg[100];
  185.     sprintf(tmpmsg,"%2.2f FPS",renderingFrameRate);
  186.     pMainWnd->m_wndStatusBar.SetPaneText( 0, tmpmsg, TRUE );*/
  187. }
  188.  
  189. /**
  190. * Close down the renderer.
  191. * Tidy up and close the rendering system.
  192. */
  193. void COpenGLWnd::Close()
  194. {
  195.     // Kill any pending timers.
  196.     KillTimer(ID_ROTATE);
  197.    
  198.     SetContext();
  199.  
  200.     mXAccel = mYAccel = mZAccel = 0;
  201.  
  202.     mXTranslate = 0;
  203.     mYTranslate = 0;
  204.     mZTranslate = 0;
  205.  
  206.     mXRotAngle = 0;
  207.     mYRotAngle = 0;
  208.  
  209.  
  210.     BaseOGLVRMLModelRenderer::Close();
  211.     SwapGLBuffers();
  212. }
  213.  
  214.  
  215.    
  216.     // -------------------------------------------------
  217.     // VisualC++ added code below
  218.     // -------------------------------------------------
  219.  
  220. IMPLEMENT_DYNCREATE(COpenGLWnd, CView)
  221.  
  222. COpenGLWnd::COpenGLWnd()
  223.  
  224. : otvoren_dialog(false)
  225.  
  226. {
  227.     m_ToolTip.Create(this);
  228.    
  229.     mLeftButtonDown = false;
  230.     mRightButtonDown = false;
  231.     m_bTimerSet = false;
  232.     m_pDC = NULL;
  233.     m_bSwap = true;
  234.     bgtexture[0] = 0;
  235.  
  236.     mXTranslate = 0;
  237.     mYTranslate = 0;
  238.     mZTranslate = 0;
  239.  
  240.     mXRotAngle = 0;
  241.     mYRotAngle = 0;
  242.     // mZRotAngle = 0;
  243.  
  244.     mVGLR_PERSPECT_FOVY = 45.0f;
  245.     mVGLR_PERSPECT_TAN_FOVY = tan(mVGLR_PERSPECT_FOVY / 2.0);
  246.     mVGLR_PERSPECT_NEAR_PLANE = 0.1f;
  247.     mFarPlane = 100.0f;
  248.  
  249.     mRenderingMode = VGLR_RENDERING_AS_IS;
  250.  
  251.     mBackfaceCull = true;
  252.  
  253.     modelViewMatrix = 0;
  254.  
  255.     trackerActive=false;
  256.    
  257.    
  258. }
  259.  
  260. COpenGLWnd::~COpenGLWnd()
  261. {
  262.     wglMakeCurrent(0,0);
  263.     wglDeleteContext(m_hRC);
  264.     wglDeleteContext(m_hRC1);
  265.     if( m_pDC )
  266.     {
  267.         delete m_pDC;
  268.     }
  269. }
  270.  
  271. // Standard OpenGL Init Stuff
  272. BOOL COpenGLWnd::SetupPixelFormat()
  273. {
  274.    
  275.   PIXELFORMATDESCRIPTOR pfdMain;
  276.  
  277.   memset( &pfdMain , 0 , sizeof( PIXELFORMATDESCRIPTOR ) );
  278.   pfdMain.nSize = sizeof( PIXELFORMATDESCRIPTOR );
  279.   pfdMain.nVersion = 1;
  280.   pfdMain.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
  281.   pfdMain.iPixelType = PFD_TYPE_RGBA;
  282.  
  283.     // Set to 16 for performance reasons.
  284.     pfdMain.cColorBits = 16;
  285.   pfdMain.cRedBits = 8;
  286.   pfdMain.cRedShift = 16;
  287.   pfdMain.cGreenBits = 8;
  288.   pfdMain.cGreenShift = 8;
  289.   pfdMain.cBlueBits = 8;
  290.   pfdMain.cBlueShift = 0;
  291.   pfdMain.cAlphaBits = 0;
  292.   pfdMain.cAlphaShift = 0;
  293.   pfdMain.cAccumBits = 64;
  294.   pfdMain.cAccumRedBits = 16;
  295.   pfdMain.cAccumGreenBits = 16;
  296.   pfdMain.cAccumBlueBits = 16;
  297.   pfdMain.cAccumAlphaBits = 0;
  298.   pfdMain.cDepthBits = 32;
  299.   pfdMain.cStencilBits = 8;
  300.   pfdMain.cAuxBuffers = 0;
  301.   pfdMain.iLayerType = PFD_MAIN_PLANE;
  302.   pfdMain.bReserved = 0;
  303.   pfdMain.dwLayerMask = 0;
  304.   pfdMain.dwVisibleMask = 0;
  305.   pfdMain.dwDamageMask = 0;
  306.  
  307.    // int m_nPixelFormat = ::ChoosePixelFormat( m_pDC->GetSafeHdc(), &pfdMain );
  308.     int m_nPixelFormat = ::ChoosePixelFormat( m_pDC->GetSafeHdc(), &pfdMain );
  309.  
  310.     if ( m_nPixelFormat == 0 )
  311.         return FALSE;
  312.  
  313.     // return ::SetPixelFormat( m_pDC->GetSafeHdc(), m_nPixelFormat, &pfdMain );
  314.         return ::SetPixelFormat( m_pDC->GetSafeHdc(), m_nPixelFormat, &pfdMain );
  315. }
  316.  
  317. /**
  318. * Initialize OpenGL.
  319. * Perform necessary OpenGL initializations, including the startup of the rendering timer through StartRenderingTimer().
  320. */
  321. BOOL COpenGLWnd::InitOpenGL()
  322. {
  323.     static int init = 0;    //CHANGED BY I.K. added type specifier
  324.  
  325.     if(init) return true;
  326.     init = 1;
  327.  
  328.     //Get a DC for the Client Area
  329.     if (m_pDC != NULL) delete m_pDC;
  330.     m_pDC = new CClientDC(this);
  331.  
  332.     //Failure to Get DC
  333.     if( m_pDC == NULL )
  334.         return FALSE;
  335.  
  336.     if( !SetupPixelFormat() )
  337.         return FALSE;
  338.  
  339.     m_hRC = ::wglCreateContext( m_pDC->GetSafeHdc() );
  340.     //m_hRC1 = ::wglCreateContext( m_pDC->GetSafeHdc() );
  341.  
  342.     //Failure to Create Rendering Context
  343.     if(m_hRC == 0 )
  344.         return FALSE;
  345.     if(m_hRC1 == 0 )
  346.         return FALSE;
  347.  
  348.     //Make the RC Current
  349.     //if( ::wglMakeCurrent( m_pDC->GetSafeHdc(), m_hRC) == FALSE )
  350.     //  return FALSE;
  351.  
  352.     // REMOVE
  353.     //if( ::wglMakeCurrent( NULL, NULL ) == FALSE )
  354.     //      return FALSE;
  355.  
  356.     rendererBusy = false;
  357.  
  358. //  StartRenderingTimer();
  359.  
  360.     // init glut
  361.     int argc = 1;
  362.     char *argv = "foo";
  363.     glutInit(&argc, &argv);
  364.  
  365.     // create main window
  366.     glutInitWindowPosition(0, 0);
  367.     glutInitWindowSize(800, 600);
  368.     glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
  369.     glutMainWindow = glutCreateWindow("glut main");
  370.  
  371.     return TRUE;
  372. }
  373.  
  374. BEGIN_MESSAGE_MAP(COpenGLWnd, CView)
  375.     //{{AFX_MSG_MAP(COpenGLWnd)
  376.     ON_WM_CREATE()
  377.     ON_WM_ERASEBKGND()
  378.     ON_WM_SIZE()
  379.     ON_WM_LBUTTONDOWN()
  380.     ON_WM_RBUTTONDOWN()
  381.     ON_WM_KEYDOWN()
  382.     ON_WM_LBUTTONUP()
  383.     ON_WM_MOUSEMOVE()
  384.     ON_WM_RBUTTONUP()
  385.     ON_WM_TIMER()
  386.    
  387.     //}}AFX_MSG_MAP
  388. END_MESSAGE_MAP()
  389.  
  390. /////////////////////////////////////////////////////////////////////////////
  391. // COpenGLWnd drawing
  392.  
  393. void COpenGLWnd::OnDraw(CDC* pDC)
  394. {
  395.     if(!trackerActive)   //disable OpenGL calls during tracking so they do not disturb tracking
  396.         RenderToScreen();
  397. }
  398.  
  399. /////////////////////////////////////////////////////////////////////////////
  400. // COpenGLWnd diagnostics
  401.  
  402. #ifdef _DEBUG
  403. void COpenGLWnd::AssertValid() const
  404. {
  405.     CView::AssertValid();
  406. }
  407.  
  408. void COpenGLWnd::Dump(CDumpContext& dc) const
  409. {
  410.     CView::Dump(dc);
  411. }
  412. #endif //_DEBUG
  413.  
  414. /////////////////////////////////////////////////////////////////////////////
  415. // COpenGLWnd message handlers
  416.  
  417.  
  418. /**
  419. * Initialize OpenGL when window is created.
  420. *
  421. */
  422. int COpenGLWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
  423. {
  424.     if (CView::OnCreate(lpCreateStruct) == -1)
  425.         return -1;
  426.  
  427.     if ( !InitOpenGL() )
  428.     {
  429.         MessageBox( "Error setting up OpenGL!", "Init Error!",
  430.             MB_OK | MB_ICONERROR );
  431.         return -1;
  432.     }
  433.  
  434.     return 0;
  435. }
  436.  
  437. // Override the errase background function to
  438. // do nothing to prevent flashing.
  439. BOOL COpenGLWnd::OnEraseBkgnd(CDC* pDC)
  440. {  
  441.     return true;
  442. }
  443.  
  444. // Set a few flags to make sure OpenGL only renders
  445. // in its viewport.
  446. BOOL COpenGLWnd::PreCreateWindow(CREATESTRUCT& cs)
  447. {
  448.     cs.style |= (WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CS_OWNDC);
  449.  
  450.     cs.lpszClass = ::AfxRegisterWndClass(CS_HREDRAW | CS_VREDRAW | CS_OWNDC | CS_DBLCLKS,
  451.       ::LoadCursor(NULL, IDC_ARROW), NULL, NULL);
  452.        
  453.     return CView::PreCreateWindow(cs);
  454. }
  455.  
  456. void COpenGLWnd::OnSize(UINT nType, int cx, int cy)
  457. {
  458.     CView::OnSize(nType, cx, cy);
  459.    
  460.     if ( 0 >= cx || 0 >= cy || nType == SIZE_MINIMIZED )
  461.         return;
  462.  
  463.     SetContext();
  464.  
  465.     ReSizeGLScene(cx, cy);
  466. }
  467.  
  468. void COpenGLWnd::OnLButtonDown(UINT nFlags, CPoint point)
  469. {  
  470.    
  471.     if(trackerActive && otvoren_dialog && zatvoren_dialog !=5){
  472.        
  473.         mLeftButtonDown = true;
  474.  
  475.         if( MoveJawHeight(point) || MoveIrisHeightWidth(point) || MoveHeadHeight(point) || MoveHeadUpperWidth(point) || MoveHeadMiddleWidth(point) || MoveHeadLowerWidth(point) || MoveChinWidth(point) || MoveJaw(point))
  476.         {
  477.            
  478.             vt2->oglIface->setOpenGLContext();
  479.             vt2->display_func();
  480.             vt2->oglIface->swapOpenGLBuffers();
  481.             m_ToolTip.Close();
  482.             LeftButtonDown(point.x, point.y);
  483.            
  484.         }
  485.  
  486.         else if (MoveNoseUpperVerticalPosition(point) || MoveNoseUpperWidth(point) || MoveNoseMiddleVerticalPosition(point) || MoveNoseLowerVerticalPosition(point) || MoveNoseLowerWidth(point) || MoveNoseThickness(point))
  487.         {
  488.             vt2->oglIface->setOpenGLContext();
  489.             vt2->display_func();
  490.             vt2->oglIface->swapOpenGLBuffers();
  491.             m_ToolTip.Close();
  492.             LeftButtonDown(point.x, point.y);
  493.         }
  494.  
  495.         else if (MoveEyebrowsBetweenVP(point) || MoveEyebrowsInnerVP_SD(point) || MoveEyebrowsOuterVP_SD
  496.             (point) || MoveEyebrowsMiddleVP_SD(point) || MoveEyebrowsThickness(point))
  497.         {
  498.             vt2->oglIface->setOpenGLContext();
  499.             vt2->display_func();
  500.             vt2->oglIface->swapOpenGLBuffers();
  501.             m_ToolTip.Close();
  502.             LeftButtonDown(point.x, point.y);
  503.         }
  504.         else if(MoveEyesVP_SD(point) || MoveEyesVD_Width(point) || MoveEyesHeight(point))
  505.         {
  506.             vt2->oglIface->setOpenGLContext();
  507.             vt2->display_func();
  508.             vt2->oglIface->swapOpenGLBuffers();
  509.             m_ToolTip.Close();
  510.             LeftButtonDown(point.x, point.y);
  511.         }
  512.         else if (MoveMouthVP(point) || MoveMouthWidth_Bending(point) || MoveMouthLipThickness(point))
  513.         {
  514.             vt2->oglIface->setOpenGLContext();
  515.             vt2->display_func();
  516.             vt2->oglIface->swapOpenGLBuffers();
  517.             m_ToolTip.Close();
  518.             LeftButtonDown(point.x, point.y);
  519.         }
  520.         else{
  521.         var = 100;
  522.             LeftButtonDown(point.x, point.y);
  523.            
  524.         }
  525.  
  526.     }
  527.     else{
  528. //--------------------for aam model-------------------
  529.             if (nFlags & MK_CONTROL)
  530.             LeftButtonControlDown(point.x, point.y);
  531.             else
  532.             LeftButtonDown(point.x, point.y);
  533.             mLeftButtonDown = true;
  534.     }
  535. }
  536.  
  537. void COpenGLWnd::OnRButtonDown(UINT nFlags, CPoint point)
  538. {
  539.     if(nFlags & MK_CONTROL)RightButtonControlDown(point.x, point.y);
  540.     if((nFlags & MK_CONTROL) && (nFlags & MK_SHIFT))RightButtonControlDown(point.x, point.y);
  541.            
  542.     RightButtonDown(point.x, point.y); 
  543.     mRightButtonDown = true;
  544. }
  545.  
  546. void COpenGLWnd::OnMouseMove(UINT nFlags, CPoint point)
  547. {
  548.     //mouse move events when dialog box is open and trackerActive
  549.     if (otvoren_dialog && zatvoren_dialog !=5 && trackerActive) {
  550.    
  551.         if(!mLeftButtonDown && zatvoren_dialog !=5)
  552.             OnMouseMoveTips(nFlags, point);
  553.                            
  554.  
  555.         if((nFlags & MK_LBUTTON) &&  (nFlags & MK_CONTROL)){var = 100; LeftButtonControlDrag(point.x, point.y);}
  556.  
  557.         if((nFlags & MK_LBUTTON))
  558.         {
  559.  
  560.             LeftButtonDrag(point.x, point.y);
  561.  
  562.             if(otvoren_dialog){
  563.                         vt2->oglIface->setOpenGLContext();
  564.                         vt2->display_func();
  565.                         vt2->oglIface->swapOpenGLBuffers();
  566.                         }
  567.            
  568.             //SetContext();
  569.             // So we don't recieve events when user has not pressed anything.
  570.             if(!mLeftButtonDown) {return;} 
  571.            
  572.  
  573.            
  574.         }
  575.         if ((nFlags & MK_RBUTTON) &&  (nFlags & MK_CONTROL) && (nFlags & MK_SHIFT) )RightButtonControlShiftDrag(point.x, point.y);
  576.  
  577.         else if ((nFlags & MK_RBUTTON) &&  (nFlags & MK_CONTROL))RightButtonControlDrag(point.x, point.y);
  578.  
  579.         else if (nFlags & MK_RBUTTON)
  580.         {
  581.             if(!mRightButtonDown) return;
  582.  
  583.             var = 100;
  584.             RightButtonDrag(point.x, point.y);
  585.  
  586.             if(otvoren_dialog){
  587.                         vt2->oglIface->setOpenGLContext();
  588.                         vt2->display_func();
  589.                         vt2->oglIface->swapOpenGLBuffers();
  590.                         }
  591.  
  592.         }
  593.     }
  594.  
  595.     else{ //for aam model
  596.          
  597.  
  598.     if (!m_bTimerSet &&  mRightButtonDown) {
  599.         SetTimer(ID_ROTATE, mTIMER_ROTATE_INTERVAL, NULL);
  600.         m_bTimerSet = true;
  601.         return;
  602.     }
  603.    
  604.         if((nFlags & MK_LBUTTON))
  605.         {
  606.             // So we don't recieve events when user has not pressed anything.
  607.             if(!mLeftButtonDown) return;
  608.             LeftButtonDrag(point.x, point.y);
  609.             SetContext();
  610.             if(nFlags & MK_CONTROL)
  611.                 LeftButtonControlDrag(point.x, point.y);
  612.             else if(!(nFlags & MK_SHIFT))
  613.                 LeftButtonDrag(point.x, point.y);
  614.         }
  615.         else if (nFlags & MK_RBUTTON)
  616.         {
  617.             if(!mRightButtonDown) return;
  618.             RightButtonDrag(point.x, point.y);
  619.         }
  620.    
  621.        
  622.     }
  623. }
  624. void COpenGLWnd:: OnMouseMoveTips(UINT nFlags, CPoint point){
  625.  
  626.    
  627.     if(MoveJawHeight(point) && !nFlags){
  628.             ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZENS));
  629.             tmp = 40;          
  630.             m_ToolTip.SetText("JAW HEIGHT");
  631.             m_ToolTip.Show(point);
  632.            
  633.     }  
  634.  
  635.     else if(MoveIrisHeightWidth(point) && !nFlags){
  636.             ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZENS));
  637.             tmp = 38;          
  638.             m_ToolTip.SetText("IRIS WIDTH and HEIGHT");
  639.             m_ToolTip.Show(point);
  640.            
  641.     }  
  642.  
  643.     else if(MoveHeadHeight(point) && !nFlags){
  644.             ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZENS));
  645.             tmp = 1;           
  646.             /*vt2->oglIface->setOpenGLContext();
  647.             vt2->display_func();
  648.             vt2->oglIface->swapOpenGLBuffers();*/
  649.             m_ToolTip.SetText("HEAD HEIGHT");
  650.             m_ToolTip.Show(point);
  651.            
  652.     }  
  653.  
  654.     else if(MoveHeadUpperWidth(point) && !nFlags){
  655.             ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEWE));
  656.             tmp = 2;
  657.             /*vt2->oglIface->setOpenGLContext();
  658.             vt2->display_func();
  659.             vt2->oglIface->swapOpenGLBuffers();*/
  660.             m_ToolTip.SetText("HEAD UPPER WIDTH");
  661.             m_ToolTip.Show(point);
  662.            
  663.     }  
  664.  
  665.     else if(MoveHeadMiddleWidth(point) && !nFlags){
  666.             ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEWE));
  667.             tmp = 3;
  668.             /*vt2->oglIface->setOpenGLContext();
  669.             vt2->display_func();
  670.             vt2->oglIface->swapOpenGLBuffers();*/
  671.             m_ToolTip.SetText("HEAD MIDDLE WIDTH");
  672.             m_ToolTip.Show(point);
  673.            
  674.     }
  675.  
  676.     else if(MoveHeadLowerWidth(point) && !nFlags){
  677.             ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEWE));
  678.             tmp = 4;
  679.             /*vt2->oglIface->setOpenGLContext();
  680.             vt2->display_func();
  681.             vt2->oglIface->swapOpenGLBuffers();*/
  682.             m_ToolTip.SetText("HEAD LOWER WIDTH");
  683.             m_ToolTip.Show(point);
  684.            
  685.     }
  686.  
  687.     else if(MoveChinWidth(point) && !nFlags){
  688.             ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEWE));
  689.             tmp = 5;
  690.             /*vt2->oglIface->setOpenGLContext();
  691.             vt2->display_func();
  692.             vt2->oglIface->swapOpenGLBuffers();*/
  693.             m_ToolTip.SetText("CHIN WIDTH");
  694.             m_ToolTip.Show(point);
  695.            
  696.     }
  697.     else if(MoveNoseUpperVerticalPosition(point) && !nFlags){
  698.             ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZENS));
  699.             tmp = 6;
  700.             /*vt2->oglIface->setOpenGLContext();
  701.             vt2->display_func();
  702.             vt2->oglIface->swapOpenGLBuffers();*/
  703.             m_ToolTip.SetText("NOSE UPPER POSITION");
  704.             m_ToolTip.Show(point);
  705.            
  706.     }
  707.     else if(MoveNoseMiddleVerticalPosition(point) && !nFlags){
  708.             ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEALL));
  709.             tmp = 7;
  710.             /*vt2->oglIface->setOpenGLContext();
  711.             vt2->display_func();
  712.             vt2->oglIface->swapOpenGLBuffers();*/
  713.             m_ToolTip.SetText("NOSE MIDDLE POSITION and WIDTH");
  714.             m_ToolTip.Show(point);
  715.            
  716.     }
  717.     else if(MoveNoseLowerVerticalPosition(point) && !nFlags){
  718.             ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZENS));
  719.             tmp = 8;
  720.             /*vt2->oglIface->setOpenGLContext();
  721.             vt2->display_func();
  722.             vt2->oglIface->swapOpenGLBuffers();*/
  723.             m_ToolTip.SetText("NOSE LOWER POSITION");
  724.             m_ToolTip.Show(point);
  725.            
  726.     }
  727.     else if(MoveNoseUpperWidth(point) && !nFlags){
  728.             ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEWE));
  729.             tmp = 9;
  730.             /*vt2->oglIface->setOpenGLContext();
  731.             vt2->display_func();
  732.             vt2->oglIface->swapOpenGLBuffers();*/
  733.             m_ToolTip.SetText("NOSE UPPER WIDTH");
  734.             m_ToolTip.Show(point);
  735.            
  736.     }
  737.     else if(MoveNoseLowerWidth(point) && !nFlags){
  738.             ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEWE));
  739.             tmp = 10;
  740.             /*vt2->oglIface->setOpenGLContext();
  741.             vt2->display_func();
  742.             vt2->oglIface->swapOpenGLBuffers();*/
  743.             m_ToolTip.SetText("NOSE LOWER WIDTH");
  744.             m_ToolTip.Show(point);
  745.            
  746.     }
  747.     else if(MoveNoseThickness(point) && !nFlags){
  748.             ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEWE));
  749.             tmp = 11;
  750.             /*vt2->oglIface->setOpenGLContext();
  751.             vt2->display_func();
  752.             vt2->oglIface->swapOpenGLBuffers();*/
  753.             m_ToolTip.SetText("NOSE THICKNESS");
  754.             m_ToolTip.Show(point);
  755.            
  756.     }
  757.     else if(MoveEyebrowsBetweenVP(point) && !nFlags){
  758.             ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZENS));
  759.             tmp = 12;
  760.             /*vt2->oglIface->setOpenGLContext();
  761.             vt2->display_func();
  762.             vt2->oglIface->swapOpenGLBuffers();*/
  763.             m_ToolTip.SetText("EYEBROWS BETWEEN POSITION");
  764.             m_ToolTip.Show(point);
  765.            
  766.     }
  767.     else if(MoveEyebrowsInnerVP_SD(point) && !nFlags){
  768.             ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEALL));
  769.             tmp = 13;
  770.             /*vt2->oglIface->setOpenGLContext();
  771.             vt2->display_func();
  772.             vt2->oglIface->swapOpenGLBuffers();*/
  773.             m_ToolTip.SetText("EYEBROWS INNER POSITION and DISTANCE");
  774.             m_ToolTip.Show(point);
  775.            
  776.     }
  777.     else if(MoveEyebrowsOuterVP_SD(point) && !nFlags){
  778.             ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEALL));
  779.             tmp = 14;
  780.             /*vt2->oglIface->setOpenGLContext();
  781.             vt2->display_func();
  782.             vt2->oglIface->swapOpenGLBuffers();*/
  783.             m_ToolTip.SetText("EYEBROWS OUTER POSITION and DISTANCE");
  784.             m_ToolTip.Show(point);
  785.            
  786.     }
  787.     else if(MoveEyebrowsMiddleVP_SD(point) && !nFlags){
  788.             ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEALL));
  789.             tmp = 16;
  790.             /*vt2->oglIface->setOpenGLContext();
  791.             vt2->display_func();
  792.             vt2->oglIface->swapOpenGLBuffers();*/
  793.             m_ToolTip.SetText("EYEBROWS MIDDLE POSITION and DISTANCE");
  794.             m_ToolTip.Show(point);
  795.            
  796.     }
  797.     else if(MoveEyebrowsThickness(point) && !nFlags){
  798.             ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZENS));
  799.             tmp = 15;
  800.             /*vt2->oglIface->setOpenGLContext();
  801.             vt2->display_func();
  802.             vt2->oglIface->swapOpenGLBuffers();*/
  803.             m_ToolTip.SetText("EYEBROWS THICKNESS");
  804.             m_ToolTip.Show(point);
  805.            
  806.     }
  807.     else if(MoveEyesVP_SD(point) && !nFlags){
  808.             ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEALL));
  809.             tmp = 17;
  810.             /*vt2->oglIface->setOpenGLContext();
  811.             vt2->display_func();
  812.             vt2->oglIface->swapOpenGLBuffers();*/
  813.             m_ToolTip.SetText("EYES POSITION and DISTANCE");
  814.             m_ToolTip.Show(point);
  815.            
  816.     }
  817.     else if(MoveEyesVD_Width(point) && !nFlags){
  818.             ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEALL));
  819.             tmp = 18;
  820.             /*vt2->oglIface->setOpenGLContext();
  821.             vt2->display_func();
  822.             vt2->oglIface->swapOpenGLBuffers();*/
  823.             m_ToolTip.SetText("EYES DIFFERENCE and WIDTH");
  824.             m_ToolTip.Show(point);
  825.            
  826.     }
  827.     else if(MoveEyesHeight(point) && !nFlags){
  828.             ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZENS));
  829.             tmp = 19;
  830.             /*vt2->oglIface->setOpenGLContext();
  831.             vt2->display_func();
  832.             vt2->oglIface->swapOpenGLBuffers();*/
  833.             m_ToolTip.SetText("EYES HEIGHT");
  834.             m_ToolTip.Show(point);
  835.            
  836.     }
  837.     else if(MoveMouthVP(point) && !nFlags){
  838.             ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZENS));
  839.             tmp = 20;
  840.             /*vt2->oglIface->setOpenGLContext();
  841.             vt2->display_func();
  842.             vt2->oglIface->swapOpenGLBuffers();*/
  843.             m_ToolTip.SetText("MOUTH POSITION");
  844.             m_ToolTip.Show(point);
  845.            
  846.     }
  847.     else if(MoveMouthWidth_Bending(point) && !nFlags){
  848.             ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEALL));
  849.             tmp = 21;
  850.             /*vt2->oglIface->setOpenGLContext();
  851.             vt2->display_func();
  852.             vt2->oglIface->swapOpenGLBuffers();*/
  853.             m_ToolTip.SetText("MOUTH WIDTH and BENDING");
  854.             m_ToolTip.Show(point);
  855.            
  856.     }
  857.     else if(MoveMouthLipThickness(point) && !nFlags)
  858.     {
  859.             ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZENS));
  860.             tmp = 22;
  861.             /*vt2->oglIface->setOpenGLContext();
  862.             vt2->display_func();
  863.             vt2->oglIface->swapOpenGLBuffers();*/
  864.             m_ToolTip.SetText("MOUTH LIP THICKNESS");
  865.             m_ToolTip.Show(point);
  866.            
  867.     }
  868.     /*else if(MoveJaw(point) && !nFlags)
  869.     {
  870.             ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZENS));
  871.             tmp = 23;
  872.             vt2->oglIface->setOpenGLContext();
  873.             vt2->display_func();
  874.             vt2->oglIface->swapOpenGLBuffers();
  875.             m_ToolTip.SetText("JAW z-extension");
  876.             m_ToolTip.Show(point);
  877.            
  878.     }*/
  879.  
  880.  
  881.    
  882. else if((tmp==2 && !MoveHeadUpperWidth(point)) || (tmp==40 && !MoveJawHeight(point)) || (tmp==38 && !MoveIrisHeightWidth(point)) || (tmp==1 && !MoveHeadHeight(point)) || (tmp==3 && !MoveHeadMiddleWidth(point))|| (tmp==4 && !MoveHeadLowerWidth(point))|| (tmp==5 && !MoveChinWidth(point)) || (tmp==23 && !MoveJaw(point)))
  883.     {  
  884.         vt2->oglIface->setOpenGLContext();
  885.         vt2->display_func();
  886.         vt2->oglIface->swapOpenGLBuffers();
  887.         m_ToolTip.Close(); 
  888.        
  889.     }
  890.  
  891.     else if ((tmp==6 && !MoveNoseUpperVerticalPosition(point)) || (tmp==9 && !MoveNoseUpperWidth(point)) || (tmp==7 && !MoveNoseMiddleVerticalPosition(point)) ||(tmp==8 && !MoveNoseLowerVerticalPosition(point)) || (tmp==10 && !MoveNoseLowerWidth(point)) || (tmp==11 && !MoveNoseThickness(point)))
  892.         {
  893.             vt2->oglIface->setOpenGLContext();
  894.             vt2->display_func();
  895.             vt2->oglIface->swapOpenGLBuffers();
  896.             m_ToolTip.Close();
  897.            
  898.         }
  899.     else if ((tmp==12 && !MoveEyebrowsBetweenVP(point)) || (tmp==13 && !MoveEyebrowsInnerVP_SD(point)) || (tmp==14 && !MoveEyebrowsOuterVP_SD
  900.             (point)) || (tmp==16 && !MoveEyebrowsMiddleVP_SD(point)) || (tmp==15 && !MoveEyebrowsThickness(point)))
  901.         {
  902.             vt2->oglIface->setOpenGLContext();
  903.             vt2->display_func();
  904.             vt2->oglIface->swapOpenGLBuffers();
  905.             m_ToolTip.Close();
  906.            
  907.         }
  908.     else if((tmp==17 && !MoveEyesVP_SD(point)) || (tmp==18 && !MoveEyesVD_Width(point)) || (tmp==19 && !MoveEyesHeight(point)))
  909.         {
  910.             vt2->oglIface->setOpenGLContext();
  911.             vt2->display_func();
  912.             vt2->oglIface->swapOpenGLBuffers();
  913.             m_ToolTip.Close();
  914.            
  915.         }
  916.     else if ((tmp==20 && !MoveMouthVP(point)) || (tmp==21 && !MoveMouthWidth_Bending(point)) || (tmp==22 && !MoveMouthLipThickness(point)))
  917.         {
  918.             vt2->oglIface->setOpenGLContext();
  919.             vt2->display_func();
  920.             vt2->oglIface->swapOpenGLBuffers();
  921.             m_ToolTip.Close();
  922.            
  923.         }
  924.    
  925.    
  926.    
  927.  
  928.  
  929. }
  930.    
  931.  
  932.  
  933. void COpenGLWnd::OnRButtonUp(UINT nFlags, CPoint point)
  934. {
  935.         KillTimer(ID_ROTATE);
  936.         m_bTimerSet = false;
  937.         mRightButtonDown = false;
  938. }
  939.  
  940. /**
  941. * Start the rendering timer.
  942. * Start the timer for the rendering. After this, the OnTimer() function
  943. * is automatically called every mTIMER_RENDERING_INTERVAL milliseconds, and in turn it calls the render function. Thus we have
  944. * a rendering function call every mTIMER_RENDERING_INTERVAL milliseconds.
  945. */
  946. void COpenGLWnd::StartRenderingTimer()
  947. {
  948.     SetTimer(ID_RENDERING, mTIMER_RENDERING_INTERVAL, NULL);
  949. }
  950.  
  951. /**
  952. * Timer callback.
  953. * This function is called by the timer. This is used to implement the rendering cycle.
  954. */
  955. void COpenGLWnd::OnTimer(UINT nIDEvent)
  956. {
  957.     switch(nIDEvent)
  958.     {
  959.         case ID_RENDERING:
  960.             RenderToScreen();
  961.             break;
  962.         case ID_ROTATE:
  963.             RightButtonDownTimerFunc();
  964.             break;
  965.     }
  966. }
  967.  
  968. void COpenGLWnd::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
  969. {
  970.     SetContext();
  971.         if(nChar == VK_F1)
  972.             SetRenderingMode(VGLR_RENDERING_WIREFRAME);
  973.         else if(nChar == VK_F2)
  974.             SetRenderingMode(VGLR_RENDERING_AS_IS);
  975.         else if(nChar == VK_F11)
  976.             FitToScreen();
  977.         else
  978.             RenderToScreen();
  979.     SwapGLBuffers();
  980. }
  981.  
  982. void COpenGLWnd::OnLButtonUp(UINT nFlags, CPoint point)
  983. {
  984.    
  985.     mLeftButtonDown = false;
  986.    
  987.    
  988. }
  989.  
  990.  
  991. /**
  992. * Pre-render setup function.
  993. * This function is called before the rendering in each rendering cycle. It sets up the GL context and clears the screen
  994. * to prepare for the next frame to be rendered.
  995. *
  996. * This is a good place to insert the rendering of other objects in the scene,
  997. * background image or similar.
  998. */
  999. void COpenGLWnd::SetContext()
  1000. {
  1001.     // set the context
  1002.     wglMakeCurrent(m_pDC->GetSafeHdc(), m_hRC);
  1003.    
  1004.    
  1005.     // clear the frame buffer before next drawing
  1006.     if(!trackerActive) // if tracker is active, do not clear screen
  1007.         glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
  1008.    
  1009.     // INSERT CODE HERE TO RENDER ANY ADDITIONAL OBJECTS, BACKGROUND IMAGE OR SIMILAR
  1010.     DrawBackgroundImage();
  1011. }
  1012.  
  1013. void COpenGLWnd::SwapGLBuffers()
  1014. {
  1015.     if(trackerActive) // if tracker is active, do not swap buffers
  1016.         return;
  1017.     SwapBuffers(m_pDC->GetSafeHdc());
  1018.     wglMakeCurrent(NULL, NULL);
  1019. }
  1020.  
  1021. int COpenGLWnd::LoadTexture(char *fullPath)
  1022. {
  1023.  
  1024.     FILE *File=NULL;
  1025.     File=fopen(fullPath,"r");
  1026.  
  1027.     if(!File)
  1028.     {
  1029.         return -1;
  1030.     }
  1031.     fclose(File);
  1032.  
  1033.     // Texture varible, return 
  1034.     GLuint texture[1];
  1035.  
  1036.  
  1037.     // Check file-extension
  1038. //  if(fullPath.substr(fullPath.size() - 4, fullPath.size()) == temp)
  1039.     if(!strcmp(fullPath+(strlen(fullPath) - 4),".jpg"))
  1040.     {
  1041.         glGenTextures(1, &texture[0]);                  // Create The Texture
  1042.  
  1043.         // Typical Texture Generation Using Data From The Bitmap
  1044.         glBindTexture(GL_TEXTURE_2D, texture[0]);
  1045.  
  1046.         JPEG_CORE_PROPERTIES *p = new JPEG_CORE_PROPERTIES;
  1047.  
  1048.         if( ijlInit( p ) != IJL_OK ) return -1;
  1049.        
  1050.     p->JPGFile = fullPath;
  1051.  
  1052.         // Read in params first so we get the right DIB.
  1053.     if( ijlRead( p, IJL_JFILE_READPARAMS ) != IJL_OK )
  1054.     {
  1055.         delete p;
  1056.         return -1;
  1057.     }
  1058.    
  1059.     switch( p->JPGChannels )
  1060.     {
  1061.       case 1:  p->JPGColor    = IJL_G;
  1062.                p->DIBChannels = 3;
  1063.                p->DIBColor    = IJL_BGR;
  1064.                break;
  1065.       case 3:  p->JPGColor    = IJL_YCBCR;
  1066.                p->DIBChannels = 3;
  1067.                p->DIBColor    = IJL_BGR;
  1068.                break;
  1069.       case 4:  p->JPGColor    = IJL_YCBCRA_FPX;
  1070.                p->DIBChannels = 4;
  1071.                p->DIBColor    = IJL_RGBA_FPX;
  1072.                break;
  1073.       default: p->DIBColor = (IJL_COLOR)IJL_OTHER;
  1074.                p->JPGColor = (IJL_COLOR) IJL_OTHER;
  1075.                p->DIBChannels = p->JPGChannels;
  1076.                break;
  1077.     }
  1078.  
  1079.     p->DIBWidth    = p->JPGWidth;
  1080.     p->DIBHeight   = p->JPGHeight;
  1081.     p->DIBPadBytes = IJL_DIB_PAD_BYTES( p->DIBWidth, p->DIBChannels );
  1082.  
  1083.     int imageSize = p->DIBWidth * p->DIBChannels + p->DIBPadBytes;
  1084.     imageSize *= p->DIBHeight;
  1085.     p->DIBBytes = new BYTE[ imageSize ];
  1086.  
  1087.     if ( ijlRead( p, IJL_JFILE_READWHOLEIMAGE ) != IJL_OK ) return -1;
  1088.  
  1089.         if ( p->DIBColor == IJL_RGBA_FPX )
  1090.         {
  1091.       if ( p->DIBBytes )
  1092.           delete[] p->DIBBytes;
  1093.             delete p;
  1094.             return -1;
  1095.         }
  1096.  
  1097.         BYTE *flipImage = new BYTE[ imageSize ];
  1098.        
  1099.         // Flip the image - since library gives us upside down images.
  1100.         int jMax = p->DIBWidth * p->DIBChannels + p->DIBPadBytes;
  1101.         int iMax = p->DIBHeight;
  1102.  
  1103.         for(int i=0; i < iMax; i++)
  1104.             for(int j=0; j < jMax; j++)
  1105.                 flipImage[i * jMax + j] = p->DIBBytes[((iMax - 1) - i) * jMax + j];
  1106.  
  1107.         // Load texture into GL.
  1108.         int maxSize = 0;
  1109.         glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxSize);
  1110.  
  1111.         // Create a texture of nearest power 2
  1112.         int xPowSize = 1;
  1113.         int yPowSize = 1;
  1114.         while((p->DIBWidth / xPowSize) > 0) xPowSize <<= 1;
  1115.         while((p->DIBHeight / yPowSize) > 0) yPowSize <<= 1;
  1116.  
  1117.         // Size to nearest lower power of 2 for speed
  1118.         xPowSize >>= 1;
  1119.         yPowSize >>= 1;
  1120.        
  1121.         // So we're not overriding gfx-cards capabilitys
  1122.         if(xPowSize > maxSize) xPowSize = maxSize;
  1123.         if(yPowSize > maxSize) yPowSize = maxSize;
  1124.  
  1125.         // Allocate memory to the scaled image.
  1126.         GLubyte* tempScaleImage = new GLubyte[yPowSize * (xPowSize * p->DIBChannels + p->DIBPadBytes)];
  1127.  
  1128.         // Scale original image to nearest lower power of 2.
  1129.         switch(p->DIBColor)
  1130.         {
  1131.             // Only three cases since last IJL_RGBA_FPX will never happen.
  1132.             case IJL_RGB:
  1133.                 {
  1134.                     // gluScaleImage(GL_RGB, p->DIBWidth, p->DIBHeight, GL_UNSIGNED_BYTE, p->DIBBytes, xPowSize, yPowSize, GL_UNSIGNED_BYTE, tempScaleImage);
  1135.                     gluScaleImage(GL_RGB, p->DIBWidth, p->DIBHeight, GL_UNSIGNED_BYTE, flipImage, xPowSize, yPowSize, GL_UNSIGNED_BYTE, tempScaleImage);
  1136.                     // const GLubyte *ragga2 = gluErrorString(glGetError());
  1137.            
  1138.                     glTexImage2D(GL_TEXTURE_2D, 0, 3, xPowSize, yPowSize, 0, GL_RGB, GL_UNSIGNED_BYTE, tempScaleImage);
  1139.                     // const GLubyte *ragga = gluErrorString(glGetError());
  1140.                 }
  1141.                 break;
  1142.  
  1143.             case IJL_BGR:
  1144.                 {
  1145.                     gluScaleImage(GL_RGB, p->DIBWidth, p->DIBHeight, GL_UNSIGNED_BYTE, flipImage, xPowSize, yPowSize, GL_UNSIGNED_BYTE, tempScaleImage);
  1146.                     // gluScaleImage(GL_BGR_EXT, p->DIBWidth, p->DIBHeight, GL_UNSIGNED_BYTE, p->DIBBytes, xPowSize, yPowSize, GL_UNSIGNED_BYTE, tempScaleImage);
  1147.                     // const GLubyte *ragga2 = gluErrorString(glGetError());
  1148.  
  1149.                     glTexImage2D(GL_TEXTURE_2D, 0, 3, xPowSize, yPowSize, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, tempScaleImage);
  1150.                     // const GLubyte *ragga = gluErrorString(glGetError());
  1151.                 }
  1152.                 break;
  1153.  
  1154.             // Safety stuff.
  1155.             default:
  1156.                 return -1;
  1157.                 break;
  1158.         }
  1159.  
  1160.         // Clean up
  1161.         delete [] flipImage;
  1162.         delete [] tempScaleImage;
  1163.         delete [] p->DIBBytes;
  1164.         delete p;
  1165.  
  1166.         glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); // Linear Filtering
  1167.         glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); // Linear Filtering
  1168.  
  1169.     }
  1170.     // Check file extension.
  1171. //  else if(fullPath.substr(fullPath.size() - 4, fullPath.size()) == temp2)
  1172.     else if(!strcmp(fullPath+(strlen(fullPath) - 4),".bmp"))
  1173.     {
  1174.         glGenTextures(1, &texture[0]);                  // Create The Texture
  1175.  
  1176.         // Typical Texture Generation Using Data From The Bitmap
  1177.         glBindTexture(GL_TEXTURE_2D, texture[0]);
  1178.  
  1179.         AUX_RGBImageRec *texPointer[1];
  1180.         memset(texPointer,0,sizeof(void *)*1);
  1181.  
  1182.         texPointer[0] = auxDIBImageLoad(fullPath);
  1183.  
  1184.         glGenTextures(1, &texture[0]);                  // Create The Texture
  1185.  
  1186.         // Typical Texture Generation Using Data From The Bitmap
  1187.         glBindTexture(GL_TEXTURE_2D, texture[0]);
  1188.  
  1189.         int maxSize;
  1190.         glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxSize);
  1191.  
  1192.         // Create a texture of nearest power 2
  1193.         int xPowSize = 1;
  1194.         int yPowSize = 1;
  1195.         while((texPointer[0]->sizeX / xPowSize) > 0) xPowSize <<= 1;
  1196.         while((texPointer[0]->sizeY / yPowSize) > 0) yPowSize <<= 1;
  1197.  
  1198.         // Size to nearest lower power of 2 for speed
  1199.         xPowSize >>= 1;
  1200.         yPowSize >>= 1;
  1201.        
  1202.         // So we're not overriding gfx-cards capabilitys
  1203.         if(xPowSize > maxSize) xPowSize = maxSize;
  1204.         if(yPowSize > maxSize) yPowSize = maxSize;
  1205.  
  1206.         GLubyte* tempScaleImage = new GLubyte[yPowSize * xPowSize * 3];
  1207.  
  1208.         // Scale original image to nearest lower power of 2.
  1209.         gluScaleImage(GL_RGB, texPointer[0]->sizeX, texPointer[0]->sizeY, GL_UNSIGNED_BYTE, texPointer[0]->data, xPowSize, yPowSize, GL_UNSIGNED_BYTE, tempScaleImage);
  1210.  
  1211.         const GLubyte *ragga2 = gluErrorString(glGetError());
  1212.  
  1213.         glTexImage2D(GL_TEXTURE_2D, 0, 3, xPowSize, yPowSize, 0, GL_RGB, GL_UNSIGNED_BYTE, tempScaleImage);
  1214.  
  1215.         const GLubyte *ragga = gluErrorString(glGetError());
  1216.  
  1217.         glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); // Linear Filtering
  1218.         glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); // Linear Filtering
  1219.  
  1220.         if (texPointer[0])                          // If Texture Exists
  1221.         {
  1222.             if (texPointer[0]->data)                    // If Texture Image Exists
  1223.             {
  1224.                 free(texPointer[0]->data);              // Free The Texture Image Memory
  1225.                 delete [] tempScaleImage;
  1226.             }
  1227.             free(texPointer[0]);                        // Free The Image Structure
  1228.         }
  1229.     }
  1230.  
  1231.     // Successfully return the loaded image.
  1232.     return texture[0];
  1233. }
  1234.  
  1235.  
  1236. /**
  1237. * Draw the background image on the screen.
  1238. * Load the background image from the file background.jpg the first time this function is called.
  1239. * If loading is succesful, the image is drawn on the screen every time the function is called.
  1240. * This function is called by SetContext(), so it is executed at the beginning of every frame.
  1241. *
  1242. * @return true if image is succesfully drawn, 0 otherwise
  1243. * @see SetContext()
  1244. */
  1245. bool COpenGLWnd::DrawBackgroundImage()
  1246. {
  1247.     // draw the background image, if any
  1248.     static int noImage = 0;
  1249.  
  1250.     if(noImage)
  1251.         return false;
  1252.  
  1253.  
  1254.  
  1255.     if(!bgtexture[0])
  1256.     {
  1257.         bgtexture[0] = LoadTexture("background.jpg");
  1258.         if(bgtexture[0] == -1)
  1259.         {
  1260.             bgtexture[0] = LoadTexture("../background.jpg");
  1261.         }
  1262.         if(bgtexture[0] == -1)
  1263.         {
  1264.             noImage=1;
  1265.             return false;
  1266.         }
  1267.     }
  1268.  
  1269.  
  1270.     glPushAttrib(GL_DEPTH_BUFFER_BIT | GL_VIEWPORT_BIT | GL_ENABLE_BIT | GL_FOG_BIT | GL_STENCIL_BUFFER_BIT | GL_TRANSFORM_BIT | GL_TEXTURE_BIT );
  1271.     glDisable(GL_ALPHA_TEST);
  1272.     glDisable(GL_DEPTH_TEST);
  1273.     glDisable(GL_BLEND );
  1274.     glDisable(GL_DITHER);
  1275.     glDisable(GL_FOG);
  1276.     glDisable(GL_SCISSOR_TEST);
  1277.     glDisable(GL_STENCIL_TEST);
  1278.     glDisable(GL_LIGHTING);
  1279.     glDisable(GL_LIGHT0);
  1280.     glEnable(GL_TEXTURE_2D);
  1281.     glBindTexture(GL_TEXTURE_2D, bgtexture[0]);             // Select Our Texture
  1282.  
  1283.     glMatrixMode(GL_MODELVIEW);
  1284.     glPushMatrix();
  1285.     glLoadIdentity();                                   // Reset The Projection Matrix
  1286.  
  1287.    
  1288.     glMatrixMode(GL_PROJECTION);
  1289.     glPushMatrix();
  1290.     glLoadIdentity();                                   // Reset The Projection Matrix
  1291.     glOrtho(0.0f,1.0f,0.0f,1.0f,-10.0f,10.0f);
  1292.  
  1293.     glBegin(GL_QUADS);
  1294.     glTexCoord2f(0.0f,0.0f);       
  1295.     glVertex3f(0.0f,0.0f,-5.0f);
  1296.  
  1297.     glTexCoord2f(1.0f,0.0f);       
  1298.     glVertex3f(1.0f,0.0f,-5.0f);
  1299.  
  1300.     glTexCoord2f(1.0f,1.0f);       
  1301.     glVertex3f(1.0f,1.0f,-5.0f);
  1302.  
  1303.     glTexCoord2f(0.0f,1.0f);       
  1304.     glVertex3f(0.0f,1.0f,-5.0f);
  1305.    
  1306.     glEnd();
  1307.     glPopMatrix();
  1308.     glMatrixMode(GL_MODELVIEW);
  1309.     glPopMatrix();
  1310.  
  1311.     glBindTexture(GL_TEXTURE_2D, 0);
  1312.     glPopAttrib();
  1313.     glClear(GL_DEPTH_BUFFER_BIT);
  1314.  
  1315.  
  1316.     return TRUE;
  1317.    
  1318.    
  1319. }
  1320.  
  1321.  
  1322. void COpenGLWnd::ReSizeGLScene(GLsizei width, GLsizei height)       // Resize And Initialize The GL Window
  1323. {
  1324.     if (height==0)                                      // Prevent A Divide By Zero By
  1325.     {
  1326.         height=1;                                       // Making Height Equal One
  1327.     }
  1328.  
  1329.     mWindowWidth = width;
  1330.     mWindowHeight = height;
  1331.     int animViewPos,animViewWidth,animViewHeight;
  1332.  
  1333.     animViewPos = (int)((1-ANIM_VIEW_SIZE)*width);
  1334.     animViewWidth = (int)(ANIM_VIEW_SIZE*width);
  1335.     animViewHeight = (animViewWidth * 3) / 4; // 3/4 aspect ratio
  1336.     if(animViewHeight > height)
  1337.         animViewHeight = height;
  1338.  
  1339.     glViewport(animViewPos,0,animViewWidth,animViewHeight);                     // Reset The Current Viewport
  1340.  
  1341.     glMatrixMode(GL_PROJECTION);                        // Select The Projection Matrix
  1342.     glLoadIdentity();                                   // Reset The Projection Matrix
  1343.  
  1344.     gluPerspective(mVGLR_PERSPECT_FOVY, (GLfloat)animViewWidth/(GLfloat)animViewHeight, mVGLR_PERSPECT_NEAR_PLANE, mFarPlane);
  1345.  
  1346.     glMatrixMode(GL_MODELVIEW);                         // Select The Modelview Matrix
  1347. }
  1348.  
  1349.  
  1350. void COpenGLWnd::SetModelViewMatrix(GLfloat *m)
  1351. {
  1352.     modelViewMatrix = m;
  1353. }
  1354.  
  1355.  
  1356. void COpenGLWnd::ToggleBackfaceCull()
  1357. {
  1358.     mBackfaceCull = !mBackfaceCull;
  1359.     SetRenderingMode(mRenderingMode);
  1360. }
  1361.  
  1362. void COpenGLWnd::SetRenderingMode(VGLR_RENDERING_MODE newMode)
  1363. {
  1364.     switch(newMode)
  1365.     {
  1366.         case VGLR_RENDERING_WIREFRAME:
  1367.         {
  1368.             // Set wireframe mode.
  1369.             if(mBackfaceCull)
  1370.                 glPolygonMode(GL_FRONT, GL_LINE);
  1371.             else
  1372.                 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
  1373.            
  1374.             // Still want lighting tho..
  1375.             glEnable(GL_LIGHTING);
  1376.             glEnable(GL_LIGHT0);
  1377.  
  1378.             // Material
  1379.             glDisable(GL_COLOR_MATERIAL);
  1380.  
  1381.             // Textures
  1382.             glDisable(GL_TEXTURE_2D);
  1383.    
  1384.             if(mBackfaceCull)
  1385.             {
  1386.                 glEnable(GL_CULL_FACE);
  1387.                 glCullFace(GL_BACK);
  1388.             }
  1389.             else
  1390.                 glDisable(GL_CULL_FACE);
  1391.            
  1392.         }
  1393.         break;
  1394.  
  1395.         case VGLR_RENDERING_SOLID_NO_MATERIAL:
  1396.         {
  1397.         }
  1398.         break;
  1399.  
  1400.         case VGLR_RENDERING_MATERIAL:
  1401.         {
  1402.         }
  1403.         break;
  1404.  
  1405.         case VGLR_RENDERING_AS_IS:
  1406.         {
  1407.             if(mBackfaceCull)
  1408.                 glPolygonMode(GL_FRONT, GL_FILL);
  1409.             else
  1410.                 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
  1411.  
  1412.             // Lightning.
  1413.             glEnable(GL_LIGHTING);
  1414.             glEnable(GL_LIGHT0);
  1415.  
  1416.             // Textures
  1417.             glEnable(GL_TEXTURE_2D);
  1418.  
  1419.             if(mBackfaceCull)
  1420.             {
  1421.                 glEnable(GL_CULL_FACE);
  1422.                 glCullFace(GL_BACK);
  1423.             }
  1424.             else
  1425.                 glDisable(GL_CULL_FACE);
  1426.         }
  1427.         break;
  1428.     }
  1429.  
  1430.     mRenderingMode = newMode;
  1431. }
  1432.  
  1433.  
  1434. void COpenGLWnd::LeftButtonDown(float x, float y)
  1435. {
  1436.     mLeftButtonX = (GLfloat)x;
  1437.     mLeftButtonY = (GLfloat)y;
  1438.    
  1439. }
  1440. void COpenGLWnd::SetRange(CPoint& point){
  1441.     CRect rc; // objekt koji predstavlja pravokutnik
  1442.     GetClientRect(rc); //u taj objekt snimamo trenutnu velicinu prozora
  1443.  
  1444.     width = (float)vt2->frame->width; //sirina okvira, npr. 640
  1445.     height = (float)vt2->frame->height; //visina okvira, npr.480
  1446.     image_width = (float)vt2->gl_image->width; //sirina slike, stalna - 800
  1447.     image_height = (float)vt2->gl_image->height; //visina slike, stalna - 600
  1448.  
  1449.     widthRight = - (float)(image_width-(float)image_width/2)/((float)image_height/2);
  1450.     widthLeft = - (float)(0-(float)image_width/2)/((float)image_height/2);
  1451.  
  1452.     point_x = - (float)(point.x-(float)image_width/2)/((float)image_height/2);
  1453.  
  1454.     imageTop = (float)(image_height-(float)image_height/2)/((float)image_height/2);
  1455.     imageBottom = (float)(0-(float)image_height/2)/((float)image_height/2);
  1456.     point_y = - (float)(point.y-((rc.top + rc.bottom) - image_height)-(float)image_height/2)/((float)image_height/2);
  1457.  
  1458.     centarX = (float)(widthRight + widthLeft)/2;
  1459.     centarY = (float)(imageTop + imageBottom)/2;
  1460.  
  1461.  
  1462. }
  1463.  
  1464. bool COpenGLWnd::MoveJawHeight(CPoint &point){
  1465.  
  1466.     // faceShape[0]
  1467.     var = 40;
  1468.  
  1469.     // y koordinate verteksa
  1470.     float y10 = vt2->fbft->projection->data.fl[2*10+1];
  1471.     float y65 = vt2->fbft->projection->data.fl[2*65+1];
  1472.    
  1473.     // x koordinate verteksa
  1474.     float x32 = vt2->fbft->projection->data.fl[2*32];
  1475.     float x65 = vt2->fbft->projection->data.fl[2*65];
  1476.  
  1477.     // podesavanje granica na [-1,1] i [-1.3333, 1.3333]
  1478.     SetRange(point);
  1479.    
  1480.     // x i y kordinate verteksa u odnosu na centar slike
  1481.     float x_32 = centarX + x32 ;
  1482.     float x_65 = centarX + x65 ;
  1483.     float y_10 = centarY + y10 ;
  1484.     float y_65 = centarY + y65 ;
  1485.  
  1486.     // pozicija misa je istinita (true) u danom podrucju
  1487.     return(point_x <= x_65 && point_x >= x_32 && point_y >= y_10 && point_y <= y_65);
  1488. }
  1489.  
  1490. bool COpenGLWnd::MoveIrisHeightWidth(CPoint& point){
  1491.  
  1492.     // faceShape[1]
  1493.     var = 38;
  1494.    
  1495.     // y koordinate verteksa
  1496.     float y68 = vt2->fbft->projection->data.fl[2*68+1];
  1497.     float y67 = vt2->fbft->projection->data.fl[2*67+1];
  1498.     float y74 = vt2->fbft->projection->data.fl[2*74+1];
  1499.     float y73 = vt2->fbft->projection->data.fl[2*73+1];
  1500.    
  1501.     // x koordinate verteksa
  1502.     float x20 = vt2->fbft->projection->data.fl[2*20];
  1503.     float x67 = vt2->fbft->projection->data.fl[2*67];
  1504.     float x71 = vt2->fbft->projection->data.fl[2*71];
  1505.     float x23 = vt2->fbft->projection->data.fl[2*23];
  1506.     float x56 = vt2->fbft->projection->data.fl[2*56];
  1507.     float x73 = vt2->fbft->projection->data.fl[2*73];
  1508.     float x69 = vt2->fbft->projection->data.fl[2*69];
  1509.     float x53 = vt2->fbft->projection->data.fl[2*53];
  1510.  
  1511.     // x koordinata verteksa 0 (otprilike centar maske po x)
  1512.     float x0 = vt2->fbft->projection->data.fl[2*0];
  1513.    
  1514.     // podesavanje granica na [-1,1] i [-1.3333, 1.3333]
  1515.     SetRange(point);
  1516.  
  1517.     // x i y kordinate verteksa u odnosu na centar slike
  1518.     float y_68 = centarY + y68 ;
  1519.     float y_67 = centarY + y67 ;
  1520.     float y_74 = centarY + y74 ;
  1521.     float y_73 = centarY + y73 ;
  1522.  
  1523.     float x_0 = centarX + x0 ;
  1524.  
  1525.     float x_20 = centarX + x20 ;
  1526.     float x_67 = centarX + x67 ;
  1527.     float x_71 = centarX + x71 ;
  1528.     float x_23 = centarX + x23 ;
  1529.     float x_56 = centarX + x56 ;
  1530.     float x_73 = centarX + x73 ;
  1531.     float x_69 = centarX + x69 ;
  1532.     float x_53 = centarX + x53 ;
  1533.    
  1534.  
  1535.     if(point_x >= x_20 && point_x <= x_67)
  1536.     {
  1537.         if(point_y >= y_68 && point_y <= y_67)
  1538.         {
  1539.             side = 1; // lijeva strana irisa
  1540.             return(true);
  1541.         }
  1542.     }
  1543.     if(point_x >= x_71 && point_x <= x_23)
  1544.     {
  1545.         if(point_y >= y_68 && point_y <= y_67)
  1546.         {
  1547.             side = 0; // desna strana irisa
  1548.             return(true);
  1549.         }
  1550.     }
  1551.     if(point_x >= x_56 && point_x <= x_73)
  1552.     {
  1553.         if(point_y >= y_74 && point_y <= y_73)
  1554.         {
  1555.             side = 1; // lijeva strana irisa
  1556.             return(true);
  1557.         }
  1558.     }
  1559.     if(point_x >= x_69 && point_x <= x_53)
  1560.     {
  1561.         if(point_y >= y_74 && point_y <= y_73)
  1562.         {
  1563.             side = 0; // desna strana irisa
  1564.             return(true);
  1565.         }
  1566.     }
  1567.  
  1568.     return(false);
  1569.  
  1570. }
  1571.  
  1572. bool COpenGLWnd::MoveHeadHeight(CPoint &point){
  1573.  
  1574.     // faceShape[0]
  1575.     var = 0;
  1576.  
  1577.     // y koordinate verteksa
  1578.     float y0 = vt2->fbft->projection->data.fl[2*0+1];
  1579.     float y34 = vt2->fbft->projection->data.fl[2*34+1];
  1580.    
  1581.     // x koordinate verteksa
  1582.     float x45 = vt2->fbft->projection->data.fl[2*45];
  1583.     float x12 = vt2->fbft->projection->data.fl[2*12];
  1584.  
  1585.     // podesavanje granica na [-1,1] i [-1.3333, 1.3333]
  1586.     SetRange(point);
  1587.    
  1588.     // x i y kordinate verteksa u odnosu na centar slike
  1589.     float x_45 = centarX + x45 ;
  1590.     float x_12 = centarX + x12 ;
  1591.     float y_0 = centarY + y0 ;
  1592.     float y_34 = centarY + y34 ;
  1593.  
  1594.     // pozicija misa je istinita (true) u danom podrucju
  1595.     return(point_x <= x_45 && point_x >= x_12 && point_y >= y_34 && point_y <= y_0);
  1596. }
  1597.  
  1598. bool COpenGLWnd::MoveHeadUpperWidth(CPoint& point){
  1599.  
  1600.     // faceShape[1]
  1601.     var = 1;
  1602.    
  1603.     // y koordinate verteksa
  1604.     float y48 = vt2->fbft->projection->data.fl[2*48+1];
  1605.     float y45 = vt2->fbft->projection->data.fl[2*45+1];
  1606.     float y15 = vt2->fbft->projection->data.fl[2*15+1];
  1607.     float y12 = vt2->fbft->projection->data.fl[2*12+1];
  1608.    
  1609.     // x koordinate verteksa
  1610.     float x48 = vt2->fbft->projection->data.fl[2*45];
  1611.     float x47 = vt2->fbft->projection->data.fl[2*47];
  1612.     float x15 = vt2->fbft->projection->data.fl[2*15];
  1613.     float x14 = vt2->fbft->projection->data.fl[2*14];
  1614.  
  1615.     // x koordinata verteksa 0 (otprilike centar maske po x)
  1616.     float x0 = vt2->fbft->projection->data.fl[2*0];
  1617.    
  1618.     // podesavanje granica na [-1,1] i [-1.3333, 1.3333]
  1619.     SetRange(point);
  1620.  
  1621.     // x i y kordinate verteksa u odnosu na centar slike
  1622.     float x_48 = centarX + x48 ;
  1623.     float x_47 = centarX + x47 ;
  1624.     float x_15 = centarX + x15 ;
  1625.     float x_14 = centarX + x14 ;
  1626.  
  1627.     float x_0 = centarX + x0 ;
  1628.  
  1629.     float y_48 = centarY + y48 ;
  1630.     float y_45 = centarY + y45 ;
  1631.     float y_15 = centarY + y15 ;
  1632.     float y_12 = centarY + y12 ;
  1633.    
  1634.  
  1635.     if(point_x > x_0) side = 0; // lijeva strana maske
  1636.     else if(point_x < x_0) side =1; // desna strana maske
  1637.  
  1638.     // pozicija misa je istinita (true) u danom podrucju
  1639.     return((point_x <= x_47 && point_x >= x_48 && point_y >= y_48 && point_y <= y_45) || (point_x <= x_48 && point_x >= x_47 && point_y >= y_48 && point_y <= y_45) || ((point_x <= x_15 && point_x >= x_14 && point_y >= y_15 && point_y <= y_12)) || (point_x <= x_14 && point_x >= x_15 && point_y >= y_15 && point_y <= y_12));
  1640.  
  1641. }
  1642.  
  1643. bool COpenGLWnd::MoveHeadMiddleWidth(CPoint& point){
  1644.  
  1645.     // faceShape[2]
  1646.     var = 2;
  1647.    
  1648.     // y koordinate verteksa
  1649.     float y48 = vt2->fbft->projection->data.fl[2*48+1];
  1650.     float y61 = vt2->fbft->projection->data.fl[2*61+1];
  1651.     float y15 = vt2->fbft->projection->data.fl[2*15+1];
  1652.     float y28 = vt2->fbft->projection->data.fl[2*28+1];
  1653.    
  1654.     // x koordinate verteksa
  1655.     float x48 = vt2->fbft->projection->data.fl[2*48];
  1656.     float x62 = vt2->fbft->projection->data.fl[2*62];
  1657.     float x15 = vt2->fbft->projection->data.fl[2*15];
  1658.     float x29 = vt2->fbft->projection->data.fl[2*29];
  1659.  
  1660.     // x koordinata verteksa 0 (otprilike centar maske po x)
  1661.     float x0 = vt2->fbft->projection->data.fl[2*0];
  1662.  
  1663.     // podesavanje granica na [-1,1] i [-1.3333, 1.3333]
  1664.     SetRange(point);
  1665.        
  1666.     // x i y kordinate verteksa u odnosu na centar slike
  1667.     float x_48 = centarX + x48 ;
  1668.     float x_62 = centarX + x62 ;
  1669.     float x_15 = centarX + x15 ;
  1670.     float x_29 = centarX + x29 ;
  1671.  
  1672.     float x_0 = centarX + x0 ;
  1673.  
  1674.     float y_48 = centarY + y48 ;
  1675.     float y_61 = centarY + y61 ;
  1676.     float y_15 = centarY + y15 ;
  1677.     float y_28 = centarY + y28 ;
  1678.    
  1679.  
  1680.     if(point_x > x_0) side = 0; // lijeva strana maske
  1681.     else if(point_x < x_0) side =1; //desna strana maske
  1682.  
  1683.     // pozicija misa je istinita (true) u danom podrucju
  1684.     return((point_x <= x_62 && point_x >= x_48 && point_y >= y_61 && point_y <= y_48) || ((point_x <= x_15 && point_x >= x_29 && point_y >= y_28 && point_y <= y_15)));
  1685.  
  1686. }
  1687. bool COpenGLWnd::MoveHeadLowerWidth(CPoint& point){
  1688.  
  1689.     // faceShape[3]
  1690.     var = 3;
  1691.    
  1692.     // y koordinate verteksa
  1693.     float y63 = vt2->fbft->projection->data.fl[2*63+1];
  1694.     float y61 = vt2->fbft->projection->data.fl[2*61+1];
  1695.     float y30 = vt2->fbft->projection->data.fl[2*30+1];
  1696.     float y28 = vt2->fbft->projection->data.fl[2*28+1];
  1697.    
  1698.     // x koordinate verteksa
  1699.     float x63 = vt2->fbft->projection->data.fl[2*63];
  1700.     float x61 = vt2->fbft->projection->data.fl[2*61];
  1701.     float x28 = vt2->fbft->projection->data.fl[2*28];
  1702.     float x30 = vt2->fbft->projection->data.fl[2*30];
  1703.  
  1704.     // x koordinata verteksa 0 (otprilike centar maske po x)
  1705.     float x0 = vt2->fbft->projection->data.fl[2*0];
  1706.  
  1707.     // podesavanje granica na [-1,1] i [-1.3333, 1.3333]
  1708.     SetRange(point);
  1709.  
  1710.     // x i y kordinate verteksa u odnosu na centar slike
  1711.     float x_61 = centarX + x61 ;
  1712.     float x_63 = centarX + x63 ;
  1713.     float x_28 = centarX + x28 ;
  1714.     float x_30 = centarX + x30 ;
  1715.  
  1716.     float x_0 = centarX + x0 ;
  1717.  
  1718.     float y_61 = centarY + y61 ;
  1719.     float y_63 = centarY + y63 ;
  1720.     float y_30 = centarY + y30 ;
  1721.     float y_28 = centarY + y28 ;
  1722.    
  1723.  
  1724.     if(point_x > x_0) side = 0; // lijeva strana maske
  1725.     else if(point_x < x_0) side =1; // desna strana maske
  1726.  
  1727.     // pozicija misa je istinita (true) u danom podrucju
  1728.     return((point_x <= x_61 && point_x >= x_63 && point_y >= y_63 && point_y <= y_61) || ((point_x <= x_30 && point_x >= x_28 && point_y >= y_30 && point_y <= y_28)));
  1729.  
  1730. }
  1731. bool COpenGLWnd::MoveChinWidth(CPoint& point){
  1732.  
  1733.     // faceShape[4]
  1734.     var = 4;
  1735.    
  1736.     // y koordinate verteksa
  1737.     float y63 = vt2->fbft->projection->data.fl[2*63+1];
  1738.     float y65 = vt2->fbft->projection->data.fl[2*65+1];
  1739.     float y30 = vt2->fbft->projection->data.fl[2*30+1];
  1740.     float y32 = vt2->fbft->projection->data.fl[2*32+1];
  1741.    
  1742.     // x koordinate verteksa
  1743.     float x63 = vt2->fbft->projection->data.fl[2*63];
  1744.     float x65 = vt2->fbft->projection->data.fl[2*65];
  1745.     float x32 = vt2->fbft->projection->data.fl[2*32];
  1746.     float x30 = vt2->fbft->projection->data.fl[2*30];
  1747.  
  1748.     // x koordinata verteksa 0 (otprilike centar maske po x)
  1749.     float x0 = vt2->fbft->projection->data.fl[2*0];
  1750.  
  1751.     // podesavanje granica na [-1,1] i [-1.3333, 1.3333]
  1752.     SetRange(point);
  1753.  
  1754.     // x i y kordinate verteksa u odnosu na centar slike
  1755.     float x_65 = centarX + x65 ;
  1756.     float x_63 = centarX + x63 ;
  1757.     float x_32 = centarX + x32 ;
  1758.     float x_30 = centarX + x30 ;
  1759.  
  1760.     float x_0 = centarX + x0 ;
  1761.  
  1762.     float y_65 = centarY + y65 ;
  1763.     float y_63 = centarY + y63 ;
  1764.     float y_30 = centarY + y30 ;
  1765.     float y_32 = centarY + y32 ;
  1766.    
  1767.  
  1768.     if(point_x > x_0) side = 0; // lijeva strana maske
  1769.     else if(point_x < x_0) side =1; // desna strana maske
  1770.  
  1771.     // pozicija misa je istinita (true) u danom podrucju
  1772.     return((point_x <= x_63 && point_x >= x_65 && point_y >= y_65 && point_y <= y_63) || ((point_x <= x_32 && point_x >= x_30 && point_y >= y_32 && point_y <= y_30)));
  1773.  
  1774.  
  1775. }
  1776. bool COpenGLWnd::MoveJaw(CPoint& point){
  1777. // faceShape[36]
  1778.     var = 36;
  1779.  
  1780.     // y koordinate verteksa
  1781.     float y10 = vt2->fbft->projection->data.fl[2*10+1];
  1782.     float y65 = vt2->fbft->projection->data.fl[2*65+1];
  1783.    
  1784.     // x koordinate verteksa
  1785.     float x65 = vt2->fbft->projection->data.fl[2*65];
  1786.     float x32 = vt2->fbft->projection->data.fl[2*32];
  1787.  
  1788.     // podesavanje granica na [-1,1] i [-1.3333, 1.3333]
  1789.     SetRange(point);
  1790.    
  1791.     // x i y kordinate verteksa u odnosu na centar slike
  1792.     float x_65 = centarX + x65 ;
  1793.     float x_32 = centarX + x32 ;
  1794.     float y_10 = centarY + y10 ;
  1795.     float y_65 = centarY + y65 ;
  1796.  
  1797.     // pozicija misa je istinita (true) u danom podrucju
  1798.     return(point_x <= x_65 && point_x >= x_32 && point_y >= y_10 && point_y <= y_65);
  1799. }
  1800.  
  1801. bool COpenGLWnd::MoveNoseUpperVerticalPosition(CPoint& point){
  1802.  
  1803.     // faceShape[5]
  1804.     var = 5;
  1805.    
  1806.     // y koordinate verteksa
  1807.     float y3 = vt2->fbft->projection->data.fl[2*3+1];
  1808.     float y78 = vt2->fbft->projection->data.fl[2*78+1];
  1809.  
  1810.     // x koordinate verteksa
  1811.     float x78 = vt2->fbft->projection->data.fl[2*78];
  1812.     float x77 = vt2->fbft->projection->data.fl[2*77];
  1813.  
  1814.     // podesavanje granica na [-1,1] i [-1.3333, 1.3333]
  1815.     SetRange(point);
  1816.  
  1817.     // x i y kordinate verteksa u odnosu na centar slike
  1818.     float x_78 = centarX + x78 ;
  1819.     float x_77 = centarX + x77 ;
  1820.  
  1821.     float y_78 = centarY + y78 ;
  1822.     float y_3 = centarY + y3 ;
  1823.  
  1824.     // pozicija misa je istinita (true) u danom podrucju
  1825.     return(point_x <= x_78 && point_x >= x_77 && point_y >= y_78 && point_y <= y_3);
  1826. }
  1827.  
  1828.  
  1829.  
  1830.  
  1831. bool COpenGLWnd::MoveNoseUpperWidth(CPoint& point){
  1832.     // faceShape[8]
  1833.     var = 8;
  1834.    
  1835.     // y koordinate verteksa
  1836.     float y78 = vt2->fbft->projection->data.fl[2*78+1];
  1837.     float y3 = vt2->fbft->projection->data.fl[2*3+1];
  1838.     float y77 = vt2->fbft->projection->data.fl[2*77+1];
  1839.    
  1840.     // x koordinate verteksa
  1841.     float x93 = vt2->fbft->projection->data.fl[2*93];
  1842.     float x78 = vt2->fbft->projection->data.fl[2*78];
  1843.     float x77 = vt2->fbft->projection->data.fl[2*77];
  1844.     float x92 = vt2->fbft->projection->data.fl[2*92];
  1845.  
  1846.     // x koordinata verteksa 0 (otprilike centar maske po x)
  1847.     float x0 = vt2->fbft->projection->data.fl[2*0];
  1848.  
  1849.     // podesavanje granica na [-1,1] i [-1.3333, 1.3333]
  1850.     SetRange(point);
  1851.        
  1852.     // x i y kordinate verteksa u odnosu na centar slike
  1853.     float x_93 = centarX + x93 ;
  1854.     float x_78 = centarX + x78 ;
  1855.     float x_77 = centarX + x77 ;
  1856.     float x_92 = centarX + x92 ;
  1857.  
  1858.     float x_0 = centarX + x0 ;
  1859.  
  1860.     float y_78 = centarY + y78 ;
  1861.     float y_3 = centarY + y3 ;
  1862.     float y_77 = centarY + y77 ;   
  1863.  
  1864.     if(point_x > x_0) side = 0; // lijeva strana maske
  1865.     else if(point_x < x_0) side =1; //desna strana maske
  1866.  
  1867.     // pozicija misa je istinita (true) u danom podrucju
  1868.     return((point_x <= x_93 && point_x >= x_78 && point_y >= y_78 && point_y <= y_3) ||(point_x <= x_78 && point_x >= x_93 && point_y >= y_78 && point_y <= y_3)|| ((point_x <= x_77 && point_x >= x_92 && point_y >= y_77 && point_y <= y_3) || (point_x <= x_92 && point_x >= x_77 && point_y >= y_77 && point_y <= y_3)));
  1869.  
  1870. }
  1871.  
  1872. bool COpenGLWnd::MoveNoseMiddleVerticalPosition(CPoint& point){ // & MOVE NoSE MIDDLE WIDTH
  1873.     // faceShape[6] i faceShape[9]
  1874.     var = 6;
  1875.    
  1876.     // y koordinate verteksa
  1877.     float y93 = vt2->fbft->projection->data.fl[2*93+1];
  1878.     float y94 = vt2->fbft->projection->data.fl[2*94+1];
  1879.  
  1880.     // x koordinate verteksa
  1881.     float x93 = vt2->fbft->projection->data.fl[2*93];
  1882.     float x92 = vt2->fbft->projection->data.fl[2*92];
  1883.  
  1884.     // x koordinata verteksa 0 (otprilike centar maske po x)
  1885.     float x0 = vt2->fbft->projection->data.fl[2*0];
  1886.  
  1887.     // podesavanje granica na [-1,1] i [-1.3333, 1.3333]
  1888.     SetRange(point);
  1889.  
  1890.     // x i y kordinate verteksa u odnosu na centar slike
  1891.     float x_93 = centarX + x93 ;
  1892.     float x_92 = centarX + x92 ;
  1893.  
  1894.     float x_0 = centarX + x0 ;
  1895.  
  1896.     float y_93 = centarY + y93 ;
  1897.     float y_94 = centarY + y94 ;
  1898.  
  1899.     //if(point_x > x_0) side = 0; // lijeva strana maske
  1900.     //else if(point_x < x_0) side =1; // desna strana maske
  1901.  
  1902.     // pozicija misa je istinita (true) u danom podrucju
  1903.     return(point_x <= x_93 && point_x >= x_92 && point_y >= y_93 && point_y <= y_94);
  1904.  
  1905. }
  1906.  
  1907. bool COpenGLWnd::MoveNoseLowerVerticalPosition(CPoint& point){
  1908. // faceShape[7]
  1909.     var = 7;
  1910.    
  1911.     // y koordinate verteksa
  1912.     float y6 = vt2->fbft->projection->data.fl[2*6+1];
  1913.     float y76 = vt2->fbft->projection->data.fl[2*76+1];
  1914.  
  1915.     // x koordinate verteksa
  1916.     float x76 = vt2->fbft->projection->data.fl[2*76];
  1917.     float x75 = vt2->fbft->projection->data.fl[2*75];
  1918.  
  1919.     // podesavanje granica na [-1,1] i [-1.3333, 1.3333]
  1920.     SetRange(point);
  1921.  
  1922.     // x i y kordinate verteksa u odnosu na centar slike
  1923.     float x_75 = centarX + x75 ;
  1924.     float x_76 = centarX + x76 ;
  1925.  
  1926.     float y_76 = centarY + y76 ;
  1927.     float y_6 = centarY + y6 ;
  1928.  
  1929.     // pozicija misa je istinita (true) u danom podrucju
  1930.     return(point_x <= x_76 && point_x >= x_75 && point_y >= y_6 && point_y <= y_76);
  1931.  
  1932. }
  1933. bool COpenGLWnd::MoveNoseLowerWidth(CPoint &point){
  1934.     // faceShape[10]
  1935.     var = 10;
  1936.    
  1937.     // y koordinate verteksa
  1938.     float y6 = vt2->fbft->projection->data.fl[2*6+1];
  1939.     float y76 = vt2->fbft->projection->data.fl[2*76+1];
  1940.    
  1941.     // x koordinate verteksa
  1942.     float x59 = vt2->fbft->projection->data.fl[2*59];
  1943.     float x76 = vt2->fbft->projection->data.fl[2*76];
  1944.     float x75 = vt2->fbft->projection->data.fl[2*75];
  1945.     float x26 = vt2->fbft->projection->data.fl[2*26];
  1946.  
  1947.     // x koordinata verteksa 0 (otprilike centar maske po x)
  1948.     float x0 = vt2->fbft->projection->data.fl[2*0];
  1949.  
  1950.     // podesavanje granica na [-1,1] i [-1.3333, 1.3333]
  1951.     SetRange(point);
  1952.  
  1953.     // x i y kordinate verteksa u odnosu na centar slike
  1954.     float x_59 = centarX + x59 ;
  1955.     float x_76 = centarX + x76 ;
  1956.     float x_75 = centarX + x75 ;
  1957.     float x_26 = centarX + x26 ;
  1958.  
  1959.     float x_0 = centarX + x0 ;
  1960.  
  1961.     float y_6 = centarY + y6 ;
  1962.     float y_76 = centarY + y76 ;
  1963.  
  1964.     if(point_x > x_0) side = 0; // lijeva strana maske
  1965.     else if(point_x < x_0) side =1; // desna strana maske
  1966.  
  1967.     // pozicija misa je istinita (true) u danom podrucju
  1968.     return((point_x <= x_59 && point_x >= x_76 && point_y >= y_6 && point_y <= y_76) || ((point_x <= x_75 && point_x >= x_26 && point_y >= y_6 && point_y <= y_76)));
  1969.  
  1970.  
  1971. }
  1972. bool COpenGLWnd::MoveNoseThickness(CPoint &point){
  1973. // faceShape[14]
  1974.     var = 14;
  1975.    
  1976.     // y koordinate verteksa
  1977.     float y58 = vt2->fbft->projection->data.fl[2*58+1];
  1978.     float y25 = vt2->fbft->projection->data.fl[2*25+1];
  1979.    
  1980.    
  1981.     // x koordinate verteksa
  1982.     float x58 = vt2->fbft->projection->data.fl[2*58];
  1983.     float x25 = vt2->fbft->projection->data.fl[2*25];
  1984.    
  1985.     float r = 0.03;
  1986.  
  1987.     // x koordinata verteksa 0 (otprilike centar maske po x)
  1988.     float x0 = vt2->fbft->projection->data.fl[2*0];
  1989.  
  1990.     // podesavanje granica na [-1,1] i [-1.3333, 1.3333]
  1991.     SetRange(point);
  1992.  
  1993.     // x i y kordinate verteksa u odnosu na centar slike
  1994.     float x_58 = centarX + x58 ;   
  1995.     float x_25 = centarX + x25 ;
  1996.    
  1997.    
  1998.  
  1999.     float x_0 = centarX + x0 ;
  2000.  
  2001.     float y_58 = centarY + y58 ;
  2002.     float y_25 = centarY + y25 ;
  2003.  
  2004.     if(point_x > x_0) side = 0; // lijeva strana maske
  2005.     else if(point_x < x_0) side =1; // desna strana maske
  2006.  
  2007.  
  2008.  
  2009.     // pozicija misa je istinita (true) u danom podrucju
  2010. return  (((x_58 - point_x)*(x_58 - point_x) + (y_58 - point_y)*(y_58 - point_y)) < r*r) || (((x_25 - point_x)*(x_25 - point_x) + (y_25 - point_y)*(y_25 - point_y)) < r*r) ;
  2011.  
  2012. }
  2013. bool COpenGLWnd::MoveEyebrowsBetweenVP(CPoint &point){
  2014.  
  2015. // faceShape[19]
  2016.     var = 19;
  2017.    
  2018.     // y koordinate verteksa
  2019.     float y3 = vt2->fbft->projection->data.fl[2*3+1];
  2020.  
  2021.     float y3plus = y3 + 0.03;
  2022.  
  2023.     // x koordinate verteksa
  2024.     float x77 = vt2->fbft->projection->data.fl[2*77];
  2025.     float x78 = vt2->fbft->projection->data.fl[2*78];
  2026.  
  2027.     // podesavanje granica na [-1,1] i [-1.3333, 1.3333]
  2028.     SetRange(point);
  2029.  
  2030.     // x i y kordinate verteksa u odnosu na centar slike
  2031.     float x_77 = centarX + x77 ;
  2032.     float x_78 = centarX + x78 ;
  2033.    
  2034.    
  2035.     float y_3 = centarY + y3 ;
  2036.     float y_3plus = centarY + y3plus ;
  2037.  
  2038.  
  2039.     // pozicija misa je istinita (true) u danom podrucju
  2040.     return(point_x <= x_78 && point_x >= x_77 && point_y >= y_3 && point_y <= y_3plus);
  2041.  
  2042.  
  2043. }
  2044. bool COpenGLWnd::MoveEyebrowsInnerVP_SD(CPoint& point){
  2045. // faceShape[20] i faceShape[21]
  2046.     var = 20;
  2047.    
  2048.     // y koordinate verteksa
  2049.     float y50 = vt2->fbft->projection->data.fl[2*50+1];
  2050.     float y17 = vt2->fbft->projection->data.fl[2*17+1];
  2051.  
  2052.     float r = 0.03;
  2053.  
  2054.     // x koordinate verteksa
  2055.     float x50 = vt2->fbft->projection->data.fl[2*50];
  2056.     float x17 = vt2->fbft->projection->data.fl[2*17];
  2057.  
  2058.     // x koordinata verteksa 0 (otprilike centar maske po x)
  2059.     float x0 = vt2->fbft->projection->data.fl[2*0];
  2060.  
  2061.  
  2062.     // podesavanje granica na [-1,1] i [-1.3333, 1.3333]
  2063.     SetRange(point);
  2064.  
  2065.     // x i y kordinate verteksa u odnosu na centar slike
  2066.     float x_50 = centarX + x50 ;
  2067.     float x_17 = centarX + x17 ;
  2068.     float x_0 = centarX + x0 ;
  2069.    
  2070.  
  2071.     float y_50 = centarY + y50 ;
  2072.     float y_17 = centarY + y17 ;
  2073.  
  2074.     if(point_x > x_0) side = 0; // lijeva strana maske
  2075.     else if(point_x < x_0) side =1; // desna strana maske
  2076.  
  2077.     // pozicija misa je istinita (true) u danom podrucju
  2078.     return (((x_50 - point_x)*(x_50 - point_x) + (y_50 - point_y)*(y_50 - point_y)) < r*r) || (((x_17 - point_x)*(x_17 - point_x) + (y_17 - point_y)*(y_17 - point_y)) < r*r) ;
  2079.  
  2080. }
  2081. bool COpenGLWnd::MoveEyebrowsOuterVP_SD(CPoint& point){
  2082.     // faceShape[22] i faceShape[23]
  2083.     var = 22;
  2084.    
  2085.     // y koordinate verteksa
  2086.     float y48 = vt2->fbft->projection->data.fl[2*48+1];
  2087.     float y15 = vt2->fbft->projection->data.fl[2*15+1];
  2088.  
  2089.     float r = 0.03;
  2090.  
  2091.     // x koordinate verteksa
  2092.     float x48 = vt2->fbft->projection->data.fl[2*48];
  2093.     float x15 = vt2->fbft->projection->data.fl[2*15];
  2094.  
  2095.     // x koordinata verteksa 0 (otprilike centar maske po x)
  2096.     float x0 = vt2->fbft->projection->data.fl[2*0];
  2097.  
  2098.     // podesavanje granica na [-1,1] i [-1.3333, 1.3333]
  2099.     SetRange(point);
  2100.  
  2101.     // x i y kordinate verteksa u odnosu na centar slike
  2102.     float x_48 = centarX + x48 ;
  2103.     float x_15 = centarX + x15 ;
  2104.     float x_0 = centarX + x0 ;
  2105.    
  2106.  
  2107.     float y_48 = centarY + y48 ;
  2108.     float y_15 = centarY + y15 ;
  2109.  
  2110.     if(point_x > x_0) side = 0; // lijeva strana maske
  2111.     else if(point_x < x_0) side =1; // desna strana maske
  2112.  
  2113.  
  2114.     // pozicija misa je istinita (true) u danom podrucju
  2115.     return (((x_48 - point_x)*(x_48 - point_x) + (y_48 - point_y)*(y_48 - point_y)) < r*r) || (((x_15 - point_x)*(x_15 - point_x) + (y_15 - point_y)*(y_15 - point_y)) < r*r) ;
  2116.  
  2117. }
  2118.  
  2119. bool COpenGLWnd::MoveEyebrowsMiddleVP_SD(CPoint& point){
  2120.     // faceShape[24] I faceShape[25]
  2121.     var = 24;
  2122.    
  2123.     // y koordinate verteksa
  2124.     float y51 = vt2->fbft->projection->data.fl[2*51+1];
  2125.     float y49 = vt2->fbft->projection->data.fl[2*49+1];
  2126.     float y16 = vt2->fbft->projection->data.fl[2*16+1];
  2127.     float y18 = vt2->fbft->projection->data.fl[2*18+1];
  2128.  
  2129.     float r = 0.03;
  2130.    
  2131.  
  2132.     // x koordinate verteksa
  2133.     float x51 = vt2->fbft->projection->data.fl[2*51];
  2134.     float x18 = vt2->fbft->projection->data.fl[2*18];
  2135.  
  2136.     // x koordinata verteksa 0 (otprilike centar maske po x)
  2137.     float x0 = vt2->fbft->projection->data.fl[2*0];
  2138.  
  2139.     float x51minus = x51 + r;
  2140.     float x51plus = x51 - r;
  2141.  
  2142.     float x18minus = x18 + r;
  2143.     float x18plus = x18 - r;
  2144.  
  2145.  
  2146.  
  2147.     // podesavanje granica na [-1,1] i [-1.3333, 1.3333]
  2148.     SetRange(point);
  2149.  
  2150.     // x i y kordinate verteksa u odnosu na centar slike
  2151.     float x_51minus = centarX + x51minus ;
  2152.     float x_51plus = centarX + x51plus ;
  2153.     float x_18minus = centarX + x18minus ;
  2154.     float x_18plus = centarX + x18plus ;
  2155.     float x_0 = centarX + x0 ;
  2156.  
  2157.     float y_51 = centarY + y51 ;
  2158.     float y_49 = centarY + y49 ;
  2159.     float y_18 = centarY + y18 ;
  2160.     float y_16 = centarY + y16 ;
  2161.  
  2162.     if(point_x > x_0) side = 0; // lijeva strana maske
  2163.     else if(point_x < x_0) side =1; // desna strana maske
  2164.  
  2165.  
  2166.     // pozicija misa je istinita (true) u danom podrucju
  2167.     return((point_x <= x_51minus && point_x >= x_51plus && point_y >= y_51 && point_y <= y_49) || (point_x <= x_18minus && point_x >= x_18plus && point_y >= y_18 && point_y <= y_16));
  2168.  
  2169.  
  2170. }
  2171.  
  2172. bool COpenGLWnd::MoveEyebrowsThickness(CPoint &point){
  2173.  
  2174. // faceShape[26]
  2175.     var = 26;
  2176.    
  2177.     // y koordinate verteksa
  2178.    
  2179.     float y49 = vt2->fbft->projection->data.fl[2*49+1];
  2180.     float y16 = vt2->fbft->projection->data.fl[2*16+1];
  2181.    
  2182.     float r = 0.03;
  2183.    
  2184.  
  2185.     // x koordinate verteksa
  2186.     float x49 = vt2->fbft->projection->data.fl[2*49];
  2187.     float x16 = vt2->fbft->projection->data.fl[2*16];
  2188.  
  2189.     float x49minus = x49 + r;
  2190.     float x49plus = x49 - r;
  2191.  
  2192.     float x16minus = x16 + r;
  2193.     float x16plus = x16 - r;
  2194.  
  2195.  
  2196.  
  2197.     // podesavanje granica na [-1,1] i [-1.3333, 1.3333]
  2198.     SetRange(point);
  2199.  
  2200.     // x i y kordinate verteksa u odnosu na centar slike
  2201.     float x_49minus = centarX + x49minus ;
  2202.     float x_49plus = centarX + x49plus ;
  2203.     float x_16minus = centarX + x16minus ;
  2204.     float x_16plus = centarX + x16plus ;
  2205.    
  2206.  
  2207.     float y_49up = centarY + (y49 + 0.03);
  2208.     float y_49 = centarY + y49 ;
  2209.     float y_16up = centarY + (y16 + 0.03);
  2210.     float y_16 = centarY + y16 ;
  2211.  
  2212.    
  2213.  
  2214.     // pozicija misa je istinita (true) u danom podrucju
  2215.     return((point_x <= x_49minus && point_x >= x_49plus && point_y >= y_49 && point_y <= y_49up) || (point_x <= x_16minus && point_x >= x_16plus && point_y >= y_16 && point_y <= y_16up));
  2216.  
  2217. }
  2218. bool COpenGLWnd::MoveEyesVP_SD(CPoint &point){
  2219.     // faceShape[27] I faceShape[28]
  2220.     var = 27;
  2221.    
  2222.     // y koordinate verteksa
  2223.     float y100 = vt2->fbft->projection->data.fl[2*100+1];
  2224.     float y69 = vt2->fbft->projection->data.fl[2*69+1];
  2225.     float y107 = vt2->fbft->projection->data.fl[2*107+1];
  2226.     float y71 = vt2->fbft->projection->data.fl[2*71+1];
  2227.  
  2228.  
  2229.     // x koordinate verteksa
  2230.     float x100 = vt2->fbft->projection->data.fl[2*100];
  2231.     float x74 = vt2->fbft->projection->data.fl[2*74];
  2232.     float x107 = vt2->fbft->projection->data.fl[2*107];
  2233.     float x68 = vt2->fbft->projection->data.fl[2*68];
  2234.  
  2235.     // x koordinata verteksa 0 (otprilike centar maske po x)
  2236.     float x0 = vt2->fbft->projection->data.fl[2*0];
  2237.  
  2238.  
  2239.     // podesavanje granica na [-1,1] i [-1.3333, 1.3333]
  2240.     SetRange(point);
  2241.  
  2242.     // x i y kordinate verteksa u odnosu na centar slike
  2243.     float x_100 = centarX + x100 ;
  2244.     float x_107 = centarX + x107 ;
  2245.     float x_74 = centarX + x74 ;
  2246.     float x_68 = centarX + x68 ;
  2247.  
  2248.     float x_0 = centarX + x0 ;
  2249.  
  2250.     float y_100 = centarY + y100 ;
  2251.     float y_69 = centarY + y69 ;
  2252.     float y_107 = centarY + y107 ;
  2253.     float y_71 = centarY + y71 ;
  2254.  
  2255.     if(point_x > x_0) side = 0; // lijeva strana maske
  2256.     else if(point_x < x_0) side =1; // desna strana maske
  2257.  
  2258.  
  2259.     // pozicija misa je istinita (true) u danom podrucju
  2260.     return((point_x <= x_100 && point_x >= x_74 && point_y >= y_100 && point_y <= y_69) || (point_x <= x_107 && point_x >= x_68 && point_y >= y_107 && point_y <= y_71));
  2261.  
  2262.  
  2263. }
  2264.  
  2265. bool COpenGLWnd::MoveEyesVD_Width(CPoint &point){
  2266. // faceShape[29] i faceShape[31]
  2267.     var = 29;
  2268.    
  2269.     // y koordinate verteksa
  2270.     float y53 = vt2->fbft->projection->data.fl[2*53+1];
  2271.     float y56 = vt2->fbft->projection->data.fl[2*56+1];
  2272.     float y23 = vt2->fbft->projection->data.fl[2*23+1];
  2273.     float y20 = vt2->fbft->projection->data.fl[2*20+1];
  2274.  
  2275.     float r = 0.03;
  2276.    
  2277.  
  2278.     // x koordinate verteksa
  2279.     float x53 = vt2->fbft->projection->data.fl[2*53];
  2280.     float x56 = vt2->fbft->projection->data.fl[2*56];
  2281.     float x23 = vt2->fbft->projection->data.fl[2*23];
  2282.     float x20 = vt2->fbft->projection->data.fl[2*20];
  2283.  
  2284.     // x koordinata verteksa 55 i 22 (otprilike centar ociju po x)
  2285.     float x55 = vt2->fbft->projection->data.fl[2*55];
  2286.     float x22 = vt2->fbft->projection->data.fl[2*22];
  2287.  
  2288.     // x koordinata verteksa 0 (otprilike centar maske po x)
  2289.     float x0 = vt2->fbft->projection->data.fl[2*0];
  2290.  
  2291.     // podesavanje granica na [-1,1] i [-1.3333, 1.3333]
  2292.     SetRange(point);
  2293.  
  2294.     // x i y kordinate verteksa u odnosu na centar slike
  2295.     float x_53 = centarX + x53 ;
  2296.     float x_56 = centarX + x56 ;
  2297.     float x_23 = centarX + x23 ;
  2298.     float x_20 = centarX + x20 ;
  2299.  
  2300.     float x_55 = centarX + x55 ;
  2301.     float x_22 = centarX + x22 ;
  2302.     float x_0 = centarX + x0 ;
  2303.  
  2304.     float y_53 = centarY + y53 ;
  2305.     float y_56 = centarY + y56 ;
  2306.     float y_23 = centarY + y23 ;
  2307.     float y_20 = centarY + y20 ;
  2308.  
  2309.     if((point_x > x_55 &&  point_x < x_53) || (point_x > x_22 &&  point_x < x_23)) side = 0; // lijeva strana maske
  2310.     else if((point_x > x_56 &&  point_x < x_55) || (point_x > x_20 &&  point_x < x_22)) side =1; // desna strana maske
  2311.  
  2312.  
  2313.     /// pozicija misa je istinita (true) u danom podrucju
  2314.     return (((x_53 - point_x)*(x_53 - point_x) + (y_53 - point_y)*(y_53 - point_y)) < r*r) || (((x_20 - point_x)*(x_20 - point_x) + (y_20 - point_y)*(y_20 - point_y)) < r*r) ||(((x_56 - point_x)*(x_56 - point_x) + (y_56 - point_y)*(y_56 - point_y)) < r*r) ||(((x_23 - point_x)*(x_23 - point_x) + (y_23 - point_y)*(y_23 - point_y)) < r*r);
  2315.  
  2316. }
  2317. bool COpenGLWnd::MoveEyesHeight(CPoint &point){
  2318.     // faceShape[30]
  2319.     var = 30;
  2320.    
  2321.     // y koordinate verteksa
  2322.    
  2323.     float y52 = vt2->fbft->projection->data.fl[2*52+1];
  2324.     float y22 = vt2->fbft->projection->data.fl[2*22+1];
  2325.     float y55 = vt2->fbft->projection->data.fl[2*55+1];
  2326.     float y21 = vt2->fbft->projection->data.fl[2*21+1];
  2327.  
  2328.     float r = 0.03;
  2329.    
  2330.  
  2331.     // x koordinate verteksa
  2332.     float x69 = vt2->fbft->projection->data.fl[2*69];
  2333.     float x73 = vt2->fbft->projection->data.fl[2*73];
  2334.     float x71 = vt2->fbft->projection->data.fl[2*71];
  2335.     float x67 = vt2->fbft->projection->data.fl[2*67];
  2336.  
  2337.     // podesavanje granica na [-1,1] i [-1.3333, 1.3333]
  2338.     SetRange(point);
  2339.  
  2340.     // x i y kordinate verteksa u odnosu na centar slike
  2341.     float x_69 = centarX + x69 ;
  2342.     float x_73 = centarX + x73 ;
  2343.     float x_71 = centarX + x71 ;
  2344.     float x_67 = centarX + x67 ;
  2345.    
  2346.  
  2347.     float y_52up = centarY + (y52 + 0.03);
  2348.     float y_52 = centarY + y52 ;
  2349.     float y_21up = centarY + (y21 + 0.03);
  2350.     float y_21 = centarY + y21 ;
  2351.     float y_22 = centarY + y22 ;
  2352.     float y_22down = centarY + (y22 - 0.03);   
  2353.     float y_55 = centarY + y55 ;
  2354.     float y_55down = centarY + (y55 - 0.03);
  2355.    
  2356.    
  2357.  
  2358.     // pozicija misa je istinita (true) u danom podrucju
  2359.     return((point_x <= x_69 && point_x >= x_73 && point_y >= y_52 && point_y <= y_52up) || (point_x <= x_69 && point_x >= x_73 && point_y >= y_55down && point_y <= y_55) || (point_x <= x_71 && point_x >= x_67 && point_y >= y_21 && point_y <= y_21up) || (point_x <= x_71 && point_x >= x_67 && point_y >= y_22down && point_y <= y_22));
  2360.  
  2361.  
  2362. }
  2363.  
  2364. bool COpenGLWnd::MoveMouthVP(CPoint &point){
  2365. // faceShape[32]
  2366.     var = 32;
  2367.    
  2368.     // y koordinate verteksa
  2369.     float y8 = vt2->fbft->projection->data.fl[2*8+1];
  2370.     float y7 = vt2->fbft->projection->data.fl[2*7+1];
  2371.  
  2372.     // x koordinate verteksa
  2373.     float x82 = vt2->fbft->projection->data.fl[2*82];
  2374.     float x83 = vt2->fbft->projection->data.fl[2*83];
  2375.  
  2376.     // podesavanje granica na [-1,1] i [-1.3333, 1.3333]
  2377.     SetRange(point);
  2378.  
  2379.     // x i y kordinate verteksa u odnosu na centar slike
  2380.     float x_82 = centarX + x82 ;
  2381.     float x_83 = centarX + x83 ;
  2382.  
  2383.     float y_8 = centarY + y8 ;
  2384.     float y_7 = centarY + y7 ;
  2385.  
  2386.     // pozicija misa je istinita (true) u danom podrucju
  2387.     return(point_x <= x_82 && point_x >= x_83 && point_y >= y_8 && point_y <= y_7);
  2388.  
  2389.  
  2390. }
  2391. bool COpenGLWnd::MoveMouthWidth_Bending(CPoint &point){
  2392. // faceShape[33] I faceShape[34]
  2393.     var = 33;
  2394.    
  2395.     // y koordinate verteksa
  2396.     float y7 = vt2->fbft->projection->data.fl[2*7+1];
  2397.     float y8 = vt2->fbft->projection->data.fl[2*8+1];
  2398.    
  2399.    
  2400.  
  2401.     // x koordinate verteksa
  2402.     float x64 = vt2->fbft->projection->data.fl[2*64];
  2403.     float x89 = vt2->fbft->projection->data.fl[2*89];
  2404.     float x88 = vt2->fbft->projection->data.fl[2*88];
  2405.     float x31 = vt2->fbft->projection->data.fl[2*31];
  2406.  
  2407.     // x koordinata verteksa 0 (otprilike centar maske po x)
  2408.     float x0 = vt2->fbft->projection->data.fl[2*0];
  2409.  
  2410.     // podesavanje granica na [-1,1] i [-1.3333, 1.3333]
  2411.     SetRange(point);
  2412.  
  2413.     // x i y kordinate verteksa u odnosu na centar slike
  2414.     float x_64 = centarX + x64 ;
  2415.     float x_89 = centarX + x89 ;
  2416.     float x_88 = centarX + x88 ;
  2417.     float x_31 = centarX + x31 ;
  2418.     float x_0 = centarX + x0 ;
  2419.  
  2420.     float y_8 = centarY + y8 ;
  2421.     float y_7 = centarY + y7 ;
  2422.  
  2423.     if(point_x > x_0) side = 0; // lijeva strana maske
  2424.     else if(point_x < x_0) side =1; // desna strana maske
  2425.  
  2426.  
  2427.     // pozicija misa je istinita (true) u danom podrucju
  2428.     return((point_x <= x_64 && point_x >= x_89 && point_y >= y_8 && point_y <= y_7) || (point_x <= x_88 && point_x >= x_31 && point_y >= y_8 && point_y <= y_7));
  2429.  
  2430.  
  2431. }
  2432. bool COpenGLWnd::MoveMouthLipThickness(CPoint &point){
  2433. // faceShape[35]
  2434.     var = 35;
  2435.    
  2436.     // y koordinate verteksa
  2437.     float y8 = vt2->fbft->projection->data.fl[2*8+1];
  2438.     float y7 = vt2->fbft->projection->data.fl[2*7+1];
  2439.  
  2440.     // y koordinata verteksa 80 (otprilike centar usta)
  2441.     float y80 = vt2->fbft->projection->data.fl[2*80+1];
  2442.  
  2443.     float y7up = y7 + 0.03;
  2444.     float y8down = y8 - 0.03;
  2445.  
  2446.     // x koordinate verteksa
  2447.     float x66 = vt2->fbft->projection->data.fl[2*66];
  2448.     float x33 = vt2->fbft->projection->data.fl[2*33];
  2449.  
  2450.     // podesavanje granica na [-1,1] i [-1.3333, 1.3333]
  2451.     SetRange(point);
  2452.  
  2453.     // x i y kordinate verteksa u odnosu na centar slike
  2454.     float x_66 = centarX + x66 ;
  2455.     float x_33 = centarX + x33 ;
  2456.    
  2457.     float y_80 = centarY + y80 ;
  2458.     float y_8 = centarY + y8 ;
  2459.     float y_8down = centarY + y8down ;
  2460.     float y_7 = centarY + y7 ;
  2461.     float y_7up = centarY + y7up ;
  2462.  
  2463.     if(point_y > y_80) side = 0; // up
  2464.     else if(point_y < y_80) side =1; // down
  2465.  
  2466.     // pozicija misa je istinita (true) u danom podrucju
  2467.     return ((point_x <= x_66 && point_x >= x_33 && point_y >= y_7 && point_y <= y_7up) || (point_x <= x_66 && point_x >= x_33 && point_y >= y_8down && point_y <= y_8)) ;
  2468.  
  2469.  
  2470. }
  2471.  
  2472. void COpenGLWnd::RightButtonDown(int x, int y)
  2473. {
  2474.     mRightButtonX = (GLfloat)x;
  2475.     mRightButtonY = (GLfloat)y;
  2476.     mRotateXAngleAdd = 0;
  2477.     mRotateYAngleAdd = 0;
  2478.  
  2479.     // SetTimer(mhWnd, (UINT) IGLW_TIMER_ROTATE, 100, NULL);
  2480.     // SetCapture(mhWnd);
  2481. }
  2482.  
  2483. void COpenGLWnd::LeftButtonControlDown(int x, int y)
  2484. {
  2485.     // Y gives the zoom factor in Z direction.
  2486.     mLeftButtonControlZ = (GLfloat)y;
  2487. }
  2488. void COpenGLWnd::RightButtonControlDown(int x, int y){
  2489.     mRightButtonControlY = (GLfloat)y;
  2490.     mRightButtonControlX = (GLfloat)x;
  2491.  
  2492. }
  2493. void COpenGLWnd::LeftButtonDrag(float x, float y)
  2494. {
  2495.     if(!trackerActive){
  2496.    
  2497.    
  2498.     mXTranslate += (x - mLeftButtonX) * mXAccel;
  2499.     // Windows y-axis is reversed to openGL.
  2500.     mYTranslate -= (y - mLeftButtonY) * mYAccel;
  2501.  
  2502.  
  2503.     // Save off current position
  2504.     mLeftButtonX = (GLfloat)x;
  2505.     mLeftButtonY = (GLfloat)y;
  2506.  
  2507.     // Redraw screen.
  2508.     RenderToScreen();
  2509.    
  2510.     }
  2511.  
  2512.     else{
  2513.     if(var==40){
  2514.         ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZENS));
  2515.         faceShape[40] +=  (GLfloat)(y - mLeftButtonY )*0.02;
  2516.     }// jaw height
  2517.     else if(var==38){
  2518.         ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEALL));
  2519.         faceShape[38] -= (GLfloat)(y - mLeftButtonY)*0.008; // iris height
  2520.         if(side == 0)faceShape[39] -= (GLfloat)(x - mLeftButtonX)*0.02; // left iris width
  2521.         else if(side == 1)faceShape[39] += (GLfloat)(x - mLeftButtonX)*0.02; // right iris width
  2522.         }
  2523.     else if(var==0){
  2524.         ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZENS));
  2525.         faceShape[0] -=  (GLfloat)(y - mLeftButtonY )*0.02;
  2526.     }// head height
  2527.     else if(var==1 && side == 0){
  2528.         ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEWE));
  2529.         faceShape[1] -= (GLfloat)(x - mLeftButtonX)*0.02;
  2530.     } // left head upper width
  2531.     else if(var==1 && side == 1){
  2532.         ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEWE));
  2533.         faceShape[1] += (GLfloat)(x - mLeftButtonX)*0.02;
  2534.     } // right head upper width
  2535.     else if(var==2 && side == 0){
  2536.         ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEWE));
  2537.         faceShape[2] -= (GLfloat)(x - mLeftButtonX)*0.02;
  2538.     }// left head middle width
  2539.     else if(var==2 && side == 1){
  2540.         ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEWE));
  2541.         faceShape[2] += (GLfloat)(x - mLeftButtonX)*0.02;
  2542.     }// right head middle width
  2543.     else if(var==3 && side == 0){
  2544.         ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEWE));
  2545.         faceShape[3] -= (GLfloat)(x - mLeftButtonX)*0.02;
  2546.     }// left head lower width
  2547.     else if(var==3 && side == 1){
  2548.         ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEWE));
  2549.         faceShape[3] += (GLfloat)(x - mLeftButtonX)*0.02;
  2550.     }// right head lower width
  2551.     else if(var==4 && side == 0){
  2552.         ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEWE));
  2553.         faceShape[4] -= (GLfloat)(x - mLeftButtonX)*0.02;
  2554.     }// left chin width
  2555.     else if(var==4 && side == 1){
  2556.         ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEWE));
  2557.         faceShape[4] += (GLfloat)(x - mLeftButtonX)*0.02;
  2558.         ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEWE));
  2559.     }// right chin width
  2560.     else if(var==5){
  2561.         ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZENS));
  2562.         faceShape[5] -= (GLfloat)(y - mLeftButtonY)*0.02;
  2563.     }// nose upper vertical position
  2564.     else if(var==6){
  2565.         ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEALL));
  2566.         faceShape[6] -= (GLfloat)(y - mLeftButtonY)*0.02; // nose middle vertical position
  2567.         faceShape[9] -= (GLfloat)(x - mLeftButtonX)*0.02; // nose middle width
  2568.         }
  2569.     else if(var==7){
  2570.         ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZENS));
  2571.         faceShape[7] -= (GLfloat)(y - mLeftButtonY)*0.02;
  2572.     }// nose lower vertical position
  2573.     else if(var==8){
  2574.         ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEWE));
  2575.         if(side == 0)// left nose upper width
  2576.             faceShape[8] -= (GLfloat)(x - mLeftButtonX)*0.02;
  2577.         else if (side == 1)// right nose upper width
  2578.             faceShape[8] += (GLfloat)(x - mLeftButtonX)*0.02;
  2579.     }
  2580.    
  2581.     else if(var==10){
  2582.         ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEWE));
  2583.         if(side == 0)// left nose lower width
  2584.             faceShape[10] -= (GLfloat)(x - mLeftButtonX)*0.02;
  2585.         else if(side == 1)// right nose lower width
  2586.             faceShape[10] += (GLfloat)(x - mLeftButtonX)*0.02;
  2587.     }
  2588.     else if(var==14){
  2589.         ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEWE));
  2590.         if(side == 0)// left nose thickness
  2591.             faceShape[14] -= (GLfloat)(x - mLeftButtonX)*0.02;
  2592.         else if(side == 1)// right nose thickness
  2593.             faceShape[14] += (GLfloat)(x - mLeftButtonX)*0.02;
  2594.     }
  2595.     else if(var==19){
  2596.         ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZENS));
  2597.         faceShape[19] -= (GLfloat)(y - mLeftButtonY)*0.02;
  2598.     }// eyebrows between vertical position
  2599.     else if(var==20){
  2600.         ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEALL));
  2601.         faceShape[20] -= (GLfloat)(y - mLeftButtonY)*0.02; // eyebrows inner vertical position
  2602.         if(side == 0)faceShape[21] -= (GLfloat)(x - mLeftButtonX)*0.02; // left eyebrows inner separation distance
  2603.         else if(side == 1)faceShape[21] += (GLfloat)(x - mLeftButtonX)*0.02; // right eyebrows inner separation distance
  2604.         }
  2605.     else if(var==22){
  2606.         ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEALL));
  2607.         faceShape[22] -= (GLfloat)(y - mLeftButtonY)*0.02; // eyebrows outer vertical position
  2608.         if(side == 0)faceShape[23] -= (GLfloat)(x - mLeftButtonX)*0.02; // left eyebrows outer separation distance
  2609.         else if(side == 1)faceShape[23] += (GLfloat)(x - mLeftButtonX)*0.02; // right eyebrows outer separation distance
  2610.         }
  2611.     else if(var==24){
  2612.         ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEALL));
  2613.         faceShape[24] -= (GLfloat)(y - mLeftButtonY)*0.02; // eyebrows middle vertical position
  2614.         if(side == 0)faceShape[25] -= (GLfloat)(x - mLeftButtonX)*0.02; // left eyebrows middle separation distance
  2615.         else if(side == 1)faceShape[25] += (GLfloat)(x - mLeftButtonX)*0.02; // right eyebrows middle separation distance
  2616.         }
  2617.     else if(var==26){
  2618.         ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZENS));
  2619.         faceShape[26] -= (GLfloat)(y - mLeftButtonY)*0.02;
  2620.     }// eyebrows thickness
  2621.     else if(var==27){
  2622.         ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEALL));
  2623.         faceShape[27] -= (GLfloat)(y - mLeftButtonY)*0.02; // eyes vertical position
  2624.         if(side == 0)faceShape[28] -= (GLfloat)(x - mLeftButtonX)*0.02; // left eyes separation distance
  2625.         else if(side == 1)faceShape[28] += (GLfloat)(x - mLeftButtonX)*0.02; // right eyes separation distance
  2626.         }
  2627.     else if(var==29){
  2628.         ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEALL));
  2629.         faceShape[29] -= (GLfloat)(y - mLeftButtonY)*0.008; // eyes vertical difference
  2630.         if(side == 0)faceShape[31] -= (GLfloat)(x - mLeftButtonX)*0.02; // left eyes width
  2631.         else if(side == 1)faceShape[31] += (GLfloat)(x - mLeftButtonX)*0.02; // right eyes width
  2632.         }
  2633.     else if(var==30){
  2634.         ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZENS));
  2635.         faceShape[30] -= (GLfloat)(y - mLeftButtonY)*0.02;
  2636.     }// eyes height
  2637.     else if(var==32){
  2638.         ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZENS));
  2639.         faceShape[32] -= (GLfloat)(y - mLeftButtonY)*0.02;
  2640.     }// mouth vertical position
  2641.     else if(var==33){
  2642.         ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEALL));
  2643.         faceShape[34] += (GLfloat)(y - mLeftButtonY)*0.02; // mouth bending
  2644.         if(side == 0)faceShape[33] -= (GLfloat)(x - mLeftButtonX)*0.02; // left mouth width
  2645.         else if(side == 1)faceShape[33] += (GLfloat)(x - mLeftButtonX)*0.02; // right mouth width
  2646.         }
  2647.     else if(var==35){  
  2648.         ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZENS));
  2649.         if(side == 0)faceShape[35] -= (GLfloat)(y - mLeftButtonY)*0.02; // mouth lip thickness up
  2650.         else if(side == 1)faceShape[35] += (GLfloat)(y - mLeftButtonY)*0.02; // mouth lip thickness down
  2651.     }
  2652.     /*else if(var==36){
  2653.         ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZENS));
  2654.         faceShape[36] +=  (GLfloat)(y - mLeftButtonY )*0.2;
  2655.     }//jaw*/
  2656.    
  2657.     // Save off current position
  2658.     mLeftButtonY = (GLfloat)y;
  2659.     mLeftButtonX = (GLfloat)x;
  2660.     /*
  2661.     mXTranslate += (x - mLeftButtonX) * mXAccel;
  2662.  
  2663.     // Windows y-axis is reversed to openGL.
  2664.     mYTranslate -= (y - mLeftButtonY) * mYAccel;
  2665.  
  2666.     // Save off current position
  2667.     mLeftButtonX = (GLfloat)x;
  2668.     mLeftButtonY = (GLfloat)y;
  2669.  
  2670.     // Redraw screen.
  2671.    
  2672.     */
  2673.     }
  2674. }
  2675.  
  2676. void COpenGLWnd::RightButtonDrag(int x, int y)
  2677. {
  2678.     if(trackerActive){
  2679.     faceTranslation[1] -= (y - mRightButtonY)*0.009;
  2680.     mRightButtonY = (GLfloat)y;
  2681.    
  2682.     faceTranslation[0] -= (x - mRightButtonX)*0.009;
  2683.     mRightButtonX = (GLfloat)x;
  2684.     }
  2685.     else{
  2686.    
  2687.     // Rotates object around X or Y axis, distance from first point gives angular rotation speed.
  2688.     // Y axis rotation is given by distance in X coords, and vice versa.
  2689.     mRotateXAngleAdd = (GLfloat)((y - mRightButtonY) * 0.1);
  2690.     mRotateYAngleAdd = (GLfloat)((x - mRightButtonX) * 0.1);
  2691.     }
  2692. }
  2693.  
  2694. void COpenGLWnd::RightButtonControlDrag(int x, int y){
  2695.     faceRotation[1] -= (x - mRightButtonControlX)*0.005;
  2696.     faceRotation[0] -= (y - mRightButtonControlY)*0.005;
  2697.     mRightButtonControlX = (GLfloat)x;
  2698.     mRightButtonControlY = (GLfloat)y;
  2699. }
  2700.  
  2701. void COpenGLWnd::RightButtonControlShiftDrag(int x, int y){
  2702.     faceRotation[2] -= (y - mRightButtonControlY)*0.005;
  2703.     mRightButtonControlY = (GLfloat)y;
  2704. }
  2705.  
  2706. void COpenGLWnd::LeftButtonControlDrag(int x, int y)
  2707. {
  2708.     if (!trackerActive){
  2709.     mZTranslate += (y - mLeftButtonControlZ) * mZAccel;
  2710.     mLeftButtonControlZ = (GLfloat)y;
  2711.  
  2712.     RenderToScreen();
  2713.    
  2714.     }
  2715.     else{
  2716.     faceScale[0] -=(y - mLeftButtonY)*0.002;
  2717.     mLeftButtonY = (GLfloat)y;
  2718.     }
  2719.  
  2720. }
  2721.  
  2722. void COpenGLWnd::RightButtonDownTimerFunc()
  2723. {
  2724.     mXRotAngle += mRotateXAngleAdd;
  2725.     mYRotAngle += mRotateYAngleAdd;
  2726.  
  2727.     // Keep it within 360 degrees so that we don't get unpleasant surprises if datatype overflows.
  2728.     if(mXRotAngle > 360.0f)
  2729.         mXRotAngle -= 360.0f;
  2730.     if(mXRotAngle < 0.0f)
  2731.         mXRotAngle += 360.0f;
  2732.    
  2733.     if(mYRotAngle > 360.0f)
  2734.         mYRotAngle -= 360.0f;
  2735.     if(mYRotAngle < 0.0f)
  2736.         mYRotAngle += 360.0f;
  2737.  
  2738.     RenderToScreen();
  2739. }
  2740.  
  2741. void COpenGLWnd::FitToScreen()
  2742. {
  2743.     mXTranslate = mXTranslateFit;
  2744.     mYTranslate = mYTranslateFit;
  2745.     mZTranslate = mZTranslateFit;
  2746.    
  2747.     mXRotAngle = 0;
  2748.     mYRotAngle = 0;
  2749.  
  2750.     RenderToScreen();
  2751. }
  2752.  
  2753. void COpenGLWnd::FitToScreen(float zoom)
  2754. {
  2755.     mXTranslate = mXTranslateFit;
  2756.     mYTranslate = mYTranslateFit;
  2757.     mZTranslate = mZTranslateFit * zoom;
  2758.    
  2759.     mXRotAngle = 0;
  2760.     mYRotAngle = 0;
  2761.  
  2762.     RenderToScreen();
  2763. }
  2764.  
  2765.  
  2766.  
  2767. /**************************************************************************/
  2768. /**************************************************************************/
  2769. /**************************************************************************/
  2770. /****************           VISAGE TRACKER 2       ************************/
  2771. /**************************************************************************/
  2772. /**************************************************************************/
  2773. /**************************************************************************/
  2774.  
  2775.  
  2776. char* COpenGLWnd::ChooseSuFileName()
  2777. {
  2778.     CDialogFirstTimeTrackingNew dlg;
  2779.     char *suFileName = (char*)malloc(200);
  2780.     dlg.suFileName = suFileName;
  2781.  
  2782.     dlg.DoModal();
  2783.  
  2784.     return suFileName;
  2785. }
  2786.  
  2787. void COpenGLWnd::displayMessage(char *userMessage,char *caption,int type)
  2788. {
  2789.     MessageBox(userMessage,caption,type);
  2790. }
  2791.  
  2792. void COpenGLWnd::setOpenGLContext()
  2793. {
  2794.     // set current window
  2795.     glutSetWindow(glutMainWindow);
  2796.  
  2797.     // set the context
  2798.     //wglMakeCurrent(m_pDC->GetSafeHdc(), m_hRC1);
  2799.     glViewport(0,0,mWindowWidth,mWindowHeight);                     // Reset The Current Viewport
  2800.    
  2801.     // clear the frame buffer before next drawing
  2802.     glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
  2803.  
  2804.     //verify color depth - FaceTracker needs 8 bits for each color
  2805.     static bool verified = false; // verify only once
  2806.     if(!verified)
  2807.     {
  2808.         verified = true;
  2809.         GLint redBits=0, greenBits=0, blueBits=0;
  2810.  
  2811.         glGetIntegerv (GL_RED_BITS, &redBits);
  2812.         glGetIntegerv (GL_GREEN_BITS, &greenBits);
  2813.         glGetIntegerv (GL_BLUE_BITS, &blueBits);
  2814.  
  2815.         if(redBits < 8 || greenBits < 8 || blueBits < 8)
  2816.         {
  2817.             MessageBox("The color depth of your graphics system is too low. FaceTracker2 requires 32 bits per pixel (True Color) for correct operation. Please change your graphics settings to True Color or 32 bit color depth.","Error",MB_ICONERROR);
  2818.             exit(0);
  2819.         }
  2820.     }
  2821. }
  2822.  
  2823. void COpenGLWnd::swapOpenGLBuffers()
  2824. {
  2825.     //SwapBuffers(m_pDC->GetSafeHdc());
  2826.     //wglMakeCurrent(NULL, NULL);
  2827.     glutSwapBuffers();
  2828. }
  2829.  
  2830. void COpenGLWnd::ManuallyAdjustShapeMask(float *face_translation, float *face_rotation, float *face_scale, float *face_shape)
  2831. {
  2832.     otvoren_dialog = true;
  2833.     faceShape = face_shape;
  2834.     faceScale = face_scale;
  2835.     faceRotation = face_rotation;
  2836.     faceTranslation = face_translation;
  2837.  
  2838.    
  2839.     CDialogNew shpman;
  2840.     shpman.vt2=vt2;
  2841.     shpman.faceTranslation=face_translation;
  2842.     shpman.faceRotation=face_rotation;
  2843.     shpman.faceScale=face_scale;
  2844.     shpman.faceShape=face_shape;
  2845.     nRet = shpman.DoModal();
  2846.  
  2847.  
  2848.     if ( nRet == IDOK || nRet == IDCANCEL  )
  2849.     {zatvoren_dialog = 5;
  2850.    
  2851.     }
  2852.    
  2853.            
  2854. }
  2855.  
  2856. void _signalWhenUserReady(void *_arg)
  2857. {
  2858.     char **arg = (char**)_arg;
  2859.     char *userMessage = (char*)arg[0];
  2860.     bool *readyFlag = (bool*)arg[1];
  2861.  
  2862.     MessageBox(0,userMessage,"",MB_OK);
  2863.  
  2864.     readyFlag[0] = true;
  2865.     free(arg);
  2866. }
  2867.  
  2868. void COpenGLWnd::signalWhenUserReady(char *userMessage,bool *readyFlag)
  2869. {
  2870.     char **arg = (char**) malloc(2*sizeof(char*));
  2871.     arg[0] = userMessage;
  2872.     arg[1] = (char*)readyFlag;
  2873.     _beginthread(_signalWhenUserReady,0,arg);
  2874. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement