?? triangleview.cpp
字號:
pFrame->m_fLeftHandX = fOffsetX;
pFrame->m_fLeftHandY = fOffsetY;
this->CheckAngle(&pFrame->m_fLeftHandX, &pFrame->m_fLeftHandY);
break;
case RIGHT_UPPER_ARM:
pFrame->m_fRightUpperArmX = fOffsetX;
pFrame->m_fRightUpperArmY = fOffsetY;
this->CheckAngle(&pFrame->m_fRightUpperArmX, &pFrame->m_fRightUpperArmY);
break;
case RIGHT_LOWER_ARM:
pFrame->m_fRightLowerArmX = fOffsetX;
pFrame->m_fRightLowerArmY = fOffsetY;
this->CheckAngle(&pFrame->m_fRightLowerArmX, &pFrame->m_fRightLowerArmY);
break;
case RIGHT_HAND:
pFrame->m_fRightHandX = fOffsetX;
pFrame->m_fRightHandY = fOffsetY;
this->CheckAngle(&pFrame->m_fRightHandX, &pFrame->m_fRightHandY);
break;
case LEFT_UPPER_LEG:
pFrame->m_fLeftUpperLegX = fOffsetX;
pFrame->m_fLeftUpperLegY = fOffsetY;
this->CheckAngle(&pFrame->m_fLeftUpperLegX, &pFrame->m_fLeftUpperLegY);
break;
case LEFT_LOWER_LEG:
pFrame->m_fLeftLowerLegX = fOffsetX;
pFrame->m_fLeftLowerLegY = fOffsetY;
this->CheckAngle(&pFrame->m_fLeftLowerLegX, &pFrame->m_fLeftLowerLegY);
break;
case LEFT_FOOT:
pFrame->m_fLeftFootX = fOffsetX;
pFrame->m_fLeftFootY = fOffsetY;
this->CheckAngle(&pFrame->m_fLeftFootX, &pFrame->m_fLeftFootY);
break;
case RIGHT_UPPER_LEG:
pFrame->m_fRightUpperLegX = fOffsetX;
pFrame->m_fRightUpperLegY = fOffsetY;
this->CheckAngle(&pFrame->m_fRightUpperLegX, &pFrame->m_fRightUpperLegY);
break;
case RIGHT_LOWER_LEG:
pFrame->m_fRightLowerLegX = fOffsetX;
pFrame->m_fRightLowerLegY = fOffsetY;
this->CheckAngle(&pFrame->m_fRightLowerLegX, &pFrame->m_fRightLowerLegY);
break;
case RIGHT_FOOT:
pFrame->m_fRightFootX = fOffsetX;
pFrame->m_fRightFootY = fOffsetY;
this->CheckAngle(&pFrame->m_fRightFootX, &pFrame->m_fRightFootY);
break;
default:
break;
}
}
void CTriangleView::OnMotionfileopen()
{
CString strFile;
CFileDialog dlg(TRUE, // Save
NULL, // No default extension
NULL, // No initial file name
OFN_OVERWRITEPROMPT
| OFN_HIDEREADONLY,
"motion files (*.mot)|*.mot|All files (*.*)|*.*||");
if (dlg.DoModal() == IDOK)
{
strFile = dlg.GetPathName();
if(LoadMotion2File((LPSTR)(LPCTSTR)strFile) == FALSE)
{
ResetSystem();
}
}
}
BOOL CTriangleView::LoadMotion2File(LPSTR pszFileName)
{
// Try to open the file for write access.
CString strFile = pszFileName;
CFile file;
if (! file.Open(strFile,
CFile::modeRead | CFile::shareDenyWrite))
{
TRACE("Failed to open file");
return FALSE;
}
BOOL bResult = LoadMotion2File(&file);
file.Close();
if (!bResult) AfxMessageBox("Failed to load file");
return bResult;
}
BOOL CTriangleView::LoadMotion2File(CFile* fp)
{
ResetSystem();
DWORD dwFileStart = fp->GetPosition();
int head1;
int head2;
CMainFrame *pMainFrame;
pMainFrame = (CMainFrame*)AfxGetMainWnd();
CString str;
fp->Read(&head1, sizeof(int));
fp->Read(&head2, sizeof(int));
if(head1 != 3120 || head2 != 2590)
{
AfxMessageBox("Error of motion file format");
return FALSE;
}
int iMaxGroup;
fp->Read(&iMaxGroup, sizeof(int));
this->m_iTotalGroup = iMaxGroup;
int i;
fp->Read(&this->Anim, sizeof(ANIMATION));
Anim.next = Anim.prev = &Anim;
LoadFrame2File(fp, &this->Anim);
LPANIMATION pAnim = NULL;
LPANIMATION pLast = NULL;
// pAnim = (LPANIMATION)LocalAlloc(LPTR, sizeof(ANIMATION));
for(i=2; i<=iMaxGroup; i++)
{
pAnim = (LPANIMATION)LocalAlloc(LPTR, sizeof(ANIMATION));
fp->Read(pAnim, sizeof(ANIMATION));
LoadFrame2File(fp, pAnim);
if(pAnim == NULL)
{
AfxMessageBox("Error of add Group into list\n");
return FALSE;
}
// this->AddGroupFromFile(pAnim);
pLast = this->Anim.prev;
LinkGroup(pAnim, pLast);
str.GetBuffer(20);
str.Format("%s", pAnim->name);
pMainFrame->AddGroupString(&str);
str.Empty();
}
// LocalFree(pAnim);
str.GetBuffer(20);
str.Format("%s", this->Anim.name);
pMainFrame->AddGroupString(&str);
pMainFrame->SetCurrentAnim(&str);
this->UpdateFrameInfo();
Invalidate(FALSE);
return TRUE;
}
BOOL CTriangleView::LoadFrame2File(CFile *fp, LPANIMATION pAnim)
{
int TotalFrame = pAnim->m_iTotalFrame;
int iSize;
int i;
iSize = sizeof(FRAME);
fp->Read(&pAnim->FrameList, iSize);
pAnim->FrameList.next = pAnim->FrameList.prev = &pAnim->FrameList;
LPFRAME temp;
temp = (LPFRAME)LocalAlloc(LPTR, iSize);
if(temp == NULL)
{
AfxMessageBox("Error of temp frame 2107");
return FALSE;
}
TRACE("Total Frame is %d\n", TotalFrame);
for(i=2; i<=TotalFrame; i++)
{
fp->Read(temp, sizeof(FRAME));
this->AddFrameFromFile(temp, pAnim);
}
LocalFree(temp);
return TRUE;
}
void CTriangleView::AddGroupFromFile(LPANIMATION pFileAnim)
{
LPANIMATION pAnim;
pAnim = (LPANIMATION)LocalAlloc(LPTR, sizeof(ANIMATION));
if(pAnim == NULL)
{
AfxMessageBox("Error of add Group into list\n");
return;
}
memcpy((void*)pAnim, (void*)pFileAnim, sizeof(ANIMATION));
LPANIMATION pLast = this->Anim.prev;
LinkGroup(pAnim, pLast);
}
void CTriangleView::AddFrameFromFile(LPFRAME pFileFrame, LPANIMATION pAnim)
{
LPFRAME pFrame;
pFrame = (LPFRAME)LocalAlloc(LPTR, sizeof(FRAME));
if(pFrame == NULL)
{
AfxMessageBox("Error of add frame into list\n");
return;
}
memcpy((void*)pFrame, (void*)pFileFrame, sizeof(FRAME));
LPFRAME pLast;
pLast = pAnim->FrameList.prev;
LinkFrame(pFrame, pLast);
}
void CTriangleView::OnMotionfilesave()
{
CString strFile;
CFileDialog dlg(FALSE, // Save
NULL, // No default extension
NULL, // No initial file name
OFN_OVERWRITEPROMPT
| OFN_HIDEREADONLY,
"motion files (*.mot)|*.mot|All files (*.*)|*.*||");
if (dlg.DoModal() == IDOK)
{
strFile = dlg.GetPathName();
SaveMotion2File((LPSTR)(LPCTSTR)strFile);
}
}
BOOL CTriangleView::SaveMotion2File(LPSTR pszFileName)
{
// Try to open the file for write access.
CString strFile = pszFileName;
CFile file;
if (!file.Open(strFile,
CFile::modeReadWrite
| CFile::modeCreate
| CFile::shareExclusive))
{
AfxMessageBox("Failed to open file");
return FALSE;
}
BOOL bResult = SaveMotion2File(&file);
file.Close();
if (!bResult) AfxMessageBox("Failed to save file");
return bResult;
}
BOOL CTriangleView::SaveMotion2File(CFile* fp)
{
CMainFrame *pFrame;
pFrame = (CMainFrame*)AfxGetMainWnd();
int iSize = sizeof(int);
int head = 3120;
TRY
{
fp->Write(&head, iSize);
} CATCH(CFileException, e)
{
TRACE("Failed to write file header");
return FALSE;
} END_CATCH
head = 2590;
TRY
{
fp->Write(&head, iSize);
} CATCH(CFileException, e)
{
TRACE("Failed to write file header");
return FALSE;
} END_CATCH
int iMaxGroup = this->m_iTotalGroup;
TRY
{
fp->Write(&iMaxGroup, iSize);
} CATCH(CFileException, e)
{
TRACE("Failed to write file header");
return FALSE;
} END_CATCH
LPANIMATION current;
LPANIMATION last;
LPANIMATION save;
current = &this->Anim;
last = &this->Anim;
iSize = sizeof(ANIMATION);
do
{
save = current;
current = current->next;
TRY
{
fp->Write(save, iSize);
} CATCH(CFileException, e)
{
TRACE("Failed to write file header");
return FALSE;
} END_CATCH
if(FALSE == SaveFrame2File(fp, save))
{
AfxMessageBox("Error of Save Frame");
}
}//do-while...
while( current != last);
return TRUE;
}
BOOL CTriangleView::SaveFrame2File(CFile *fp, LPANIMATION pAnim)
{
LPFRAME current;
LPFRAME last;
LPFRAME save;
current = &pAnim->FrameList;
last = &pAnim->FrameList;
int iSize = sizeof(FRAME);
do
{
save = current;
current = current->next;
TRY
{
fp->Write(save, iSize);
} CATCH(CFileException, e)
{
TRACE("Failed to write file header");
return FALSE;
} END_CATCH
}//do-while...
while( current != last);
return TRUE;
}
void CTriangleView::ResetSystem()
{
LPANIMATION current;
LPANIMATION last;
LPANIMATION die;
current = &Anim;
last = &Anim;
do
{
if(current->m_iID != 0)
{
die = current;
current = current->next;
DelGroup(die);
}else
{
current = current->next;
}
}//do-while
while(current != last);
CMainFrame *pMainFrame;
pMainFrame = (CMainFrame*)AfxGetMainWnd();
CString str;
str.GetBuffer(20);
str.Format("%s", Anim.name);
pMainFrame->DelGroupString(&str);
InitAnim();
}
void CTriangleView::OnSize(UINT nType, int cx, int cy)
{
CView::OnSize(nType, cx, cy);
VERIFY(wglMakeCurrent(m_hDC,m_hRC));
GLResize(cx, cy);
VERIFY(wglMakeCurrent(NULL,NULL));
}
BOOL CTriangleView::OnQueryNewPalette()
{
// If the palette was created.
if((HPALETTE)m_GLPalette)
{
int nRet;
// Selects the palette into the current device context
SelectPalette(m_hDC, (HPALETTE)m_GLPalette, FALSE);
// Map entries from the currently selected palette to
// the system palette. The return value is the number
// of palette entries modified.
nRet = RealizePalette(m_hDC);
// Repaint, forces remap of palette in current window
InvalidateRect(NULL,FALSE);
return nRet;
}
return CView::OnQueryNewPalette();
}
void CTriangleView::OnPaletteChanged(CWnd* pFocusWnd)
{
if(((HPALETTE)m_GLPalette != NULL) && (pFocusWnd != this))
{
// Select the palette into the device context
SelectPalette(m_hDC,(HPALETTE)m_GLPalette,FALSE);
// Map entries to system palette
RealizePalette(m_hDC);
// Remap the current colors to the newly realized palette
UpdateColors(m_hDC);
return;
}
CView::OnPaletteChanged(pFocusWnd);
}
int CTriangleView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
int nPixelFormat; // Pixel format index
m_hDC = ::GetDC(m_hWnd); // Get the Device context
static PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR), // Size of this structure
1, // Version of this structure
PFD_DRAW_TO_WINDOW | // Draw to Window (not to bitmap)
PFD_SUPPORT_OPENGL | // Support OpenGL calls in window
PFD_DOUBLEBUFFER, // Double buffered mode
PFD_TYPE_RGBA, // RGBA Color mode
24, // Want 24bit color
0,0,0,0,0,0, // Not used to select mode
0,0, // Not used to select mode
0,0,0,0,0, // Not used to select mode
32, // Size of depth buffer
0, // Not used to select mode
0, // Not used to select mode
PFD_MAIN_PLANE, // Draw in main plane
0, // Not used to select mode
0,0,0 }; // Not used to select mode
// Choose a pixel format that best matches that described in pfd
nPixelFormat = ChoosePixelFormat(m_hDC, &pfd);
// Set the pixel format for the device context
VERIFY(SetPixelFormat(m_hDC, nPixelFormat, &pfd));
// Create the rendering context
m_hRC = wglCreateContext(m_hDC);
// Make the rendering context current, perform initialization, then
// deselect it
VERIFY(wglMakeCurrent(m_hDC,m_hRC));
GLSetupRC(m_hDC);
wglMakeCurrent(NULL,NULL);
// Create the palette if needed
InitializePalette();
return 0;
}
void CTriangleView::OnDestroy()
{
CView::OnDestroy();
// Clean up rendering context stuff
wglDeleteContext(m_hRC);
::ReleaseDC(m_hWnd,m_hDC);
}
BOOL CTrian
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -