Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // OpenGLWnd.cpp : implementation file
- //
- #include "stdafx.h"
- #include "OpenGLWndFaceTracker.h"
- #include "MainFrm.h"
- #include "VRMLFitToScreenTraverser.h"
- #include <process.h>
- #include <gl\glaux.h>
- #include <assert.h>
- #include <math.h>
- #include <stdlib.h>
- #include <sys/timeb.h>
- #include <sys/types.h>
- #include <iostream>
- #include <fstream>
- //#include "DialogShapeManager.h"
- #include "DialogNew.h"
- #include "glut.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- #define ANIM_VIEW_SIZE 0.35
- #define SLIDER_RESOLUTION 200
- /////////////////////////////////////////////////////////////////////////////
- // COpenGLWnd
- // -------------------------------------------------
- // My own code
- // -------------------------------------------------
- const int COpenGLWnd::mTIMER_RENDERING_INTERVAL = 20;
- const int COpenGLWnd::mTIMER_ROTATE_INTERVAL = 30;
- void COpenGLWnd::Init(VRMLModel *theModel)
- {
- SetContext();
- BaseOGLVRMLModelRenderer::Init(theModel);
- glShadeModel(GL_SMOOTH); // Enable Smooth Shading
- glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Black Background
- glClearDepth(1.0f); // Depth Buffer Setup
- glEnable(GL_DEPTH_TEST); // Enables Depth Testing
- glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do
- // glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations
- // For performance we set all of these to fastest.
- glHint(GL_LINE_SMOOTH_HINT, GL_FASTEST);
- glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
- glHint(GL_POINT_SMOOTH_HINT, GL_FASTEST);
- glHint(GL_POLYGON_SMOOTH_HINT, GL_FASTEST);
- // Can't assume that normals aren't scaled. Therefore I need this.
- glEnable(GL_NORMALIZE);
- // Reset modelview matrix before getting coords.
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- // Retrieve max and min in all axes and also the worl-transformed coordinates in a vector.
- VRMLFitToScreenTraverser *tempFitter = new VRMLFitToScreenTraverser;
- tempFitter->Reset();
- theModel->traverse(theModel->rootNode, tempFitter);
- GLfloat sceneMinX, sceneMaxX, sceneMinY, sceneMaxY, sceneMinZ, sceneMaxZ;
- tempFitter->GetCoords(sceneMinX, sceneMaxX, sceneMinY, sceneMaxY, sceneMinZ, sceneMaxZ, mMaxRadius);
- GLfloat distance = (GLfloat)((mMaxRadius / 2.0) / mVGLR_PERSPECT_TAN_FOVY);
- // Make this constant.
- mFarPlane = distance * 10;
- mXTranslateFit = - (GLfloat)((sceneMinX + (abs(sceneMaxX - sceneMinX) / 2.0)));
- mYTranslateFit = - (GLfloat)((sceneMinY + (abs(sceneMaxY - sceneMinY) / 2.0)));
- mZTranslateFit = - (GLfloat)((distance + (abs(sceneMinZ - sceneMaxZ) / 2.0)));
- mXTranslate = mXTranslateFit;
- mYTranslate = mYTranslateFit;
- mZTranslate = mZTranslateFit;
- // Translate and zoom acceleration depends on size of model.
- mXAccel = (GLfloat)(fabs(sceneMinX - sceneMaxX) * 0.005);
- mYAccel = (GLfloat)(fabs(sceneMinX - sceneMaxX) * 0.005);
- mZAccel = (GLfloat)(fabs(sceneMinZ - sceneMaxZ) * 0.005);
- Accel = (GLfloat)(2 * 0.005);
- delete tempFitter;
- SetRenderingMode(mRenderingMode);
- if(mWindowWidth && mWindowHeight)
- ReSizeGLScene(mWindowWidth, mWindowHeight);
- SwapGLBuffers();
- }
- /**
- * Render all attached VRML models to screen using OpenGL commands.
- * The actual rendering is implemented in VRMLRenderer, the parent class.
- *
- * This function is called automatically by OnTimer() so only in special occassions it may
- * be interesting to call it directly. One such occassion is just after a textured model is loaded
- * in order to enforce loading of textures. In fact, when the VRMLModel is loaded from a file the
- * texture file names are stored but texture images are not actually loaded. This is done by the
- * renderer when it renders the textured model first time. That can take some time, and it may be desirable
- * to call RenderToScreen() and thus force the loading of textures. The function will return after the
- * textures are loaded and the models rendered.
- */
- void COpenGLWnd::RenderToScreen()
- {
- static CMainFrame* pMainWnd = 0;
- struct _timeb timebuffer;
- _ftime( &timebuffer );
- long current_time = 1000 * (long)timebuffer.time + timebuffer.millitm; //CHANGED BY I.K. added explicit cast
- static long last_times[50];
- static int cnt = -1;
- if(rendererBusy) // a simple mechanism to make sure that we do not draw again before last rendering is done
- {
- return;
- }
- rendererBusy = true;
- SetContext();
- if(cnt == -1)
- {
- cnt = 0;
- for(int i=0;i<10;i++)
- last_times[i]=0;
- }
- cnt++;
- if(cnt == 50) cnt = 0;
- renderingFrameRate = 50000.0f / (float)(current_time - last_times[cnt]);
- last_times[cnt] = current_time;
- glMatrixMode(GL_MODELVIEW);
- if(modelViewMatrix)
- {
- glLoadMatrixf(modelViewMatrix);
- }
- else
- {
- glLoadIdentity();
- glTranslatef(mXTranslate, mYTranslate, mZTranslate);
- glRotatef(mXRotAngle, 1.0f, 0.0f, 0.0f);
- glRotatef(mYRotAngle, 0.0f, 1.0f, 0.0f);
- }
- BaseOGLVRMLModelRenderer::RenderToScreen();
- SwapGLBuffers();
- rendererBusy = false;
- /* // display the frame rate
- if(!pMainWnd) pMainWnd = (CMainFrame*)AfxGetMainWnd();
- char tmpmsg[100];
- sprintf(tmpmsg,"%2.2f FPS",renderingFrameRate);
- pMainWnd->m_wndStatusBar.SetPaneText( 0, tmpmsg, TRUE );*/
- }
- /**
- * Close down the renderer.
- * Tidy up and close the rendering system.
- */
- void COpenGLWnd::Close()
- {
- // Kill any pending timers.
- KillTimer(ID_ROTATE);
- SetContext();
- mXAccel = mYAccel = mZAccel = 0;
- mXTranslate = 0;
- mYTranslate = 0;
- mZTranslate = 0;
- mXRotAngle = 0;
- mYRotAngle = 0;
- BaseOGLVRMLModelRenderer::Close();
- SwapGLBuffers();
- }
- // -------------------------------------------------
- // VisualC++ added code below
- // -------------------------------------------------
- IMPLEMENT_DYNCREATE(COpenGLWnd, CView)
- COpenGLWnd::COpenGLWnd()
- : otvoren_dialog(false)
- {
- m_ToolTip.Create(this);
- mLeftButtonDown = false;
- mRightButtonDown = false;
- m_bTimerSet = false;
- m_pDC = NULL;
- m_bSwap = true;
- bgtexture[0] = 0;
- mXTranslate = 0;
- mYTranslate = 0;
- mZTranslate = 0;
- mXRotAngle = 0;
- mYRotAngle = 0;
- // mZRotAngle = 0;
- mVGLR_PERSPECT_FOVY = 45.0f;
- mVGLR_PERSPECT_TAN_FOVY = tan(mVGLR_PERSPECT_FOVY / 2.0);
- mVGLR_PERSPECT_NEAR_PLANE = 0.1f;
- mFarPlane = 100.0f;
- mRenderingMode = VGLR_RENDERING_AS_IS;
- mBackfaceCull = true;
- modelViewMatrix = 0;
- trackerActive=false;
- }
- COpenGLWnd::~COpenGLWnd()
- {
- wglMakeCurrent(0,0);
- wglDeleteContext(m_hRC);
- wglDeleteContext(m_hRC1);
- if( m_pDC )
- {
- delete m_pDC;
- }
- }
- // Standard OpenGL Init Stuff
- BOOL COpenGLWnd::SetupPixelFormat()
- {
- PIXELFORMATDESCRIPTOR pfdMain;
- memset( &pfdMain , 0 , sizeof( PIXELFORMATDESCRIPTOR ) );
- pfdMain.nSize = sizeof( PIXELFORMATDESCRIPTOR );
- pfdMain.nVersion = 1;
- pfdMain.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
- pfdMain.iPixelType = PFD_TYPE_RGBA;
- // Set to 16 for performance reasons.
- pfdMain.cColorBits = 16;
- pfdMain.cRedBits = 8;
- pfdMain.cRedShift = 16;
- pfdMain.cGreenBits = 8;
- pfdMain.cGreenShift = 8;
- pfdMain.cBlueBits = 8;
- pfdMain.cBlueShift = 0;
- pfdMain.cAlphaBits = 0;
- pfdMain.cAlphaShift = 0;
- pfdMain.cAccumBits = 64;
- pfdMain.cAccumRedBits = 16;
- pfdMain.cAccumGreenBits = 16;
- pfdMain.cAccumBlueBits = 16;
- pfdMain.cAccumAlphaBits = 0;
- pfdMain.cDepthBits = 32;
- pfdMain.cStencilBits = 8;
- pfdMain.cAuxBuffers = 0;
- pfdMain.iLayerType = PFD_MAIN_PLANE;
- pfdMain.bReserved = 0;
- pfdMain.dwLayerMask = 0;
- pfdMain.dwVisibleMask = 0;
- pfdMain.dwDamageMask = 0;
- // int m_nPixelFormat = ::ChoosePixelFormat( m_pDC->GetSafeHdc(), &pfdMain );
- int m_nPixelFormat = ::ChoosePixelFormat( m_pDC->GetSafeHdc(), &pfdMain );
- if ( m_nPixelFormat == 0 )
- return FALSE;
- // return ::SetPixelFormat( m_pDC->GetSafeHdc(), m_nPixelFormat, &pfdMain );
- return ::SetPixelFormat( m_pDC->GetSafeHdc(), m_nPixelFormat, &pfdMain );
- }
- /**
- * Initialize OpenGL.
- * Perform necessary OpenGL initializations, including the startup of the rendering timer through StartRenderingTimer().
- */
- BOOL COpenGLWnd::InitOpenGL()
- {
- static int init = 0; //CHANGED BY I.K. added type specifier
- if(init) return true;
- init = 1;
- //Get a DC for the Client Area
- if (m_pDC != NULL) delete m_pDC;
- m_pDC = new CClientDC(this);
- //Failure to Get DC
- if( m_pDC == NULL )
- return FALSE;
- if( !SetupPixelFormat() )
- return FALSE;
- m_hRC = ::wglCreateContext( m_pDC->GetSafeHdc() );
- //m_hRC1 = ::wglCreateContext( m_pDC->GetSafeHdc() );
- //Failure to Create Rendering Context
- if(m_hRC == 0 )
- return FALSE;
- if(m_hRC1 == 0 )
- return FALSE;
- //Make the RC Current
- //if( ::wglMakeCurrent( m_pDC->GetSafeHdc(), m_hRC) == FALSE )
- // return FALSE;
- // REMOVE
- //if( ::wglMakeCurrent( NULL, NULL ) == FALSE )
- // return FALSE;
- rendererBusy = false;
- // StartRenderingTimer();
- // init glut
- int argc = 1;
- char *argv = "foo";
- glutInit(&argc, &argv);
- // create main window
- glutInitWindowPosition(0, 0);
- glutInitWindowSize(800, 600);
- glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
- glutMainWindow = glutCreateWindow("glut main");
- return TRUE;
- }
- BEGIN_MESSAGE_MAP(COpenGLWnd, CView)
- //{{AFX_MSG_MAP(COpenGLWnd)
- ON_WM_CREATE()
- ON_WM_ERASEBKGND()
- ON_WM_SIZE()
- ON_WM_LBUTTONDOWN()
- ON_WM_RBUTTONDOWN()
- ON_WM_KEYDOWN()
- ON_WM_LBUTTONUP()
- ON_WM_MOUSEMOVE()
- ON_WM_RBUTTONUP()
- ON_WM_TIMER()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // COpenGLWnd drawing
- void COpenGLWnd::OnDraw(CDC* pDC)
- {
- if(!trackerActive) //disable OpenGL calls during tracking so they do not disturb tracking
- RenderToScreen();
- }
- /////////////////////////////////////////////////////////////////////////////
- // COpenGLWnd diagnostics
- #ifdef _DEBUG
- void COpenGLWnd::AssertValid() const
- {
- CView::AssertValid();
- }
- void COpenGLWnd::Dump(CDumpContext& dc) const
- {
- CView::Dump(dc);
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // COpenGLWnd message handlers
- /**
- * Initialize OpenGL when window is created.
- *
- */
- int COpenGLWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CView::OnCreate(lpCreateStruct) == -1)
- return -1;
- if ( !InitOpenGL() )
- {
- MessageBox( "Error setting up OpenGL!", "Init Error!",
- MB_OK | MB_ICONERROR );
- return -1;
- }
- return 0;
- }
- // Override the errase background function to
- // do nothing to prevent flashing.
- BOOL COpenGLWnd::OnEraseBkgnd(CDC* pDC)
- {
- return true;
- }
- // Set a few flags to make sure OpenGL only renders
- // in its viewport.
- BOOL COpenGLWnd::PreCreateWindow(CREATESTRUCT& cs)
- {
- cs.style |= (WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CS_OWNDC);
- cs.lpszClass = ::AfxRegisterWndClass(CS_HREDRAW | CS_VREDRAW | CS_OWNDC | CS_DBLCLKS,
- ::LoadCursor(NULL, IDC_ARROW), NULL, NULL);
- return CView::PreCreateWindow(cs);
- }
- void COpenGLWnd::OnSize(UINT nType, int cx, int cy)
- {
- CView::OnSize(nType, cx, cy);
- if ( 0 >= cx || 0 >= cy || nType == SIZE_MINIMIZED )
- return;
- SetContext();
- ReSizeGLScene(cx, cy);
- }
- void COpenGLWnd::OnLButtonDown(UINT nFlags, CPoint point)
- {
- if(trackerActive && otvoren_dialog && zatvoren_dialog !=5){
- mLeftButtonDown = true;
- if( MoveJawHeight(point) || MoveIrisHeightWidth(point) || MoveHeadHeight(point) || MoveHeadUpperWidth(point) || MoveHeadMiddleWidth(point) || MoveHeadLowerWidth(point) || MoveChinWidth(point) || MoveJaw(point))
- {
- vt2->oglIface->setOpenGLContext();
- vt2->display_func();
- vt2->oglIface->swapOpenGLBuffers();
- m_ToolTip.Close();
- LeftButtonDown(point.x, point.y);
- }
- else if (MoveNoseUpperVerticalPosition(point) || MoveNoseUpperWidth(point) || MoveNoseMiddleVerticalPosition(point) || MoveNoseLowerVerticalPosition(point) || MoveNoseLowerWidth(point) || MoveNoseThickness(point))
- {
- vt2->oglIface->setOpenGLContext();
- vt2->display_func();
- vt2->oglIface->swapOpenGLBuffers();
- m_ToolTip.Close();
- LeftButtonDown(point.x, point.y);
- }
- else if (MoveEyebrowsBetweenVP(point) || MoveEyebrowsInnerVP_SD(point) || MoveEyebrowsOuterVP_SD
- (point) || MoveEyebrowsMiddleVP_SD(point) || MoveEyebrowsThickness(point))
- {
- vt2->oglIface->setOpenGLContext();
- vt2->display_func();
- vt2->oglIface->swapOpenGLBuffers();
- m_ToolTip.Close();
- LeftButtonDown(point.x, point.y);
- }
- else if(MoveEyesVP_SD(point) || MoveEyesVD_Width(point) || MoveEyesHeight(point))
- {
- vt2->oglIface->setOpenGLContext();
- vt2->display_func();
- vt2->oglIface->swapOpenGLBuffers();
- m_ToolTip.Close();
- LeftButtonDown(point.x, point.y);
- }
- else if (MoveMouthVP(point) || MoveMouthWidth_Bending(point) || MoveMouthLipThickness(point))
- {
- vt2->oglIface->setOpenGLContext();
- vt2->display_func();
- vt2->oglIface->swapOpenGLBuffers();
- m_ToolTip.Close();
- LeftButtonDown(point.x, point.y);
- }
- else{
- var = 100;
- LeftButtonDown(point.x, point.y);
- }
- }
- else{
- //--------------------for aam model-------------------
- if (nFlags & MK_CONTROL)
- LeftButtonControlDown(point.x, point.y);
- else
- LeftButtonDown(point.x, point.y);
- mLeftButtonDown = true;
- }
- }
- void COpenGLWnd::OnRButtonDown(UINT nFlags, CPoint point)
- {
- if(nFlags & MK_CONTROL)RightButtonControlDown(point.x, point.y);
- if((nFlags & MK_CONTROL) && (nFlags & MK_SHIFT))RightButtonControlDown(point.x, point.y);
- RightButtonDown(point.x, point.y);
- mRightButtonDown = true;
- }
- void COpenGLWnd::OnMouseMove(UINT nFlags, CPoint point)
- {
- //mouse move events when dialog box is open and trackerActive
- if (otvoren_dialog && zatvoren_dialog !=5 && trackerActive) {
- if(!mLeftButtonDown && zatvoren_dialog !=5)
- OnMouseMoveTips(nFlags, point);
- if((nFlags & MK_LBUTTON) && (nFlags & MK_CONTROL)){var = 100; LeftButtonControlDrag(point.x, point.y);}
- if((nFlags & MK_LBUTTON))
- {
- LeftButtonDrag(point.x, point.y);
- if(otvoren_dialog){
- vt2->oglIface->setOpenGLContext();
- vt2->display_func();
- vt2->oglIface->swapOpenGLBuffers();
- }
- //SetContext();
- // So we don't recieve events when user has not pressed anything.
- if(!mLeftButtonDown) {return;}
- }
- if ((nFlags & MK_RBUTTON) && (nFlags & MK_CONTROL) && (nFlags & MK_SHIFT) )RightButtonControlShiftDrag(point.x, point.y);
- else if ((nFlags & MK_RBUTTON) && (nFlags & MK_CONTROL))RightButtonControlDrag(point.x, point.y);
- else if (nFlags & MK_RBUTTON)
- {
- if(!mRightButtonDown) return;
- var = 100;
- RightButtonDrag(point.x, point.y);
- if(otvoren_dialog){
- vt2->oglIface->setOpenGLContext();
- vt2->display_func();
- vt2->oglIface->swapOpenGLBuffers();
- }
- }
- }
- else{ //for aam model
- if (!m_bTimerSet && mRightButtonDown) {
- SetTimer(ID_ROTATE, mTIMER_ROTATE_INTERVAL, NULL);
- m_bTimerSet = true;
- return;
- }
- if((nFlags & MK_LBUTTON))
- {
- // So we don't recieve events when user has not pressed anything.
- if(!mLeftButtonDown) return;
- LeftButtonDrag(point.x, point.y);
- SetContext();
- if(nFlags & MK_CONTROL)
- LeftButtonControlDrag(point.x, point.y);
- else if(!(nFlags & MK_SHIFT))
- LeftButtonDrag(point.x, point.y);
- }
- else if (nFlags & MK_RBUTTON)
- {
- if(!mRightButtonDown) return;
- RightButtonDrag(point.x, point.y);
- }
- }
- }
- void COpenGLWnd:: OnMouseMoveTips(UINT nFlags, CPoint point){
- if(MoveJawHeight(point) && !nFlags){
- ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZENS));
- tmp = 40;
- m_ToolTip.SetText("JAW HEIGHT");
- m_ToolTip.Show(point);
- }
- else if(MoveIrisHeightWidth(point) && !nFlags){
- ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZENS));
- tmp = 38;
- m_ToolTip.SetText("IRIS WIDTH and HEIGHT");
- m_ToolTip.Show(point);
- }
- else if(MoveHeadHeight(point) && !nFlags){
- ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZENS));
- tmp = 1;
- /*vt2->oglIface->setOpenGLContext();
- vt2->display_func();
- vt2->oglIface->swapOpenGLBuffers();*/
- m_ToolTip.SetText("HEAD HEIGHT");
- m_ToolTip.Show(point);
- }
- else if(MoveHeadUpperWidth(point) && !nFlags){
- ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEWE));
- tmp = 2;
- /*vt2->oglIface->setOpenGLContext();
- vt2->display_func();
- vt2->oglIface->swapOpenGLBuffers();*/
- m_ToolTip.SetText("HEAD UPPER WIDTH");
- m_ToolTip.Show(point);
- }
- else if(MoveHeadMiddleWidth(point) && !nFlags){
- ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEWE));
- tmp = 3;
- /*vt2->oglIface->setOpenGLContext();
- vt2->display_func();
- vt2->oglIface->swapOpenGLBuffers();*/
- m_ToolTip.SetText("HEAD MIDDLE WIDTH");
- m_ToolTip.Show(point);
- }
- else if(MoveHeadLowerWidth(point) && !nFlags){
- ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEWE));
- tmp = 4;
- /*vt2->oglIface->setOpenGLContext();
- vt2->display_func();
- vt2->oglIface->swapOpenGLBuffers();*/
- m_ToolTip.SetText("HEAD LOWER WIDTH");
- m_ToolTip.Show(point);
- }
- else if(MoveChinWidth(point) && !nFlags){
- ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEWE));
- tmp = 5;
- /*vt2->oglIface->setOpenGLContext();
- vt2->display_func();
- vt2->oglIface->swapOpenGLBuffers();*/
- m_ToolTip.SetText("CHIN WIDTH");
- m_ToolTip.Show(point);
- }
- else if(MoveNoseUpperVerticalPosition(point) && !nFlags){
- ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZENS));
- tmp = 6;
- /*vt2->oglIface->setOpenGLContext();
- vt2->display_func();
- vt2->oglIface->swapOpenGLBuffers();*/
- m_ToolTip.SetText("NOSE UPPER POSITION");
- m_ToolTip.Show(point);
- }
- else if(MoveNoseMiddleVerticalPosition(point) && !nFlags){
- ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEALL));
- tmp = 7;
- /*vt2->oglIface->setOpenGLContext();
- vt2->display_func();
- vt2->oglIface->swapOpenGLBuffers();*/
- m_ToolTip.SetText("NOSE MIDDLE POSITION and WIDTH");
- m_ToolTip.Show(point);
- }
- else if(MoveNoseLowerVerticalPosition(point) && !nFlags){
- ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZENS));
- tmp = 8;
- /*vt2->oglIface->setOpenGLContext();
- vt2->display_func();
- vt2->oglIface->swapOpenGLBuffers();*/
- m_ToolTip.SetText("NOSE LOWER POSITION");
- m_ToolTip.Show(point);
- }
- else if(MoveNoseUpperWidth(point) && !nFlags){
- ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEWE));
- tmp = 9;
- /*vt2->oglIface->setOpenGLContext();
- vt2->display_func();
- vt2->oglIface->swapOpenGLBuffers();*/
- m_ToolTip.SetText("NOSE UPPER WIDTH");
- m_ToolTip.Show(point);
- }
- else if(MoveNoseLowerWidth(point) && !nFlags){
- ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEWE));
- tmp = 10;
- /*vt2->oglIface->setOpenGLContext();
- vt2->display_func();
- vt2->oglIface->swapOpenGLBuffers();*/
- m_ToolTip.SetText("NOSE LOWER WIDTH");
- m_ToolTip.Show(point);
- }
- else if(MoveNoseThickness(point) && !nFlags){
- ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEWE));
- tmp = 11;
- /*vt2->oglIface->setOpenGLContext();
- vt2->display_func();
- vt2->oglIface->swapOpenGLBuffers();*/
- m_ToolTip.SetText("NOSE THICKNESS");
- m_ToolTip.Show(point);
- }
- else if(MoveEyebrowsBetweenVP(point) && !nFlags){
- ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZENS));
- tmp = 12;
- /*vt2->oglIface->setOpenGLContext();
- vt2->display_func();
- vt2->oglIface->swapOpenGLBuffers();*/
- m_ToolTip.SetText("EYEBROWS BETWEEN POSITION");
- m_ToolTip.Show(point);
- }
- else if(MoveEyebrowsInnerVP_SD(point) && !nFlags){
- ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEALL));
- tmp = 13;
- /*vt2->oglIface->setOpenGLContext();
- vt2->display_func();
- vt2->oglIface->swapOpenGLBuffers();*/
- m_ToolTip.SetText("EYEBROWS INNER POSITION and DISTANCE");
- m_ToolTip.Show(point);
- }
- else if(MoveEyebrowsOuterVP_SD(point) && !nFlags){
- ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEALL));
- tmp = 14;
- /*vt2->oglIface->setOpenGLContext();
- vt2->display_func();
- vt2->oglIface->swapOpenGLBuffers();*/
- m_ToolTip.SetText("EYEBROWS OUTER POSITION and DISTANCE");
- m_ToolTip.Show(point);
- }
- else if(MoveEyebrowsMiddleVP_SD(point) && !nFlags){
- ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEALL));
- tmp = 16;
- /*vt2->oglIface->setOpenGLContext();
- vt2->display_func();
- vt2->oglIface->swapOpenGLBuffers();*/
- m_ToolTip.SetText("EYEBROWS MIDDLE POSITION and DISTANCE");
- m_ToolTip.Show(point);
- }
- else if(MoveEyebrowsThickness(point) && !nFlags){
- ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZENS));
- tmp = 15;
- /*vt2->oglIface->setOpenGLContext();
- vt2->display_func();
- vt2->oglIface->swapOpenGLBuffers();*/
- m_ToolTip.SetText("EYEBROWS THICKNESS");
- m_ToolTip.Show(point);
- }
- else if(MoveEyesVP_SD(point) && !nFlags){
- ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEALL));
- tmp = 17;
- /*vt2->oglIface->setOpenGLContext();
- vt2->display_func();
- vt2->oglIface->swapOpenGLBuffers();*/
- m_ToolTip.SetText("EYES POSITION and DISTANCE");
- m_ToolTip.Show(point);
- }
- else if(MoveEyesVD_Width(point) && !nFlags){
- ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEALL));
- tmp = 18;
- /*vt2->oglIface->setOpenGLContext();
- vt2->display_func();
- vt2->oglIface->swapOpenGLBuffers();*/
- m_ToolTip.SetText("EYES DIFFERENCE and WIDTH");
- m_ToolTip.Show(point);
- }
- else if(MoveEyesHeight(point) && !nFlags){
- ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZENS));
- tmp = 19;
- /*vt2->oglIface->setOpenGLContext();
- vt2->display_func();
- vt2->oglIface->swapOpenGLBuffers();*/
- m_ToolTip.SetText("EYES HEIGHT");
- m_ToolTip.Show(point);
- }
- else if(MoveMouthVP(point) && !nFlags){
- ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZENS));
- tmp = 20;
- /*vt2->oglIface->setOpenGLContext();
- vt2->display_func();
- vt2->oglIface->swapOpenGLBuffers();*/
- m_ToolTip.SetText("MOUTH POSITION");
- m_ToolTip.Show(point);
- }
- else if(MoveMouthWidth_Bending(point) && !nFlags){
- ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEALL));
- tmp = 21;
- /*vt2->oglIface->setOpenGLContext();
- vt2->display_func();
- vt2->oglIface->swapOpenGLBuffers();*/
- m_ToolTip.SetText("MOUTH WIDTH and BENDING");
- m_ToolTip.Show(point);
- }
- else if(MoveMouthLipThickness(point) && !nFlags)
- {
- ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZENS));
- tmp = 22;
- /*vt2->oglIface->setOpenGLContext();
- vt2->display_func();
- vt2->oglIface->swapOpenGLBuffers();*/
- m_ToolTip.SetText("MOUTH LIP THICKNESS");
- m_ToolTip.Show(point);
- }
- /*else if(MoveJaw(point) && !nFlags)
- {
- ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZENS));
- tmp = 23;
- vt2->oglIface->setOpenGLContext();
- vt2->display_func();
- vt2->oglIface->swapOpenGLBuffers();
- m_ToolTip.SetText("JAW z-extension");
- m_ToolTip.Show(point);
- }*/
- 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)))
- {
- vt2->oglIface->setOpenGLContext();
- vt2->display_func();
- vt2->oglIface->swapOpenGLBuffers();
- m_ToolTip.Close();
- }
- 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)))
- {
- vt2->oglIface->setOpenGLContext();
- vt2->display_func();
- vt2->oglIface->swapOpenGLBuffers();
- m_ToolTip.Close();
- }
- else if ((tmp==12 && !MoveEyebrowsBetweenVP(point)) || (tmp==13 && !MoveEyebrowsInnerVP_SD(point)) || (tmp==14 && !MoveEyebrowsOuterVP_SD
- (point)) || (tmp==16 && !MoveEyebrowsMiddleVP_SD(point)) || (tmp==15 && !MoveEyebrowsThickness(point)))
- {
- vt2->oglIface->setOpenGLContext();
- vt2->display_func();
- vt2->oglIface->swapOpenGLBuffers();
- m_ToolTip.Close();
- }
- else if((tmp==17 && !MoveEyesVP_SD(point)) || (tmp==18 && !MoveEyesVD_Width(point)) || (tmp==19 && !MoveEyesHeight(point)))
- {
- vt2->oglIface->setOpenGLContext();
- vt2->display_func();
- vt2->oglIface->swapOpenGLBuffers();
- m_ToolTip.Close();
- }
- else if ((tmp==20 && !MoveMouthVP(point)) || (tmp==21 && !MoveMouthWidth_Bending(point)) || (tmp==22 && !MoveMouthLipThickness(point)))
- {
- vt2->oglIface->setOpenGLContext();
- vt2->display_func();
- vt2->oglIface->swapOpenGLBuffers();
- m_ToolTip.Close();
- }
- }
- void COpenGLWnd::OnRButtonUp(UINT nFlags, CPoint point)
- {
- KillTimer(ID_ROTATE);
- m_bTimerSet = false;
- mRightButtonDown = false;
- }
- /**
- * Start the rendering timer.
- * Start the timer for the rendering. After this, the OnTimer() function
- * is automatically called every mTIMER_RENDERING_INTERVAL milliseconds, and in turn it calls the render function. Thus we have
- * a rendering function call every mTIMER_RENDERING_INTERVAL milliseconds.
- */
- void COpenGLWnd::StartRenderingTimer()
- {
- SetTimer(ID_RENDERING, mTIMER_RENDERING_INTERVAL, NULL);
- }
- /**
- * Timer callback.
- * This function is called by the timer. This is used to implement the rendering cycle.
- */
- void COpenGLWnd::OnTimer(UINT nIDEvent)
- {
- switch(nIDEvent)
- {
- case ID_RENDERING:
- RenderToScreen();
- break;
- case ID_ROTATE:
- RightButtonDownTimerFunc();
- break;
- }
- }
- void COpenGLWnd::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
- {
- SetContext();
- if(nChar == VK_F1)
- SetRenderingMode(VGLR_RENDERING_WIREFRAME);
- else if(nChar == VK_F2)
- SetRenderingMode(VGLR_RENDERING_AS_IS);
- else if(nChar == VK_F11)
- FitToScreen();
- else
- RenderToScreen();
- SwapGLBuffers();
- }
- void COpenGLWnd::OnLButtonUp(UINT nFlags, CPoint point)
- {
- mLeftButtonDown = false;
- }
- /**
- * Pre-render setup function.
- * This function is called before the rendering in each rendering cycle. It sets up the GL context and clears the screen
- * to prepare for the next frame to be rendered.
- *
- * This is a good place to insert the rendering of other objects in the scene,
- * background image or similar.
- */
- void COpenGLWnd::SetContext()
- {
- // set the context
- wglMakeCurrent(m_pDC->GetSafeHdc(), m_hRC);
- // clear the frame buffer before next drawing
- if(!trackerActive) // if tracker is active, do not clear screen
- glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
- // INSERT CODE HERE TO RENDER ANY ADDITIONAL OBJECTS, BACKGROUND IMAGE OR SIMILAR
- DrawBackgroundImage();
- }
- void COpenGLWnd::SwapGLBuffers()
- {
- if(trackerActive) // if tracker is active, do not swap buffers
- return;
- SwapBuffers(m_pDC->GetSafeHdc());
- wglMakeCurrent(NULL, NULL);
- }
- int COpenGLWnd::LoadTexture(char *fullPath)
- {
- FILE *File=NULL;
- File=fopen(fullPath,"r");
- if(!File)
- {
- return -1;
- }
- fclose(File);
- // Texture varible, return
- GLuint texture[1];
- // Check file-extension
- // if(fullPath.substr(fullPath.size() - 4, fullPath.size()) == temp)
- if(!strcmp(fullPath+(strlen(fullPath) - 4),".jpg"))
- {
- glGenTextures(1, &texture[0]); // Create The Texture
- // Typical Texture Generation Using Data From The Bitmap
- glBindTexture(GL_TEXTURE_2D, texture[0]);
- JPEG_CORE_PROPERTIES *p = new JPEG_CORE_PROPERTIES;
- if( ijlInit( p ) != IJL_OK ) return -1;
- p->JPGFile = fullPath;
- // Read in params first so we get the right DIB.
- if( ijlRead( p, IJL_JFILE_READPARAMS ) != IJL_OK )
- {
- delete p;
- return -1;
- }
- switch( p->JPGChannels )
- {
- case 1: p->JPGColor = IJL_G;
- p->DIBChannels = 3;
- p->DIBColor = IJL_BGR;
- break;
- case 3: p->JPGColor = IJL_YCBCR;
- p->DIBChannels = 3;
- p->DIBColor = IJL_BGR;
- break;
- case 4: p->JPGColor = IJL_YCBCRA_FPX;
- p->DIBChannels = 4;
- p->DIBColor = IJL_RGBA_FPX;
- break;
- default: p->DIBColor = (IJL_COLOR)IJL_OTHER;
- p->JPGColor = (IJL_COLOR) IJL_OTHER;
- p->DIBChannels = p->JPGChannels;
- break;
- }
- p->DIBWidth = p->JPGWidth;
- p->DIBHeight = p->JPGHeight;
- p->DIBPadBytes = IJL_DIB_PAD_BYTES( p->DIBWidth, p->DIBChannels );
- int imageSize = p->DIBWidth * p->DIBChannels + p->DIBPadBytes;
- imageSize *= p->DIBHeight;
- p->DIBBytes = new BYTE[ imageSize ];
- if ( ijlRead( p, IJL_JFILE_READWHOLEIMAGE ) != IJL_OK ) return -1;
- if ( p->DIBColor == IJL_RGBA_FPX )
- {
- if ( p->DIBBytes )
- delete[] p->DIBBytes;
- delete p;
- return -1;
- }
- BYTE *flipImage = new BYTE[ imageSize ];
- // Flip the image - since library gives us upside down images.
- int jMax = p->DIBWidth * p->DIBChannels + p->DIBPadBytes;
- int iMax = p->DIBHeight;
- for(int i=0; i < iMax; i++)
- for(int j=0; j < jMax; j++)
- flipImage[i * jMax + j] = p->DIBBytes[((iMax - 1) - i) * jMax + j];
- // Load texture into GL.
- int maxSize = 0;
- glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxSize);
- // Create a texture of nearest power 2
- int xPowSize = 1;
- int yPowSize = 1;
- while((p->DIBWidth / xPowSize) > 0) xPowSize <<= 1;
- while((p->DIBHeight / yPowSize) > 0) yPowSize <<= 1;
- // Size to nearest lower power of 2 for speed
- xPowSize >>= 1;
- yPowSize >>= 1;
- // So we're not overriding gfx-cards capabilitys
- if(xPowSize > maxSize) xPowSize = maxSize;
- if(yPowSize > maxSize) yPowSize = maxSize;
- // Allocate memory to the scaled image.
- GLubyte* tempScaleImage = new GLubyte[yPowSize * (xPowSize * p->DIBChannels + p->DIBPadBytes)];
- // Scale original image to nearest lower power of 2.
- switch(p->DIBColor)
- {
- // Only three cases since last IJL_RGBA_FPX will never happen.
- case IJL_RGB:
- {
- // gluScaleImage(GL_RGB, p->DIBWidth, p->DIBHeight, GL_UNSIGNED_BYTE, p->DIBBytes, xPowSize, yPowSize, GL_UNSIGNED_BYTE, tempScaleImage);
- gluScaleImage(GL_RGB, p->DIBWidth, p->DIBHeight, GL_UNSIGNED_BYTE, flipImage, xPowSize, yPowSize, GL_UNSIGNED_BYTE, tempScaleImage);
- // const GLubyte *ragga2 = gluErrorString(glGetError());
- glTexImage2D(GL_TEXTURE_2D, 0, 3, xPowSize, yPowSize, 0, GL_RGB, GL_UNSIGNED_BYTE, tempScaleImage);
- // const GLubyte *ragga = gluErrorString(glGetError());
- }
- break;
- case IJL_BGR:
- {
- gluScaleImage(GL_RGB, p->DIBWidth, p->DIBHeight, GL_UNSIGNED_BYTE, flipImage, xPowSize, yPowSize, GL_UNSIGNED_BYTE, tempScaleImage);
- // gluScaleImage(GL_BGR_EXT, p->DIBWidth, p->DIBHeight, GL_UNSIGNED_BYTE, p->DIBBytes, xPowSize, yPowSize, GL_UNSIGNED_BYTE, tempScaleImage);
- // const GLubyte *ragga2 = gluErrorString(glGetError());
- glTexImage2D(GL_TEXTURE_2D, 0, 3, xPowSize, yPowSize, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, tempScaleImage);
- // const GLubyte *ragga = gluErrorString(glGetError());
- }
- break;
- // Safety stuff.
- default:
- return -1;
- break;
- }
- // Clean up
- delete [] flipImage;
- delete [] tempScaleImage;
- delete [] p->DIBBytes;
- delete p;
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); // Linear Filtering
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); // Linear Filtering
- }
- // Check file extension.
- // else if(fullPath.substr(fullPath.size() - 4, fullPath.size()) == temp2)
- else if(!strcmp(fullPath+(strlen(fullPath) - 4),".bmp"))
- {
- glGenTextures(1, &texture[0]); // Create The Texture
- // Typical Texture Generation Using Data From The Bitmap
- glBindTexture(GL_TEXTURE_2D, texture[0]);
- AUX_RGBImageRec *texPointer[1];
- memset(texPointer,0,sizeof(void *)*1);
- texPointer[0] = auxDIBImageLoad(fullPath);
- glGenTextures(1, &texture[0]); // Create The Texture
- // Typical Texture Generation Using Data From The Bitmap
- glBindTexture(GL_TEXTURE_2D, texture[0]);
- int maxSize;
- glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxSize);
- // Create a texture of nearest power 2
- int xPowSize = 1;
- int yPowSize = 1;
- while((texPointer[0]->sizeX / xPowSize) > 0) xPowSize <<= 1;
- while((texPointer[0]->sizeY / yPowSize) > 0) yPowSize <<= 1;
- // Size to nearest lower power of 2 for speed
- xPowSize >>= 1;
- yPowSize >>= 1;
- // So we're not overriding gfx-cards capabilitys
- if(xPowSize > maxSize) xPowSize = maxSize;
- if(yPowSize > maxSize) yPowSize = maxSize;
- GLubyte* tempScaleImage = new GLubyte[yPowSize * xPowSize * 3];
- // Scale original image to nearest lower power of 2.
- gluScaleImage(GL_RGB, texPointer[0]->sizeX, texPointer[0]->sizeY, GL_UNSIGNED_BYTE, texPointer[0]->data, xPowSize, yPowSize, GL_UNSIGNED_BYTE, tempScaleImage);
- const GLubyte *ragga2 = gluErrorString(glGetError());
- glTexImage2D(GL_TEXTURE_2D, 0, 3, xPowSize, yPowSize, 0, GL_RGB, GL_UNSIGNED_BYTE, tempScaleImage);
- const GLubyte *ragga = gluErrorString(glGetError());
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); // Linear Filtering
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); // Linear Filtering
- if (texPointer[0]) // If Texture Exists
- {
- if (texPointer[0]->data) // If Texture Image Exists
- {
- free(texPointer[0]->data); // Free The Texture Image Memory
- delete [] tempScaleImage;
- }
- free(texPointer[0]); // Free The Image Structure
- }
- }
- // Successfully return the loaded image.
- return texture[0];
- }
- /**
- * Draw the background image on the screen.
- * Load the background image from the file background.jpg the first time this function is called.
- * If loading is succesful, the image is drawn on the screen every time the function is called.
- * This function is called by SetContext(), so it is executed at the beginning of every frame.
- *
- * @return true if image is succesfully drawn, 0 otherwise
- * @see SetContext()
- */
- bool COpenGLWnd::DrawBackgroundImage()
- {
- // draw the background image, if any
- static int noImage = 0;
- if(noImage)
- return false;
- if(!bgtexture[0])
- {
- bgtexture[0] = LoadTexture("background.jpg");
- if(bgtexture[0] == -1)
- {
- bgtexture[0] = LoadTexture("../background.jpg");
- }
- if(bgtexture[0] == -1)
- {
- noImage=1;
- return false;
- }
- }
- glPushAttrib(GL_DEPTH_BUFFER_BIT | GL_VIEWPORT_BIT | GL_ENABLE_BIT | GL_FOG_BIT | GL_STENCIL_BUFFER_BIT | GL_TRANSFORM_BIT | GL_TEXTURE_BIT );
- glDisable(GL_ALPHA_TEST);
- glDisable(GL_DEPTH_TEST);
- glDisable(GL_BLEND );
- glDisable(GL_DITHER);
- glDisable(GL_FOG);
- glDisable(GL_SCISSOR_TEST);
- glDisable(GL_STENCIL_TEST);
- glDisable(GL_LIGHTING);
- glDisable(GL_LIGHT0);
- glEnable(GL_TEXTURE_2D);
- glBindTexture(GL_TEXTURE_2D, bgtexture[0]); // Select Our Texture
- glMatrixMode(GL_MODELVIEW);
- glPushMatrix();
- glLoadIdentity(); // Reset The Projection Matrix
- glMatrixMode(GL_PROJECTION);
- glPushMatrix();
- glLoadIdentity(); // Reset The Projection Matrix
- glOrtho(0.0f,1.0f,0.0f,1.0f,-10.0f,10.0f);
- glBegin(GL_QUADS);
- glTexCoord2f(0.0f,0.0f);
- glVertex3f(0.0f,0.0f,-5.0f);
- glTexCoord2f(1.0f,0.0f);
- glVertex3f(1.0f,0.0f,-5.0f);
- glTexCoord2f(1.0f,1.0f);
- glVertex3f(1.0f,1.0f,-5.0f);
- glTexCoord2f(0.0f,1.0f);
- glVertex3f(0.0f,1.0f,-5.0f);
- glEnd();
- glPopMatrix();
- glMatrixMode(GL_MODELVIEW);
- glPopMatrix();
- glBindTexture(GL_TEXTURE_2D, 0);
- glPopAttrib();
- glClear(GL_DEPTH_BUFFER_BIT);
- return TRUE;
- }
- void COpenGLWnd::ReSizeGLScene(GLsizei width, GLsizei height) // Resize And Initialize The GL Window
- {
- if (height==0) // Prevent A Divide By Zero By
- {
- height=1; // Making Height Equal One
- }
- mWindowWidth = width;
- mWindowHeight = height;
- int animViewPos,animViewWidth,animViewHeight;
- animViewPos = (int)((1-ANIM_VIEW_SIZE)*width);
- animViewWidth = (int)(ANIM_VIEW_SIZE*width);
- animViewHeight = (animViewWidth * 3) / 4; // 3/4 aspect ratio
- if(animViewHeight > height)
- animViewHeight = height;
- glViewport(animViewPos,0,animViewWidth,animViewHeight); // Reset The Current Viewport
- glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
- glLoadIdentity(); // Reset The Projection Matrix
- gluPerspective(mVGLR_PERSPECT_FOVY, (GLfloat)animViewWidth/(GLfloat)animViewHeight, mVGLR_PERSPECT_NEAR_PLANE, mFarPlane);
- glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
- }
- void COpenGLWnd::SetModelViewMatrix(GLfloat *m)
- {
- modelViewMatrix = m;
- }
- void COpenGLWnd::ToggleBackfaceCull()
- {
- mBackfaceCull = !mBackfaceCull;
- SetRenderingMode(mRenderingMode);
- }
- void COpenGLWnd::SetRenderingMode(VGLR_RENDERING_MODE newMode)
- {
- switch(newMode)
- {
- case VGLR_RENDERING_WIREFRAME:
- {
- // Set wireframe mode.
- if(mBackfaceCull)
- glPolygonMode(GL_FRONT, GL_LINE);
- else
- glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
- // Still want lighting tho..
- glEnable(GL_LIGHTING);
- glEnable(GL_LIGHT0);
- // Material
- glDisable(GL_COLOR_MATERIAL);
- // Textures
- glDisable(GL_TEXTURE_2D);
- if(mBackfaceCull)
- {
- glEnable(GL_CULL_FACE);
- glCullFace(GL_BACK);
- }
- else
- glDisable(GL_CULL_FACE);
- }
- break;
- case VGLR_RENDERING_SOLID_NO_MATERIAL:
- {
- }
- break;
- case VGLR_RENDERING_MATERIAL:
- {
- }
- break;
- case VGLR_RENDERING_AS_IS:
- {
- if(mBackfaceCull)
- glPolygonMode(GL_FRONT, GL_FILL);
- else
- glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
- // Lightning.
- glEnable(GL_LIGHTING);
- glEnable(GL_LIGHT0);
- // Textures
- glEnable(GL_TEXTURE_2D);
- if(mBackfaceCull)
- {
- glEnable(GL_CULL_FACE);
- glCullFace(GL_BACK);
- }
- else
- glDisable(GL_CULL_FACE);
- }
- break;
- }
- mRenderingMode = newMode;
- }
- void COpenGLWnd::LeftButtonDown(float x, float y)
- {
- mLeftButtonX = (GLfloat)x;
- mLeftButtonY = (GLfloat)y;
- }
- void COpenGLWnd::SetRange(CPoint& point){
- CRect rc; // objekt koji predstavlja pravokutnik
- GetClientRect(rc); //u taj objekt snimamo trenutnu velicinu prozora
- width = (float)vt2->frame->width; //sirina okvira, npr. 640
- height = (float)vt2->frame->height; //visina okvira, npr.480
- image_width = (float)vt2->gl_image->width; //sirina slike, stalna - 800
- image_height = (float)vt2->gl_image->height; //visina slike, stalna - 600
- widthRight = - (float)(image_width-(float)image_width/2)/((float)image_height/2);
- widthLeft = - (float)(0-(float)image_width/2)/((float)image_height/2);
- point_x = - (float)(point.x-(float)image_width/2)/((float)image_height/2);
- imageTop = (float)(image_height-(float)image_height/2)/((float)image_height/2);
- imageBottom = (float)(0-(float)image_height/2)/((float)image_height/2);
- point_y = - (float)(point.y-((rc.top + rc.bottom) - image_height)-(float)image_height/2)/((float)image_height/2);
- centarX = (float)(widthRight + widthLeft)/2;
- centarY = (float)(imageTop + imageBottom)/2;
- }
- bool COpenGLWnd::MoveJawHeight(CPoint &point){
- // faceShape[0]
- var = 40;
- // y koordinate verteksa
- float y10 = vt2->fbft->projection->data.fl[2*10+1];
- float y65 = vt2->fbft->projection->data.fl[2*65+1];
- // x koordinate verteksa
- float x32 = vt2->fbft->projection->data.fl[2*32];
- float x65 = vt2->fbft->projection->data.fl[2*65];
- // podesavanje granica na [-1,1] i [-1.3333, 1.3333]
- SetRange(point);
- // x i y kordinate verteksa u odnosu na centar slike
- float x_32 = centarX + x32 ;
- float x_65 = centarX + x65 ;
- float y_10 = centarY + y10 ;
- float y_65 = centarY + y65 ;
- // pozicija misa je istinita (true) u danom podrucju
- return(point_x <= x_65 && point_x >= x_32 && point_y >= y_10 && point_y <= y_65);
- }
- bool COpenGLWnd::MoveIrisHeightWidth(CPoint& point){
- // faceShape[1]
- var = 38;
- // y koordinate verteksa
- float y68 = vt2->fbft->projection->data.fl[2*68+1];
- float y67 = vt2->fbft->projection->data.fl[2*67+1];
- float y74 = vt2->fbft->projection->data.fl[2*74+1];
- float y73 = vt2->fbft->projection->data.fl[2*73+1];
- // x koordinate verteksa
- float x20 = vt2->fbft->projection->data.fl[2*20];
- float x67 = vt2->fbft->projection->data.fl[2*67];
- float x71 = vt2->fbft->projection->data.fl[2*71];
- float x23 = vt2->fbft->projection->data.fl[2*23];
- float x56 = vt2->fbft->projection->data.fl[2*56];
- float x73 = vt2->fbft->projection->data.fl[2*73];
- float x69 = vt2->fbft->projection->data.fl[2*69];
- float x53 = vt2->fbft->projection->data.fl[2*53];
- // x koordinata verteksa 0 (otprilike centar maske po x)
- float x0 = vt2->fbft->projection->data.fl[2*0];
- // podesavanje granica na [-1,1] i [-1.3333, 1.3333]
- SetRange(point);
- // x i y kordinate verteksa u odnosu na centar slike
- float y_68 = centarY + y68 ;
- float y_67 = centarY + y67 ;
- float y_74 = centarY + y74 ;
- float y_73 = centarY + y73 ;
- float x_0 = centarX + x0 ;
- float x_20 = centarX + x20 ;
- float x_67 = centarX + x67 ;
- float x_71 = centarX + x71 ;
- float x_23 = centarX + x23 ;
- float x_56 = centarX + x56 ;
- float x_73 = centarX + x73 ;
- float x_69 = centarX + x69 ;
- float x_53 = centarX + x53 ;
- if(point_x >= x_20 && point_x <= x_67)
- {
- if(point_y >= y_68 && point_y <= y_67)
- {
- side = 1; // lijeva strana irisa
- return(true);
- }
- }
- if(point_x >= x_71 && point_x <= x_23)
- {
- if(point_y >= y_68 && point_y <= y_67)
- {
- side = 0; // desna strana irisa
- return(true);
- }
- }
- if(point_x >= x_56 && point_x <= x_73)
- {
- if(point_y >= y_74 && point_y <= y_73)
- {
- side = 1; // lijeva strana irisa
- return(true);
- }
- }
- if(point_x >= x_69 && point_x <= x_53)
- {
- if(point_y >= y_74 && point_y <= y_73)
- {
- side = 0; // desna strana irisa
- return(true);
- }
- }
- return(false);
- }
- bool COpenGLWnd::MoveHeadHeight(CPoint &point){
- // faceShape[0]
- var = 0;
- // y koordinate verteksa
- float y0 = vt2->fbft->projection->data.fl[2*0+1];
- float y34 = vt2->fbft->projection->data.fl[2*34+1];
- // x koordinate verteksa
- float x45 = vt2->fbft->projection->data.fl[2*45];
- float x12 = vt2->fbft->projection->data.fl[2*12];
- // podesavanje granica na [-1,1] i [-1.3333, 1.3333]
- SetRange(point);
- // x i y kordinate verteksa u odnosu na centar slike
- float x_45 = centarX + x45 ;
- float x_12 = centarX + x12 ;
- float y_0 = centarY + y0 ;
- float y_34 = centarY + y34 ;
- // pozicija misa je istinita (true) u danom podrucju
- return(point_x <= x_45 && point_x >= x_12 && point_y >= y_34 && point_y <= y_0);
- }
- bool COpenGLWnd::MoveHeadUpperWidth(CPoint& point){
- // faceShape[1]
- var = 1;
- // y koordinate verteksa
- float y48 = vt2->fbft->projection->data.fl[2*48+1];
- float y45 = vt2->fbft->projection->data.fl[2*45+1];
- float y15 = vt2->fbft->projection->data.fl[2*15+1];
- float y12 = vt2->fbft->projection->data.fl[2*12+1];
- // x koordinate verteksa
- float x48 = vt2->fbft->projection->data.fl[2*45];
- float x47 = vt2->fbft->projection->data.fl[2*47];
- float x15 = vt2->fbft->projection->data.fl[2*15];
- float x14 = vt2->fbft->projection->data.fl[2*14];
- // x koordinata verteksa 0 (otprilike centar maske po x)
- float x0 = vt2->fbft->projection->data.fl[2*0];
- // podesavanje granica na [-1,1] i [-1.3333, 1.3333]
- SetRange(point);
- // x i y kordinate verteksa u odnosu na centar slike
- float x_48 = centarX + x48 ;
- float x_47 = centarX + x47 ;
- float x_15 = centarX + x15 ;
- float x_14 = centarX + x14 ;
- float x_0 = centarX + x0 ;
- float y_48 = centarY + y48 ;
- float y_45 = centarY + y45 ;
- float y_15 = centarY + y15 ;
- float y_12 = centarY + y12 ;
- if(point_x > x_0) side = 0; // lijeva strana maske
- else if(point_x < x_0) side =1; // desna strana maske
- // pozicija misa je istinita (true) u danom podrucju
- 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));
- }
- bool COpenGLWnd::MoveHeadMiddleWidth(CPoint& point){
- // faceShape[2]
- var = 2;
- // y koordinate verteksa
- float y48 = vt2->fbft->projection->data.fl[2*48+1];
- float y61 = vt2->fbft->projection->data.fl[2*61+1];
- float y15 = vt2->fbft->projection->data.fl[2*15+1];
- float y28 = vt2->fbft->projection->data.fl[2*28+1];
- // x koordinate verteksa
- float x48 = vt2->fbft->projection->data.fl[2*48];
- float x62 = vt2->fbft->projection->data.fl[2*62];
- float x15 = vt2->fbft->projection->data.fl[2*15];
- float x29 = vt2->fbft->projection->data.fl[2*29];
- // x koordinata verteksa 0 (otprilike centar maske po x)
- float x0 = vt2->fbft->projection->data.fl[2*0];
- // podesavanje granica na [-1,1] i [-1.3333, 1.3333]
- SetRange(point);
- // x i y kordinate verteksa u odnosu na centar slike
- float x_48 = centarX + x48 ;
- float x_62 = centarX + x62 ;
- float x_15 = centarX + x15 ;
- float x_29 = centarX + x29 ;
- float x_0 = centarX + x0 ;
- float y_48 = centarY + y48 ;
- float y_61 = centarY + y61 ;
- float y_15 = centarY + y15 ;
- float y_28 = centarY + y28 ;
- if(point_x > x_0) side = 0; // lijeva strana maske
- else if(point_x < x_0) side =1; //desna strana maske
- // pozicija misa je istinita (true) u danom podrucju
- 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)));
- }
- bool COpenGLWnd::MoveHeadLowerWidth(CPoint& point){
- // faceShape[3]
- var = 3;
- // y koordinate verteksa
- float y63 = vt2->fbft->projection->data.fl[2*63+1];
- float y61 = vt2->fbft->projection->data.fl[2*61+1];
- float y30 = vt2->fbft->projection->data.fl[2*30+1];
- float y28 = vt2->fbft->projection->data.fl[2*28+1];
- // x koordinate verteksa
- float x63 = vt2->fbft->projection->data.fl[2*63];
- float x61 = vt2->fbft->projection->data.fl[2*61];
- float x28 = vt2->fbft->projection->data.fl[2*28];
- float x30 = vt2->fbft->projection->data.fl[2*30];
- // x koordinata verteksa 0 (otprilike centar maske po x)
- float x0 = vt2->fbft->projection->data.fl[2*0];
- // podesavanje granica na [-1,1] i [-1.3333, 1.3333]
- SetRange(point);
- // x i y kordinate verteksa u odnosu na centar slike
- float x_61 = centarX + x61 ;
- float x_63 = centarX + x63 ;
- float x_28 = centarX + x28 ;
- float x_30 = centarX + x30 ;
- float x_0 = centarX + x0 ;
- float y_61 = centarY + y61 ;
- float y_63 = centarY + y63 ;
- float y_30 = centarY + y30 ;
- float y_28 = centarY + y28 ;
- if(point_x > x_0) side = 0; // lijeva strana maske
- else if(point_x < x_0) side =1; // desna strana maske
- // pozicija misa je istinita (true) u danom podrucju
- 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)));
- }
- bool COpenGLWnd::MoveChinWidth(CPoint& point){
- // faceShape[4]
- var = 4;
- // y koordinate verteksa
- float y63 = vt2->fbft->projection->data.fl[2*63+1];
- float y65 = vt2->fbft->projection->data.fl[2*65+1];
- float y30 = vt2->fbft->projection->data.fl[2*30+1];
- float y32 = vt2->fbft->projection->data.fl[2*32+1];
- // x koordinate verteksa
- float x63 = vt2->fbft->projection->data.fl[2*63];
- float x65 = vt2->fbft->projection->data.fl[2*65];
- float x32 = vt2->fbft->projection->data.fl[2*32];
- float x30 = vt2->fbft->projection->data.fl[2*30];
- // x koordinata verteksa 0 (otprilike centar maske po x)
- float x0 = vt2->fbft->projection->data.fl[2*0];
- // podesavanje granica na [-1,1] i [-1.3333, 1.3333]
- SetRange(point);
- // x i y kordinate verteksa u odnosu na centar slike
- float x_65 = centarX + x65 ;
- float x_63 = centarX + x63 ;
- float x_32 = centarX + x32 ;
- float x_30 = centarX + x30 ;
- float x_0 = centarX + x0 ;
- float y_65 = centarY + y65 ;
- float y_63 = centarY + y63 ;
- float y_30 = centarY + y30 ;
- float y_32 = centarY + y32 ;
- if(point_x > x_0) side = 0; // lijeva strana maske
- else if(point_x < x_0) side =1; // desna strana maske
- // pozicija misa je istinita (true) u danom podrucju
- 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)));
- }
- bool COpenGLWnd::MoveJaw(CPoint& point){
- // faceShape[36]
- var = 36;
- // y koordinate verteksa
- float y10 = vt2->fbft->projection->data.fl[2*10+1];
- float y65 = vt2->fbft->projection->data.fl[2*65+1];
- // x koordinate verteksa
- float x65 = vt2->fbft->projection->data.fl[2*65];
- float x32 = vt2->fbft->projection->data.fl[2*32];
- // podesavanje granica na [-1,1] i [-1.3333, 1.3333]
- SetRange(point);
- // x i y kordinate verteksa u odnosu na centar slike
- float x_65 = centarX + x65 ;
- float x_32 = centarX + x32 ;
- float y_10 = centarY + y10 ;
- float y_65 = centarY + y65 ;
- // pozicija misa je istinita (true) u danom podrucju
- return(point_x <= x_65 && point_x >= x_32 && point_y >= y_10 && point_y <= y_65);
- }
- bool COpenGLWnd::MoveNoseUpperVerticalPosition(CPoint& point){
- // faceShape[5]
- var = 5;
- // y koordinate verteksa
- float y3 = vt2->fbft->projection->data.fl[2*3+1];
- float y78 = vt2->fbft->projection->data.fl[2*78+1];
- // x koordinate verteksa
- float x78 = vt2->fbft->projection->data.fl[2*78];
- float x77 = vt2->fbft->projection->data.fl[2*77];
- // podesavanje granica na [-1,1] i [-1.3333, 1.3333]
- SetRange(point);
- // x i y kordinate verteksa u odnosu na centar slike
- float x_78 = centarX + x78 ;
- float x_77 = centarX + x77 ;
- float y_78 = centarY + y78 ;
- float y_3 = centarY + y3 ;
- // pozicija misa je istinita (true) u danom podrucju
- return(point_x <= x_78 && point_x >= x_77 && point_y >= y_78 && point_y <= y_3);
- }
- bool COpenGLWnd::MoveNoseUpperWidth(CPoint& point){
- // faceShape[8]
- var = 8;
- // y koordinate verteksa
- float y78 = vt2->fbft->projection->data.fl[2*78+1];
- float y3 = vt2->fbft->projection->data.fl[2*3+1];
- float y77 = vt2->fbft->projection->data.fl[2*77+1];
- // x koordinate verteksa
- float x93 = vt2->fbft->projection->data.fl[2*93];
- float x78 = vt2->fbft->projection->data.fl[2*78];
- float x77 = vt2->fbft->projection->data.fl[2*77];
- float x92 = vt2->fbft->projection->data.fl[2*92];
- // x koordinata verteksa 0 (otprilike centar maske po x)
- float x0 = vt2->fbft->projection->data.fl[2*0];
- // podesavanje granica na [-1,1] i [-1.3333, 1.3333]
- SetRange(point);
- // x i y kordinate verteksa u odnosu na centar slike
- float x_93 = centarX + x93 ;
- float x_78 = centarX + x78 ;
- float x_77 = centarX + x77 ;
- float x_92 = centarX + x92 ;
- float x_0 = centarX + x0 ;
- float y_78 = centarY + y78 ;
- float y_3 = centarY + y3 ;
- float y_77 = centarY + y77 ;
- if(point_x > x_0) side = 0; // lijeva strana maske
- else if(point_x < x_0) side =1; //desna strana maske
- // pozicija misa je istinita (true) u danom podrucju
- 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)));
- }
- bool COpenGLWnd::MoveNoseMiddleVerticalPosition(CPoint& point){ // & MOVE NoSE MIDDLE WIDTH
- // faceShape[6] i faceShape[9]
- var = 6;
- // y koordinate verteksa
- float y93 = vt2->fbft->projection->data.fl[2*93+1];
- float y94 = vt2->fbft->projection->data.fl[2*94+1];
- // x koordinate verteksa
- float x93 = vt2->fbft->projection->data.fl[2*93];
- float x92 = vt2->fbft->projection->data.fl[2*92];
- // x koordinata verteksa 0 (otprilike centar maske po x)
- float x0 = vt2->fbft->projection->data.fl[2*0];
- // podesavanje granica na [-1,1] i [-1.3333, 1.3333]
- SetRange(point);
- // x i y kordinate verteksa u odnosu na centar slike
- float x_93 = centarX + x93 ;
- float x_92 = centarX + x92 ;
- float x_0 = centarX + x0 ;
- float y_93 = centarY + y93 ;
- float y_94 = centarY + y94 ;
- //if(point_x > x_0) side = 0; // lijeva strana maske
- //else if(point_x < x_0) side =1; // desna strana maske
- // pozicija misa je istinita (true) u danom podrucju
- return(point_x <= x_93 && point_x >= x_92 && point_y >= y_93 && point_y <= y_94);
- }
- bool COpenGLWnd::MoveNoseLowerVerticalPosition(CPoint& point){
- // faceShape[7]
- var = 7;
- // y koordinate verteksa
- float y6 = vt2->fbft->projection->data.fl[2*6+1];
- float y76 = vt2->fbft->projection->data.fl[2*76+1];
- // x koordinate verteksa
- float x76 = vt2->fbft->projection->data.fl[2*76];
- float x75 = vt2->fbft->projection->data.fl[2*75];
- // podesavanje granica na [-1,1] i [-1.3333, 1.3333]
- SetRange(point);
- // x i y kordinate verteksa u odnosu na centar slike
- float x_75 = centarX + x75 ;
- float x_76 = centarX + x76 ;
- float y_76 = centarY + y76 ;
- float y_6 = centarY + y6 ;
- // pozicija misa je istinita (true) u danom podrucju
- return(point_x <= x_76 && point_x >= x_75 && point_y >= y_6 && point_y <= y_76);
- }
- bool COpenGLWnd::MoveNoseLowerWidth(CPoint &point){
- // faceShape[10]
- var = 10;
- // y koordinate verteksa
- float y6 = vt2->fbft->projection->data.fl[2*6+1];
- float y76 = vt2->fbft->projection->data.fl[2*76+1];
- // x koordinate verteksa
- float x59 = vt2->fbft->projection->data.fl[2*59];
- float x76 = vt2->fbft->projection->data.fl[2*76];
- float x75 = vt2->fbft->projection->data.fl[2*75];
- float x26 = vt2->fbft->projection->data.fl[2*26];
- // x koordinata verteksa 0 (otprilike centar maske po x)
- float x0 = vt2->fbft->projection->data.fl[2*0];
- // podesavanje granica na [-1,1] i [-1.3333, 1.3333]
- SetRange(point);
- // x i y kordinate verteksa u odnosu na centar slike
- float x_59 = centarX + x59 ;
- float x_76 = centarX + x76 ;
- float x_75 = centarX + x75 ;
- float x_26 = centarX + x26 ;
- float x_0 = centarX + x0 ;
- float y_6 = centarY + y6 ;
- float y_76 = centarY + y76 ;
- if(point_x > x_0) side = 0; // lijeva strana maske
- else if(point_x < x_0) side =1; // desna strana maske
- // pozicija misa je istinita (true) u danom podrucju
- 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)));
- }
- bool COpenGLWnd::MoveNoseThickness(CPoint &point){
- // faceShape[14]
- var = 14;
- // y koordinate verteksa
- float y58 = vt2->fbft->projection->data.fl[2*58+1];
- float y25 = vt2->fbft->projection->data.fl[2*25+1];
- // x koordinate verteksa
- float x58 = vt2->fbft->projection->data.fl[2*58];
- float x25 = vt2->fbft->projection->data.fl[2*25];
- float r = 0.03;
- // x koordinata verteksa 0 (otprilike centar maske po x)
- float x0 = vt2->fbft->projection->data.fl[2*0];
- // podesavanje granica na [-1,1] i [-1.3333, 1.3333]
- SetRange(point);
- // x i y kordinate verteksa u odnosu na centar slike
- float x_58 = centarX + x58 ;
- float x_25 = centarX + x25 ;
- float x_0 = centarX + x0 ;
- float y_58 = centarY + y58 ;
- float y_25 = centarY + y25 ;
- if(point_x > x_0) side = 0; // lijeva strana maske
- else if(point_x < x_0) side =1; // desna strana maske
- // pozicija misa je istinita (true) u danom podrucju
- 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) ;
- }
- bool COpenGLWnd::MoveEyebrowsBetweenVP(CPoint &point){
- // faceShape[19]
- var = 19;
- // y koordinate verteksa
- float y3 = vt2->fbft->projection->data.fl[2*3+1];
- float y3plus = y3 + 0.03;
- // x koordinate verteksa
- float x77 = vt2->fbft->projection->data.fl[2*77];
- float x78 = vt2->fbft->projection->data.fl[2*78];
- // podesavanje granica na [-1,1] i [-1.3333, 1.3333]
- SetRange(point);
- // x i y kordinate verteksa u odnosu na centar slike
- float x_77 = centarX + x77 ;
- float x_78 = centarX + x78 ;
- float y_3 = centarY + y3 ;
- float y_3plus = centarY + y3plus ;
- // pozicija misa je istinita (true) u danom podrucju
- return(point_x <= x_78 && point_x >= x_77 && point_y >= y_3 && point_y <= y_3plus);
- }
- bool COpenGLWnd::MoveEyebrowsInnerVP_SD(CPoint& point){
- // faceShape[20] i faceShape[21]
- var = 20;
- // y koordinate verteksa
- float y50 = vt2->fbft->projection->data.fl[2*50+1];
- float y17 = vt2->fbft->projection->data.fl[2*17+1];
- float r = 0.03;
- // x koordinate verteksa
- float x50 = vt2->fbft->projection->data.fl[2*50];
- float x17 = vt2->fbft->projection->data.fl[2*17];
- // x koordinata verteksa 0 (otprilike centar maske po x)
- float x0 = vt2->fbft->projection->data.fl[2*0];
- // podesavanje granica na [-1,1] i [-1.3333, 1.3333]
- SetRange(point);
- // x i y kordinate verteksa u odnosu na centar slike
- float x_50 = centarX + x50 ;
- float x_17 = centarX + x17 ;
- float x_0 = centarX + x0 ;
- float y_50 = centarY + y50 ;
- float y_17 = centarY + y17 ;
- if(point_x > x_0) side = 0; // lijeva strana maske
- else if(point_x < x_0) side =1; // desna strana maske
- // pozicija misa je istinita (true) u danom podrucju
- 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) ;
- }
- bool COpenGLWnd::MoveEyebrowsOuterVP_SD(CPoint& point){
- // faceShape[22] i faceShape[23]
- var = 22;
- // y koordinate verteksa
- float y48 = vt2->fbft->projection->data.fl[2*48+1];
- float y15 = vt2->fbft->projection->data.fl[2*15+1];
- float r = 0.03;
- // x koordinate verteksa
- float x48 = vt2->fbft->projection->data.fl[2*48];
- float x15 = vt2->fbft->projection->data.fl[2*15];
- // x koordinata verteksa 0 (otprilike centar maske po x)
- float x0 = vt2->fbft->projection->data.fl[2*0];
- // podesavanje granica na [-1,1] i [-1.3333, 1.3333]
- SetRange(point);
- // x i y kordinate verteksa u odnosu na centar slike
- float x_48 = centarX + x48 ;
- float x_15 = centarX + x15 ;
- float x_0 = centarX + x0 ;
- float y_48 = centarY + y48 ;
- float y_15 = centarY + y15 ;
- if(point_x > x_0) side = 0; // lijeva strana maske
- else if(point_x < x_0) side =1; // desna strana maske
- // pozicija misa je istinita (true) u danom podrucju
- 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) ;
- }
- bool COpenGLWnd::MoveEyebrowsMiddleVP_SD(CPoint& point){
- // faceShape[24] I faceShape[25]
- var = 24;
- // y koordinate verteksa
- float y51 = vt2->fbft->projection->data.fl[2*51+1];
- float y49 = vt2->fbft->projection->data.fl[2*49+1];
- float y16 = vt2->fbft->projection->data.fl[2*16+1];
- float y18 = vt2->fbft->projection->data.fl[2*18+1];
- float r = 0.03;
- // x koordinate verteksa
- float x51 = vt2->fbft->projection->data.fl[2*51];
- float x18 = vt2->fbft->projection->data.fl[2*18];
- // x koordinata verteksa 0 (otprilike centar maske po x)
- float x0 = vt2->fbft->projection->data.fl[2*0];
- float x51minus = x51 + r;
- float x51plus = x51 - r;
- float x18minus = x18 + r;
- float x18plus = x18 - r;
- // podesavanje granica na [-1,1] i [-1.3333, 1.3333]
- SetRange(point);
- // x i y kordinate verteksa u odnosu na centar slike
- float x_51minus = centarX + x51minus ;
- float x_51plus = centarX + x51plus ;
- float x_18minus = centarX + x18minus ;
- float x_18plus = centarX + x18plus ;
- float x_0 = centarX + x0 ;
- float y_51 = centarY + y51 ;
- float y_49 = centarY + y49 ;
- float y_18 = centarY + y18 ;
- float y_16 = centarY + y16 ;
- if(point_x > x_0) side = 0; // lijeva strana maske
- else if(point_x < x_0) side =1; // desna strana maske
- // pozicija misa je istinita (true) u danom podrucju
- 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));
- }
- bool COpenGLWnd::MoveEyebrowsThickness(CPoint &point){
- // faceShape[26]
- var = 26;
- // y koordinate verteksa
- float y49 = vt2->fbft->projection->data.fl[2*49+1];
- float y16 = vt2->fbft->projection->data.fl[2*16+1];
- float r = 0.03;
- // x koordinate verteksa
- float x49 = vt2->fbft->projection->data.fl[2*49];
- float x16 = vt2->fbft->projection->data.fl[2*16];
- float x49minus = x49 + r;
- float x49plus = x49 - r;
- float x16minus = x16 + r;
- float x16plus = x16 - r;
- // podesavanje granica na [-1,1] i [-1.3333, 1.3333]
- SetRange(point);
- // x i y kordinate verteksa u odnosu na centar slike
- float x_49minus = centarX + x49minus ;
- float x_49plus = centarX + x49plus ;
- float x_16minus = centarX + x16minus ;
- float x_16plus = centarX + x16plus ;
- float y_49up = centarY + (y49 + 0.03);
- float y_49 = centarY + y49 ;
- float y_16up = centarY + (y16 + 0.03);
- float y_16 = centarY + y16 ;
- // pozicija misa je istinita (true) u danom podrucju
- 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));
- }
- bool COpenGLWnd::MoveEyesVP_SD(CPoint &point){
- // faceShape[27] I faceShape[28]
- var = 27;
- // y koordinate verteksa
- float y100 = vt2->fbft->projection->data.fl[2*100+1];
- float y69 = vt2->fbft->projection->data.fl[2*69+1];
- float y107 = vt2->fbft->projection->data.fl[2*107+1];
- float y71 = vt2->fbft->projection->data.fl[2*71+1];
- // x koordinate verteksa
- float x100 = vt2->fbft->projection->data.fl[2*100];
- float x74 = vt2->fbft->projection->data.fl[2*74];
- float x107 = vt2->fbft->projection->data.fl[2*107];
- float x68 = vt2->fbft->projection->data.fl[2*68];
- // x koordinata verteksa 0 (otprilike centar maske po x)
- float x0 = vt2->fbft->projection->data.fl[2*0];
- // podesavanje granica na [-1,1] i [-1.3333, 1.3333]
- SetRange(point);
- // x i y kordinate verteksa u odnosu na centar slike
- float x_100 = centarX + x100 ;
- float x_107 = centarX + x107 ;
- float x_74 = centarX + x74 ;
- float x_68 = centarX + x68 ;
- float x_0 = centarX + x0 ;
- float y_100 = centarY + y100 ;
- float y_69 = centarY + y69 ;
- float y_107 = centarY + y107 ;
- float y_71 = centarY + y71 ;
- if(point_x > x_0) side = 0; // lijeva strana maske
- else if(point_x < x_0) side =1; // desna strana maske
- // pozicija misa je istinita (true) u danom podrucju
- 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));
- }
- bool COpenGLWnd::MoveEyesVD_Width(CPoint &point){
- // faceShape[29] i faceShape[31]
- var = 29;
- // y koordinate verteksa
- float y53 = vt2->fbft->projection->data.fl[2*53+1];
- float y56 = vt2->fbft->projection->data.fl[2*56+1];
- float y23 = vt2->fbft->projection->data.fl[2*23+1];
- float y20 = vt2->fbft->projection->data.fl[2*20+1];
- float r = 0.03;
- // x koordinate verteksa
- float x53 = vt2->fbft->projection->data.fl[2*53];
- float x56 = vt2->fbft->projection->data.fl[2*56];
- float x23 = vt2->fbft->projection->data.fl[2*23];
- float x20 = vt2->fbft->projection->data.fl[2*20];
- // x koordinata verteksa 55 i 22 (otprilike centar ociju po x)
- float x55 = vt2->fbft->projection->data.fl[2*55];
- float x22 = vt2->fbft->projection->data.fl[2*22];
- // x koordinata verteksa 0 (otprilike centar maske po x)
- float x0 = vt2->fbft->projection->data.fl[2*0];
- // podesavanje granica na [-1,1] i [-1.3333, 1.3333]
- SetRange(point);
- // x i y kordinate verteksa u odnosu na centar slike
- float x_53 = centarX + x53 ;
- float x_56 = centarX + x56 ;
- float x_23 = centarX + x23 ;
- float x_20 = centarX + x20 ;
- float x_55 = centarX + x55 ;
- float x_22 = centarX + x22 ;
- float x_0 = centarX + x0 ;
- float y_53 = centarY + y53 ;
- float y_56 = centarY + y56 ;
- float y_23 = centarY + y23 ;
- float y_20 = centarY + y20 ;
- if((point_x > x_55 && point_x < x_53) || (point_x > x_22 && point_x < x_23)) side = 0; // lijeva strana maske
- else if((point_x > x_56 && point_x < x_55) || (point_x > x_20 && point_x < x_22)) side =1; // desna strana maske
- /// pozicija misa je istinita (true) u danom podrucju
- 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);
- }
- bool COpenGLWnd::MoveEyesHeight(CPoint &point){
- // faceShape[30]
- var = 30;
- // y koordinate verteksa
- float y52 = vt2->fbft->projection->data.fl[2*52+1];
- float y22 = vt2->fbft->projection->data.fl[2*22+1];
- float y55 = vt2->fbft->projection->data.fl[2*55+1];
- float y21 = vt2->fbft->projection->data.fl[2*21+1];
- float r = 0.03;
- // x koordinate verteksa
- float x69 = vt2->fbft->projection->data.fl[2*69];
- float x73 = vt2->fbft->projection->data.fl[2*73];
- float x71 = vt2->fbft->projection->data.fl[2*71];
- float x67 = vt2->fbft->projection->data.fl[2*67];
- // podesavanje granica na [-1,1] i [-1.3333, 1.3333]
- SetRange(point);
- // x i y kordinate verteksa u odnosu na centar slike
- float x_69 = centarX + x69 ;
- float x_73 = centarX + x73 ;
- float x_71 = centarX + x71 ;
- float x_67 = centarX + x67 ;
- float y_52up = centarY + (y52 + 0.03);
- float y_52 = centarY + y52 ;
- float y_21up = centarY + (y21 + 0.03);
- float y_21 = centarY + y21 ;
- float y_22 = centarY + y22 ;
- float y_22down = centarY + (y22 - 0.03);
- float y_55 = centarY + y55 ;
- float y_55down = centarY + (y55 - 0.03);
- // pozicija misa je istinita (true) u danom podrucju
- 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));
- }
- bool COpenGLWnd::MoveMouthVP(CPoint &point){
- // faceShape[32]
- var = 32;
- // y koordinate verteksa
- float y8 = vt2->fbft->projection->data.fl[2*8+1];
- float y7 = vt2->fbft->projection->data.fl[2*7+1];
- // x koordinate verteksa
- float x82 = vt2->fbft->projection->data.fl[2*82];
- float x83 = vt2->fbft->projection->data.fl[2*83];
- // podesavanje granica na [-1,1] i [-1.3333, 1.3333]
- SetRange(point);
- // x i y kordinate verteksa u odnosu na centar slike
- float x_82 = centarX + x82 ;
- float x_83 = centarX + x83 ;
- float y_8 = centarY + y8 ;
- float y_7 = centarY + y7 ;
- // pozicija misa je istinita (true) u danom podrucju
- return(point_x <= x_82 && point_x >= x_83 && point_y >= y_8 && point_y <= y_7);
- }
- bool COpenGLWnd::MoveMouthWidth_Bending(CPoint &point){
- // faceShape[33] I faceShape[34]
- var = 33;
- // y koordinate verteksa
- float y7 = vt2->fbft->projection->data.fl[2*7+1];
- float y8 = vt2->fbft->projection->data.fl[2*8+1];
- // x koordinate verteksa
- float x64 = vt2->fbft->projection->data.fl[2*64];
- float x89 = vt2->fbft->projection->data.fl[2*89];
- float x88 = vt2->fbft->projection->data.fl[2*88];
- float x31 = vt2->fbft->projection->data.fl[2*31];
- // x koordinata verteksa 0 (otprilike centar maske po x)
- float x0 = vt2->fbft->projection->data.fl[2*0];
- // podesavanje granica na [-1,1] i [-1.3333, 1.3333]
- SetRange(point);
- // x i y kordinate verteksa u odnosu na centar slike
- float x_64 = centarX + x64 ;
- float x_89 = centarX + x89 ;
- float x_88 = centarX + x88 ;
- float x_31 = centarX + x31 ;
- float x_0 = centarX + x0 ;
- float y_8 = centarY + y8 ;
- float y_7 = centarY + y7 ;
- if(point_x > x_0) side = 0; // lijeva strana maske
- else if(point_x < x_0) side =1; // desna strana maske
- // pozicija misa je istinita (true) u danom podrucju
- 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));
- }
- bool COpenGLWnd::MoveMouthLipThickness(CPoint &point){
- // faceShape[35]
- var = 35;
- // y koordinate verteksa
- float y8 = vt2->fbft->projection->data.fl[2*8+1];
- float y7 = vt2->fbft->projection->data.fl[2*7+1];
- // y koordinata verteksa 80 (otprilike centar usta)
- float y80 = vt2->fbft->projection->data.fl[2*80+1];
- float y7up = y7 + 0.03;
- float y8down = y8 - 0.03;
- // x koordinate verteksa
- float x66 = vt2->fbft->projection->data.fl[2*66];
- float x33 = vt2->fbft->projection->data.fl[2*33];
- // podesavanje granica na [-1,1] i [-1.3333, 1.3333]
- SetRange(point);
- // x i y kordinate verteksa u odnosu na centar slike
- float x_66 = centarX + x66 ;
- float x_33 = centarX + x33 ;
- float y_80 = centarY + y80 ;
- float y_8 = centarY + y8 ;
- float y_8down = centarY + y8down ;
- float y_7 = centarY + y7 ;
- float y_7up = centarY + y7up ;
- if(point_y > y_80) side = 0; // up
- else if(point_y < y_80) side =1; // down
- // pozicija misa je istinita (true) u danom podrucju
- 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)) ;
- }
- void COpenGLWnd::RightButtonDown(int x, int y)
- {
- mRightButtonX = (GLfloat)x;
- mRightButtonY = (GLfloat)y;
- mRotateXAngleAdd = 0;
- mRotateYAngleAdd = 0;
- // SetTimer(mhWnd, (UINT) IGLW_TIMER_ROTATE, 100, NULL);
- // SetCapture(mhWnd);
- }
- void COpenGLWnd::LeftButtonControlDown(int x, int y)
- {
- // Y gives the zoom factor in Z direction.
- mLeftButtonControlZ = (GLfloat)y;
- }
- void COpenGLWnd::RightButtonControlDown(int x, int y){
- mRightButtonControlY = (GLfloat)y;
- mRightButtonControlX = (GLfloat)x;
- }
- void COpenGLWnd::LeftButtonDrag(float x, float y)
- {
- if(!trackerActive){
- mXTranslate += (x - mLeftButtonX) * mXAccel;
- // Windows y-axis is reversed to openGL.
- mYTranslate -= (y - mLeftButtonY) * mYAccel;
- // Save off current position
- mLeftButtonX = (GLfloat)x;
- mLeftButtonY = (GLfloat)y;
- // Redraw screen.
- RenderToScreen();
- }
- else{
- if(var==40){
- ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZENS));
- faceShape[40] += (GLfloat)(y - mLeftButtonY )*0.02;
- }// jaw height
- else if(var==38){
- ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEALL));
- faceShape[38] -= (GLfloat)(y - mLeftButtonY)*0.008; // iris height
- if(side == 0)faceShape[39] -= (GLfloat)(x - mLeftButtonX)*0.02; // left iris width
- else if(side == 1)faceShape[39] += (GLfloat)(x - mLeftButtonX)*0.02; // right iris width
- }
- else if(var==0){
- ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZENS));
- faceShape[0] -= (GLfloat)(y - mLeftButtonY )*0.02;
- }// head height
- else if(var==1 && side == 0){
- ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEWE));
- faceShape[1] -= (GLfloat)(x - mLeftButtonX)*0.02;
- } // left head upper width
- else if(var==1 && side == 1){
- ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEWE));
- faceShape[1] += (GLfloat)(x - mLeftButtonX)*0.02;
- } // right head upper width
- else if(var==2 && side == 0){
- ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEWE));
- faceShape[2] -= (GLfloat)(x - mLeftButtonX)*0.02;
- }// left head middle width
- else if(var==2 && side == 1){
- ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEWE));
- faceShape[2] += (GLfloat)(x - mLeftButtonX)*0.02;
- }// right head middle width
- else if(var==3 && side == 0){
- ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEWE));
- faceShape[3] -= (GLfloat)(x - mLeftButtonX)*0.02;
- }// left head lower width
- else if(var==3 && side == 1){
- ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEWE));
- faceShape[3] += (GLfloat)(x - mLeftButtonX)*0.02;
- }// right head lower width
- else if(var==4 && side == 0){
- ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEWE));
- faceShape[4] -= (GLfloat)(x - mLeftButtonX)*0.02;
- }// left chin width
- else if(var==4 && side == 1){
- ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEWE));
- faceShape[4] += (GLfloat)(x - mLeftButtonX)*0.02;
- ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEWE));
- }// right chin width
- else if(var==5){
- ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZENS));
- faceShape[5] -= (GLfloat)(y - mLeftButtonY)*0.02;
- }// nose upper vertical position
- else if(var==6){
- ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEALL));
- faceShape[6] -= (GLfloat)(y - mLeftButtonY)*0.02; // nose middle vertical position
- faceShape[9] -= (GLfloat)(x - mLeftButtonX)*0.02; // nose middle width
- }
- else if(var==7){
- ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZENS));
- faceShape[7] -= (GLfloat)(y - mLeftButtonY)*0.02;
- }// nose lower vertical position
- else if(var==8){
- ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEWE));
- if(side == 0)// left nose upper width
- faceShape[8] -= (GLfloat)(x - mLeftButtonX)*0.02;
- else if (side == 1)// right nose upper width
- faceShape[8] += (GLfloat)(x - mLeftButtonX)*0.02;
- }
- else if(var==10){
- ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEWE));
- if(side == 0)// left nose lower width
- faceShape[10] -= (GLfloat)(x - mLeftButtonX)*0.02;
- else if(side == 1)// right nose lower width
- faceShape[10] += (GLfloat)(x - mLeftButtonX)*0.02;
- }
- else if(var==14){
- ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEWE));
- if(side == 0)// left nose thickness
- faceShape[14] -= (GLfloat)(x - mLeftButtonX)*0.02;
- else if(side == 1)// right nose thickness
- faceShape[14] += (GLfloat)(x - mLeftButtonX)*0.02;
- }
- else if(var==19){
- ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZENS));
- faceShape[19] -= (GLfloat)(y - mLeftButtonY)*0.02;
- }// eyebrows between vertical position
- else if(var==20){
- ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEALL));
- faceShape[20] -= (GLfloat)(y - mLeftButtonY)*0.02; // eyebrows inner vertical position
- if(side == 0)faceShape[21] -= (GLfloat)(x - mLeftButtonX)*0.02; // left eyebrows inner separation distance
- else if(side == 1)faceShape[21] += (GLfloat)(x - mLeftButtonX)*0.02; // right eyebrows inner separation distance
- }
- else if(var==22){
- ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEALL));
- faceShape[22] -= (GLfloat)(y - mLeftButtonY)*0.02; // eyebrows outer vertical position
- if(side == 0)faceShape[23] -= (GLfloat)(x - mLeftButtonX)*0.02; // left eyebrows outer separation distance
- else if(side == 1)faceShape[23] += (GLfloat)(x - mLeftButtonX)*0.02; // right eyebrows outer separation distance
- }
- else if(var==24){
- ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEALL));
- faceShape[24] -= (GLfloat)(y - mLeftButtonY)*0.02; // eyebrows middle vertical position
- if(side == 0)faceShape[25] -= (GLfloat)(x - mLeftButtonX)*0.02; // left eyebrows middle separation distance
- else if(side == 1)faceShape[25] += (GLfloat)(x - mLeftButtonX)*0.02; // right eyebrows middle separation distance
- }
- else if(var==26){
- ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZENS));
- faceShape[26] -= (GLfloat)(y - mLeftButtonY)*0.02;
- }// eyebrows thickness
- else if(var==27){
- ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEALL));
- faceShape[27] -= (GLfloat)(y - mLeftButtonY)*0.02; // eyes vertical position
- if(side == 0)faceShape[28] -= (GLfloat)(x - mLeftButtonX)*0.02; // left eyes separation distance
- else if(side == 1)faceShape[28] += (GLfloat)(x - mLeftButtonX)*0.02; // right eyes separation distance
- }
- else if(var==29){
- ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEALL));
- faceShape[29] -= (GLfloat)(y - mLeftButtonY)*0.008; // eyes vertical difference
- if(side == 0)faceShape[31] -= (GLfloat)(x - mLeftButtonX)*0.02; // left eyes width
- else if(side == 1)faceShape[31] += (GLfloat)(x - mLeftButtonX)*0.02; // right eyes width
- }
- else if(var==30){
- ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZENS));
- faceShape[30] -= (GLfloat)(y - mLeftButtonY)*0.02;
- }// eyes height
- else if(var==32){
- ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZENS));
- faceShape[32] -= (GLfloat)(y - mLeftButtonY)*0.02;
- }// mouth vertical position
- else if(var==33){
- ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEALL));
- faceShape[34] += (GLfloat)(y - mLeftButtonY)*0.02; // mouth bending
- if(side == 0)faceShape[33] -= (GLfloat)(x - mLeftButtonX)*0.02; // left mouth width
- else if(side == 1)faceShape[33] += (GLfloat)(x - mLeftButtonX)*0.02; // right mouth width
- }
- else if(var==35){
- ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZENS));
- if(side == 0)faceShape[35] -= (GLfloat)(y - mLeftButtonY)*0.02; // mouth lip thickness up
- else if(side == 1)faceShape[35] += (GLfloat)(y - mLeftButtonY)*0.02; // mouth lip thickness down
- }
- /*else if(var==36){
- ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZENS));
- faceShape[36] += (GLfloat)(y - mLeftButtonY )*0.2;
- }//jaw*/
- // Save off current position
- mLeftButtonY = (GLfloat)y;
- mLeftButtonX = (GLfloat)x;
- /*
- mXTranslate += (x - mLeftButtonX) * mXAccel;
- // Windows y-axis is reversed to openGL.
- mYTranslate -= (y - mLeftButtonY) * mYAccel;
- // Save off current position
- mLeftButtonX = (GLfloat)x;
- mLeftButtonY = (GLfloat)y;
- // Redraw screen.
- */
- }
- }
- void COpenGLWnd::RightButtonDrag(int x, int y)
- {
- if(trackerActive){
- faceTranslation[1] -= (y - mRightButtonY)*0.009;
- mRightButtonY = (GLfloat)y;
- faceTranslation[0] -= (x - mRightButtonX)*0.009;
- mRightButtonX = (GLfloat)x;
- }
- else{
- // Rotates object around X or Y axis, distance from first point gives angular rotation speed.
- // Y axis rotation is given by distance in X coords, and vice versa.
- mRotateXAngleAdd = (GLfloat)((y - mRightButtonY) * 0.1);
- mRotateYAngleAdd = (GLfloat)((x - mRightButtonX) * 0.1);
- }
- }
- void COpenGLWnd::RightButtonControlDrag(int x, int y){
- faceRotation[1] -= (x - mRightButtonControlX)*0.005;
- faceRotation[0] -= (y - mRightButtonControlY)*0.005;
- mRightButtonControlX = (GLfloat)x;
- mRightButtonControlY = (GLfloat)y;
- }
- void COpenGLWnd::RightButtonControlShiftDrag(int x, int y){
- faceRotation[2] -= (y - mRightButtonControlY)*0.005;
- mRightButtonControlY = (GLfloat)y;
- }
- void COpenGLWnd::LeftButtonControlDrag(int x, int y)
- {
- if (!trackerActive){
- mZTranslate += (y - mLeftButtonControlZ) * mZAccel;
- mLeftButtonControlZ = (GLfloat)y;
- RenderToScreen();
- }
- else{
- faceScale[0] -=(y - mLeftButtonY)*0.002;
- mLeftButtonY = (GLfloat)y;
- }
- }
- void COpenGLWnd::RightButtonDownTimerFunc()
- {
- mXRotAngle += mRotateXAngleAdd;
- mYRotAngle += mRotateYAngleAdd;
- // Keep it within 360 degrees so that we don't get unpleasant surprises if datatype overflows.
- if(mXRotAngle > 360.0f)
- mXRotAngle -= 360.0f;
- if(mXRotAngle < 0.0f)
- mXRotAngle += 360.0f;
- if(mYRotAngle > 360.0f)
- mYRotAngle -= 360.0f;
- if(mYRotAngle < 0.0f)
- mYRotAngle += 360.0f;
- RenderToScreen();
- }
- void COpenGLWnd::FitToScreen()
- {
- mXTranslate = mXTranslateFit;
- mYTranslate = mYTranslateFit;
- mZTranslate = mZTranslateFit;
- mXRotAngle = 0;
- mYRotAngle = 0;
- RenderToScreen();
- }
- void COpenGLWnd::FitToScreen(float zoom)
- {
- mXTranslate = mXTranslateFit;
- mYTranslate = mYTranslateFit;
- mZTranslate = mZTranslateFit * zoom;
- mXRotAngle = 0;
- mYRotAngle = 0;
- RenderToScreen();
- }
- /**************************************************************************/
- /**************************************************************************/
- /**************************************************************************/
- /**************** VISAGE TRACKER 2 ************************/
- /**************************************************************************/
- /**************************************************************************/
- /**************************************************************************/
- char* COpenGLWnd::ChooseSuFileName()
- {
- CDialogFirstTimeTrackingNew dlg;
- char *suFileName = (char*)malloc(200);
- dlg.suFileName = suFileName;
- dlg.DoModal();
- return suFileName;
- }
- void COpenGLWnd::displayMessage(char *userMessage,char *caption,int type)
- {
- MessageBox(userMessage,caption,type);
- }
- void COpenGLWnd::setOpenGLContext()
- {
- // set current window
- glutSetWindow(glutMainWindow);
- // set the context
- //wglMakeCurrent(m_pDC->GetSafeHdc(), m_hRC1);
- glViewport(0,0,mWindowWidth,mWindowHeight); // Reset The Current Viewport
- // clear the frame buffer before next drawing
- glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
- //verify color depth - FaceTracker needs 8 bits for each color
- static bool verified = false; // verify only once
- if(!verified)
- {
- verified = true;
- GLint redBits=0, greenBits=0, blueBits=0;
- glGetIntegerv (GL_RED_BITS, &redBits);
- glGetIntegerv (GL_GREEN_BITS, &greenBits);
- glGetIntegerv (GL_BLUE_BITS, &blueBits);
- if(redBits < 8 || greenBits < 8 || blueBits < 8)
- {
- 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);
- exit(0);
- }
- }
- }
- void COpenGLWnd::swapOpenGLBuffers()
- {
- //SwapBuffers(m_pDC->GetSafeHdc());
- //wglMakeCurrent(NULL, NULL);
- glutSwapBuffers();
- }
- void COpenGLWnd::ManuallyAdjustShapeMask(float *face_translation, float *face_rotation, float *face_scale, float *face_shape)
- {
- otvoren_dialog = true;
- faceShape = face_shape;
- faceScale = face_scale;
- faceRotation = face_rotation;
- faceTranslation = face_translation;
- CDialogNew shpman;
- shpman.vt2=vt2;
- shpman.faceTranslation=face_translation;
- shpman.faceRotation=face_rotation;
- shpman.faceScale=face_scale;
- shpman.faceShape=face_shape;
- nRet = shpman.DoModal();
- if ( nRet == IDOK || nRet == IDCANCEL )
- {zatvoren_dialog = 5;
- }
- }
- void _signalWhenUserReady(void *_arg)
- {
- char **arg = (char**)_arg;
- char *userMessage = (char*)arg[0];
- bool *readyFlag = (bool*)arg[1];
- MessageBox(0,userMessage,"",MB_OK);
- readyFlag[0] = true;
- free(arg);
- }
- void COpenGLWnd::signalWhenUserReady(char *userMessage,bool *readyFlag)
- {
- char **arg = (char**) malloc(2*sizeof(char*));
- arg[0] = userMessage;
- arg[1] = (char*)readyFlag;
- _beginthread(_signalWhenUserReady,0,arg);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement