Курсовой проект 106 страниц, 42 рисунка, 2 таблицы, 18 фомул, 15 матриц, 4 приложения
Скачать 5.65 Mb.
|
} void GetType(int lmt, HWND hDlg) { switch(lmt) { case LMT_POINT: SendMessage(GetDlgItem(hDlg, IDC_LMT_POINT), BM_SETCHECK, true, 0); SendMessage(GetDlgItem(hDlg, IDC_LMT_CYL), BM_SETCHECK, false, 0); SendMessage(GetDlgItem(hDlg, IDC_LMT_REMOTE), BM_SETCHECK, false, 0); break; case LMT_CYL: SendMessage(GetDlgItem(hDlg, IDC_LMT_CYL), BM_SETCHECK, true, 0); SendMessage(GetDlgItem(hDlg, IDC_LMT_POINT), BM_SETCHECK, false, 0); SendMessage(GetDlgItem(hDlg, IDC_LMT_REMOTE), BM_SETCHECK, false, 0); break; case LMT_REMOTE: SendMessage(GetDlgItem(hDlg, IDC_LMT_REMOTE), BM_SETCHECK, true, 0); SendMessage(GetDlgItem(hDlg, IDC_LMT_POINT), BM_SETCHECK, false, 0); SendMessage(GetDlgItem(hDlg, IDC_LMT_CYL), BM_SETCHECK, false, 0); break; } } void SetType(LIGHT& light, HWND hDlg) { bool point=SendMessage(GetDlgItem(hDlg, IDC_LMT_POINT), BM_GETCHECK, 0, 0); bool cyl=SendMessage(GetDlgItem(hDlg, IDC_LMT_CYL), BM_GETCHECK, 0, 0); bool remote=SendMessage(GetDlgItem(hDlg, IDC_LMT_REMOTE), BM_GETCHECK, 0, 0); if(point) light.SetLightModelType(LMT_POINT); if(cyl) light.SetLightModelType(LMT_CYL); if(remote) light.SetLightModelType(LMT_REMOTE); } BOOL WINAPI LightParamsProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) { HWND hList; int CurSel; switch(msg) { case WM_INITDIALOG: hList=GetDlgItem(hDlg, IDC_LIGHTS); hLightParams=hDlg; RECT rct; GetWindowRect(hList, &rct); MoveWindow(hList, 10, 40, rct.right-rct.left, 200, true); SendMessage(hList, CB_RESETCONTENT, 0, 0); SendMessage(hList, CB_ADDSTRING, 0, (LPARAM)"Источник 1"); SendMessage(hList, CB_ADDSTRING, 0, (LPARAM)"Источник 2"); SendMessage(hList, CB_ADDSTRING, 0, (LPARAM)"Источник 3"); SendMessage(hList, CB_ADDSTRING, 0, (LPARAM)"Источник 4"); SendMessage(hList, CB_SETCURSEL, 0, 0); SendMessage(GetDlgItem(hDlg, IDC_LIGHT_ON), BM_SETCHECK, lights[0].Shining(), 0); FillPos(lights[0], GetDlgItem(hDlg, IDC_LIGHT_POSX), GetDlgItem(hDlg, IDC_LIGHT_POSY), GetDlgItem(hDlg, IDC_LIGHT_POSZ)); FillColor(lights[0], GetDlgItem(hDlg, IDC_LIGHT_COLORR), GetDlgItem(hDlg, IDC_LIGHT_COLORG), GetDlgItem(hDlg, IDC_LIGHT_COLORB)); GetType(lights[0].settings.lightmodeltype, hDlg); break; case WM_COMMAND: CurSel=SendMessage(GetDlgItem(hDlg, IDC_LIGHTS), CB_GETCURSEL, 0, 0); if(LOWORD(wParam)==IDC_LIGHT_COLOR_GET) SetLightColor(lights[CurSel], GetDlgItem(hDlg, IDC_LIGHT_COLORR), GetDlgItem(hDlg, IDC_LIGHT_COLORG), GetDlgItem(hDlg, IDC_LIGHT_COLORB)); if(LOWORD(wParam)==IDC_LIGHT_ON) { if(SendMessage(GetDlgItem(hDlg, IDC_LIGHT_ON), BM_GETCHECK, 0, 0)) lights[CurSel].TurnOn(); else lights[CurSel].TurnOff(); HMENU hMenu=GetMenu(hWndMain); CheckMenuItem(hMenu, CurSel+IDC_LIGHT0, MF_BYCOMMAND|(lights[CurSel].Shining())? MF_CHECKED:MF_UNCHECKED); } if(LOWORD(wParam)==IDC_LMT_POINT || LOWORD(wParam)==IDC_LMT_CYL || LOWORD(wParam)==IDC_LMT_REMOTE) SetType(lights[CurSel], hDlg); if(LOWORD(wParam)==IDC_LIGHTS && HIWORD(wParam)==CBN_SELCHANGE) { SendMessage(GetDlgItem(hDlg, IDC_LIGHT_ON), BM_SETCHECK, lights[CurSel].Shining(), 0); FillPos(lights[CurSel], GetDlgItem(hDlg, IDC_LIGHT_POSX), GetDlgItem(hDlg, IDC_LIGHT_POSY), GetDlgItem(hDlg, IDC_LIGHT_POSZ)); FillColor(lights[CurSel], GetDlgItem(hDlg, IDC_LIGHT_COLORR), GetDlgItem(hDlg, IDC_LIGHT_COLORG), GetDlgItem(hDlg, IDC_LIGHT_COLORB)); GetType(lights[CurSel].settings.lightmodeltype, hDlg); } if( (LOWORD(wParam)==IDC_LIGHT_POSX || LOWORD(wParam)==IDC_LIGHT_POSY || LOWORD(wParam)==IDC_LIGHT_POSZ ) && HIWORD(wParam)==EN_CHANGE ) SetLightPos(lights[CurSel], GetDlgItem(hDlg, IDC_LIGHT_POSX), GetDlgItem(hDlg, IDC_LIGHT_POSY), GetDlgItem(hDlg, IDC_LIGHT_POSZ)); break; } return 0; } #endif _____________panel_premetives_______ #ifndef PRIMITIVES_ #define PRIMITIVES_ #include #include "tip_wnd.h" void GetColor(int obj, HWND hDlg) { OBJECT3D *pobj; switch(obj) { case PR_SPHERE: pobj=&sp; break; case PR_HALFSPHERE: pobj=&hsp; break; case PR_IKO: pobj=&cube; break; case PR_PRISM3: pobj=&prism3; break; case PR_ELIPS: pobj=⪙ break; case PR_CYL: pobj=&cyl; break; case PR_PIRAMID3: pobj=&pir3; break; case PR_KOSPR: pobj=&kospr[0]; break; } char s[10]; sprintf(s, "%.0f", pobj->settings.r*255); SetDlgItemText( hDlg, IDC_OBJ_COLORR, s); sprintf(s, "%.0f", pobj->settings.g*255); SetDlgItemText( hDlg, IDC_OBJ_COLORG, s); sprintf(s, "%.0f", pobj->settings.b*255); SetDlgItemText( hDlg, IDC_OBJ_COLORB, s); } void GetMaterial(int mat, HWND hDlg) { SendMessage(GetDlgItem(hDlg, IDC_OBJ_MATERIAL), CB_SETCURSEL, (mat==GL_DIFFUSE)?0:1, 0); } void SetPrimitiveColor(int obj, HWND hR, HWND hG, HWND hB) { CHOOSECOLOR cc; memset(&cc, 0, sizeof(cc)); cc.lStructSize=sizeof(CHOOSECOLOR); COLORREF cust[16]={0}; cc.Flags=CC_SOLIDCOLOR; cc.hwndOwner=hWndMain; cc.lpCustColors=cust; if(!ChooseColor(&cc)) return; int i; OBJECT3D *pobj=NULL; switch(obj) { case PR_SPHERE: pobj=&sp; break; case PR_HALFSPHERE: pobj=&hsp; break; case PR_IKO: pobj=&cube; break; case PR_PRISM3: pobj=&prism3; break; case PR_ELIPS: pobj=⪙ break; case PR_CYL: pobj=&cyl; break; case PR_PIRAMID3: pobj=&pir3; break; case PR_KOSPR: for(i=0; i<2; i++) { kospr[i].settings.r=GetRValue(cc.rgbResult)/255.f; kospr[i].settings.g=GetGValue(cc.rgbResult)/255.f; kospr[i].settings.b=GetBValue(cc.rgbResult)/255.f; char s[10]; sprintf(s, "%i", GetRValue(cc.rgbResult)); SetWindowText(hR, s); sprintf(s, "%i", GetGValue(cc.rgbResult)); SetWindowText(hG, s); sprintf(s, "%i", GetBValue(cc.rgbResult)); SetWindowText(hB, s); } return; break; } if(pobj) { pobj->settings.r=GetRValue(cc.rgbResult)/255.f; pobj->settings.g=GetGValue(cc.rgbResult)/255.f; pobj->settings.b=GetBValue(cc.rgbResult)/255.f; char s[10]; sprintf(s, "%i", GetRValue(cc.rgbResult)); SetWindowText(hR, s); sprintf(s, "%i", GetGValue(cc.rgbResult)); SetWindowText(hG, s); sprintf(s, "%i", GetBValue(cc.rgbResult)); SetWindowText(hB, s); } } void SetPrimitiveMaterial(int obj, int material) { ObjMat=-1; int i; OBJECT3D *pobj=NULL; switch(obj) { case PR_SPHERE: pobj=&sp; break; case PR_HALFSPHERE: pobj=&hsp; break; case PR_IKO: pobj=&cube; break; case PR_PRISM3: pobj=&prism3; break; case PR_ELIPS: pobj=⪙ break; case PR_CYL: pobj=&cyl; break; case PR_PIRAMID3: pobj=&pir3; break; case PR_KOSPR: for(i=0; i<2; i++) { kospr[i].SetMaterial(material); kospr[i].SetMaterial(material); kospr[i].SetMaterial(material); } return; break; } if(pobj) pobj->SetMaterial(material); } void SetModelType(int obj, HWND hSolid) { ObjModel=-1; int i; OBJECT3D *pobj=NULL; bool bSolid=(SendMessage(hSolid, BM_GETCHECK, 0, 0)==BST_CHECKED); switch(obj) { case PR_SPHERE: pobj=&sp; break; case PR_HALFSPHERE: pobj=&hsp; break; case PR_IKO: pobj=&cube; break; case PR_PRISM3: pobj=&prism3; break; case PR_ELIPS: pobj=⪙ break; case PR_CYL: pobj=&cyl; break; case PR_PIRAMID3: pobj=&pir3; break; case PR_KOSPR: for(i=0; i<2; i++) { kospr[i].settings.model=bSolid?GL_FILL:GL_LINE; } return; break; } if(pobj) pobj->settings.model=bSolid?GL_FILL:GL_LINE;; CheckItem(GetMenu(hWndMain), obj, PARAM_MODEL, bSolid?MODEL_SOLID:MODEL_WIRE, false); } void GetPartitions(int obj, HWND hWParts, HWND hHParts) { char szWParts[21], szHParts[21]; OBJECT3D *pobj=NULL; switch(obj) { case PR_SPHERE: pobj=&sp; EnableWindow(hWParts, pobj->settings.visible); EnableWindow(hHParts, pobj->settings.visible); break; case PR_HALFSPHERE: pobj=&hsp; EnableWindow(hWParts, pobj->settings.visible); EnableWindow(hHParts, pobj->settings.visible); break; case PR_IKO: pobj=&cube; EnableWindow(hWParts, false); EnableWindow(hHParts, false); break; case PR_PRISM3: pobj=&prism3; EnableWindow(hWParts, false); EnableWindow(hHParts, false); break; case PR_ELIPS: pobj=⪙ EnableWindow(hWParts, pobj->settings.visible); EnableWindow(hHParts, pobj->settings.visible); break; case PR_CYL: pobj=&cyl; EnableWindow(hWParts, false/*pobj->settings.visible*/); EnableWindow(hHParts, false); break; case PR_PIRAMID3: pobj=&pir3; EnableWindow(hWParts, false); EnableWindow(hHParts, false); break; case PR_KOSPR: pobj=&kospr[0]; EnableWindow(hWParts, false); EnableWindow(hHParts, false); break; } sprintf(szHParts, "%u", pobj->settings.n); sprintf(szWParts, "%u", pobj->settings.m); SetWindowText(hWParts, szWParts); SetWindowText(hHParts, szHParts); } void SetModelRadio(int obj, HWND hSolid, HWND hWire) { bool bSolid=false; switch(obj) { case PR_SPHERE: bSolid=(sp.settings.model==GL_FILL); break; case PR_HALFSPHERE: bSolid=hsp.settings.model==GL_FILL; break; case PR_IKO: bSolid=cube.settings.model==GL_FILL; break; case PR_PRISM3: bSolid=(prism3.settings.model==GL_FILL); break; case PR_ELIPS: bSolid=el.settings.model==GL_FILL; break; case PR_CYL: bSolid=cyl.settings.model==GL_FILL; break; case PR_PIRAMID3: bSolid=pir3.settings.model==GL_FILL; break; case PR_KOSPR: bSolid=kospr[0].settings.model==GL_FILL; break; } SendMessage(hSolid, BM_SETCHECK, bSolid, 0); SendMessage(hWire, BM_SETCHECK, !bSolid, 0); } void FillObjectsList(HWND hList) { RECT rct; GetWindowRect(hList, &rct); MoveWindow(hList, 10, 40, rct.right-rct.left, 200, true); SendMessage(hList, CB_RESETCONTENT, 0, 0); if(sp.settings.visible) SendMessage(hList, CB_ADDSTRING, 0, (LPARAM)"+Сфера"); else SendMessage(hList, CB_ADDSTRING, 0, (LPARAM)"Сфера"); if(hsp.settings.visible) SendMessage(hList, CB_ADDSTRING, 0, (LPARAM)"+Полуcфера"); else SendMessage(hList, CB_ADDSTRING, 0, (LPARAM)"Полуcфера"); if(cube.settings.visible) SendMessage(hList, CB_ADDSTRING, 0, (LPARAM)"+Икосаэдр"); else SendMessage(hList, CB_ADDSTRING, 0, (LPARAM)"Икосаэдр"); if(prism3.settings.visible) SendMessage(hList, CB_ADDSTRING, 0, (LPARAM)"+3-уг призма"); else SendMessage(hList, CB_ADDSTRING, 0, (LPARAM)"3-уг призма"); if(el.settings.visible) SendMessage(hList, CB_ADDSTRING, 0, (LPARAM)"+Эллипсоид"); else SendMessage(hList, CB_ADDSTRING, 0, (LPARAM)"Эллипсоид"); if(cyl.settings.visible) SendMessage(hList, CB_ADDSTRING, 0, (LPARAM)"+Косоугольный цилиндр"); else SendMessage(hList, CB_ADDSTRING, 0, (LPARAM)"Косоугольный цилиндр"); if(pir3.settings.visible) SendMessage(hList, CB_ADDSTRING, 0, (LPARAM)"+Усечённая пирамида с 3-уг. осн."); else SendMessage(hList, CB_ADDSTRING, 0, (LPARAM)"Усечённая пирамида с 3-уг. осн."); if(kospr->settings.visible) SendMessage(hList, CB_ADDSTRING, 0, (LPARAM)"+Кос. призма с 3-уг. осн."); else SendMessage(hList, CB_ADDSTRING, 0, (LPARAM)"Кос. призма с 3-уг. осн."); SendMessage(hList, CB_SETCURSEL, 0, 0); } void SetWParts(int obj, HWND hWParts, HWND hHParts) { OBJECT3D *pobj=NULL; switch(obj) { case PR_SPHERE: pobj=&sp; break; case PR_HALFSPHERE: pobj=&hsp; break; case PR_CYL: pobj=&cyl; break; case PR_ELIPS: pobj=⪙ break; } if(pobj) { char s[21]; GetWindowText(hWParts, s, 20); pobj->settings.m=atoi(s); } else return; } void SetHParts(int obj, HWND hHParts) { OBJECT3D *pobj=NULL; switch(obj) { case PR_SPHERE: pobj=&sp; break; case PR_HALFSPHERE: pobj=&hsp; break; case PR_CYL: pobj=&cyl; break; case PR_ELIPS: pobj=⪙ break; } if(pobj) { char s[21]; GetWindowText(hHParts, s, 20); pobj->settings.n=atoi(s); } } void EnablePrimitiveAttrs(int obj, bool enable, HWND hDlg) { EnableWindow(GetDlgItem(hDlg, IDC_OBJ_DEL), enable); EnableWindow(GetDlgItem(hDlg, IDC_OBJ_ADD), !enable); EnableWindow(GetDlgItem(hDlg, IDC_OBJ_FIND), enable); OBJECT3D *pobj=NULL; HWND hWParts=GetDlgItem(hDlg, IDC_WPARTS); HWND hHParts=GetDlgItem(hDlg, IDC_HPARTS); EnableWindow(GetDlgItem(hDlg, IDC_SETPRIMCOLOR), enable); EnableWindow(GetDlgItem(hDlg, IDC_SOLID), enable); EnableWindow(GetDlgItem(hDlg, IDC_WIRE), enable); EnableWindow(GetDlgItem(hDlg, IDC_OBJ_MATERIAL), enable); switch(obj) { case PR_SPHERE: pobj=&sp; EnableWindow(hWParts, enable); EnableWindow(hHParts, enable); break; case PR_HALFSPHERE: pobj=&hsp; EnableWindow(hWParts, enable); EnableWindow(hHParts, enable); break; case PR_IKO: pobj=&cube; EnableWindow(hWParts, false); EnableWindow(hHParts, false); break; case PR_PRISM3: pobj=&prism3; EnableWindow(hWParts, false); EnableWindow(hHParts, false); break; case PR_ELIPS: pobj=⪙ EnableWindow(hWParts, enable); EnableWindow(hHParts, enable); break; case PR_CYL: pobj=&cyl; EnableWindow(hWParts, false/*enable*/); EnableWindow(hHParts, false); break; case PR_PIRAMID3: pobj=&pir3; EnableWindow(hWParts, false); EnableWindow(hHParts, false); break; case PR_KOSPR: pobj=&kospr[0]; EnableWindow(hWParts, false); EnableWindow(hHParts, false); break; } } void AddPrimitive(int obj, HWND hDlg) { OBJECT3D *pobj; int i; switch(obj) { case PR_SPHERE: pobj=&sp; break; case PR_HALFSPHERE: pobj=&hsp; break; case PR_IKO: pobj=&cube; break; case PR_PRISM3: pobj=&prism3; break; case PR_ELIPS: pobj=⪙ break; case PR_CYL: pobj=&cyl; break; case PR_PIRAMID3: pobj=&pir3; break; case PR_KOSPR: for(i=0; i<2; i++) kospr[i].settings.visible=true; EnablePrimitiveAttrs(obj, true, hDlg); return; break; } if(pobj) pobj->settings.visible=true; EnablePrimitiveAttrs(obj, true, hDlg); } void DelPrimitive(int obj, HWND hDlg) { OBJECT3D *pobj; int i; switch(obj) { case PR_SPHERE: pobj=&sp; break; case PR_HALFSPHERE: pobj=&hsp; break; case PR_IKO: |