Курсовой проект 106 страниц, 42 рисунка, 2 таблицы, 18 фомул, 15 матриц, 4 приложения
Скачать 5.65 Mb.
|
{ if(obj==PR_KOSPR) { for(int i=0; i<2; i++) kospr[i].SetMaterial((value==MAT_DIFF)?GL_DIFFUSE:GL_SPECULAR); return; } if(obj==PR_PRISM3) { prism3.SetMaterial((value==MAT_DIFF)?GL_DIFFUSE:GL_SPECULAR); } ObjectsNotAll[obj]->SetMaterial((value==MAT_DIFF)?GL_DIFFUSE:GL_SPECULAR); if(IsWindow(hPrimParams)) { int cs=SendMessage(GetDlgItem(hPrimParams, IDC_OBJECTS_LIST), CB_GETCURSEL, 0, 0); if(cs==obj) { if(param==PARAM_MAT) SendMessage(GetDlgItem(hPrimParams, IDC_OBJ_MATERIAL), CB_SETCURSEL, (value==MAT_SPEC)?1:0, 0); } } } if(param==PARAM_MODEL) { if(obj==PR_PRISM3) { prism3.settings.model=(value==MODEL_SOLID)?GL_FILL:GL_LINE; } if(obj==PR_KOSPR) { for(int i=0; i<2; i++) kospr[i].settings.model=(value==MODEL_SOLID)?GL_FILL:GL_LINE; return; } ObjectsNotAll[obj]->settings.model=(value==MODEL_SOLID)?GL_FILL:GL_LINE; if(IsWindow(hPrimParams)) { int cs=SendMessage(GetDlgItem(hPrimParams, IDC_OBJECTS_LIST), CB_GETCURSEL, 0, 0); if(cs==obj) SetModelRadio(obj, GetDlgItem(hPrimParams, IDC_SOLID), GetDlgItem(hPrimParams, IDC_WIRE)); } } } #endif _____________panel_______________ #include "resource.h" #include "drawscene.h" #include "primitives.h" #include "panel_primitives.h" #include "panel_camera.h" #include "panel_light.h" #include "panel_scene.h" #include "panel_aff_aj.h" #include #include HWND hPage; LRESULT CALLBACK PanelWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { LPNMHDR nm; switch(msg) { case WM_NOTIFY: nm=(LPNMHDR)lParam; switch(nm->code) { case TCN_SELCHANGE: if(IsWindow(hPage)) DestroyWindow(hPage); if(TabCtrl_GetCurSel(nm->hwndFrom)==4) hPage=CreateDialog(hInst, MAKEINTRESOURCE(IDD_AFF_AJ), nm->hwndFrom, AffajParamsProc); if(TabCtrl_GetCurSel(nm->hwndFrom)==3) hPage=CreateDialog(hInst, MAKEINTRESOURCE(IDD_SCENE_PARAMS), nm->hwndFrom, SceneParamsProc); if(TabCtrl_GetCurSel(nm->hwndFrom)==2) hPage=CreateDialog(hInst, MAKEINTRESOURCE(IDD_PRIMITIVES_PARAMS), nm->hwndFrom, ParamsProc); if(TabCtrl_GetCurSel(nm->hwndFrom)==1) hPage=CreateDialog(hInst, MAKEINTRESOURCE(IDD_CAMERA_PARAMS), nm->hwndFrom, CameraParamsProc); if(TabCtrl_GetCurSel(nm->hwndFrom)==0) hPage=CreateDialog(hInst, MAKEINTRESOURCE(IDD_LIGHTS_PARAMS), nm->hwndFrom, LightParamsProc); break; } break; } return DefWindowProc(hWnd, msg, wParam, lParam); } void InitPanel(HINSTANCE hInstance) { WNDCLASS wcl; memset(&wcl, 0, sizeof(wcl)); wcl.hbrBackground=(HBRUSH)COLOR_BTNSHADOW; wcl.hIcon=LoadIcon(NULL, IDI_APPLICATION); wcl.hCursor=LoadCursor(NULL, IDC_ARROW); wcl.hInstance=hInstance; wcl.lpszClassName="panel"; wcl.lpfnWndProc=PanelWndProc; wcl.lpszMenuName=NULL; hInst=hInstance; RegisterClass(&wcl); RECT rct; GetClientRect(hWndMain, &rct); HWND hWndPanel=CreateWindow( "panel", "", WS_VISIBLE|WS_CHILD, rct.right-200, 0, 200, 800, hWndMain, 0, hInstance, 0 ); HWND hTabCtl=CreateWindow(WC_TABCONTROL, "", TCS_HOTTRACK|WS_VISIBLE|TCS_TABS|TCS_MULTILINE|WS_CHILD, 0, 0, 200, 600, hWndPanel, (HMENU)1, hInstance, 0); TC_ITEM ti; ti.pszText="Свет"; ti.cchTextMax=100; ti.mask=TCIF_TEXT; SendMessage(hTabCtl, TCM_INSERTITEM, 0, (LPARAM)&ti); ti.pszText="Камера"; SendMessage(hTabCtl, TCM_INSERTITEM, 1, (LPARAM)&ti); ti.pszText="Прим-вы"; SendMessage(hTabCtl, TCM_INSERTITEM, 2, (LPARAM)&ti); ti.pszText="Сцена"; SendMessage(hTabCtl, TCM_INSERTITEM, 3, (LPARAM)&ti); ti.pszText="Афф. преобразования"; SendMessage(hTabCtl, TCM_INSERTITEM, 4, (LPARAM)&ti); hPage=CreateDialog(hInst, MAKEINTRESOURCE(IDD_PRIMITIVES_PARAMS), hTabCtl, ParamsProc); TabCtrl_SetCurSel(hTabCtl, 2); } ______________panel_aff_aj__________ #ifndef AFFAJ_ #define AFFAJ_ #include "globals.h" #include "tip_wnd.h" float PrevAjustment[16]; void HideRadioButtons(HWND hDlg, bool hide=true) { ShowWindow(GetDlgItem(hDlg, IDC_PAR1_NAME), hide?SW_SHOW:SW_HIDE); ShowWindow(GetDlgItem(hDlg, IDC_PAR2_NAME), hide?SW_SHOW:SW_HIDE); ShowWindow(GetDlgItem(hDlg, IDC_PAR3_NAME), hide?SW_SHOW:SW_HIDE); ShowWindow(GetDlgItem(hDlg, IDC_PAR1), hide?SW_SHOW:SW_HIDE); ShowWindow(GetDlgItem(hDlg, IDC_PAR2), hide?SW_SHOW:SW_HIDE); ShowWindow(GetDlgItem(hDlg, IDC_PAR3), hide?SW_SHOW:SW_HIDE); ShowWindow(GetDlgItem(hDlg, IDC_REFL_OXZ), hide?SW_HIDE:SW_SHOW); ShowWindow(GetDlgItem(hDlg, IDC_REFL_OYZ), hide?SW_HIDE:SW_SHOW); ShowWindow(GetDlgItem(hDlg, IDC_REFL_OXY), hide?SW_HIDE:SW_SHOW); ShowWindow(GetDlgItem(hDlg, IDC_REFL_O), hide?SW_HIDE:SW_SHOW); if(!hide) { SendMessage(GetDlgItem(hDlg, IDC_REFL_OXZ), BM_SETCHECK, true, 0); SendMessage(GetDlgItem(hDlg, IDC_REFL_OYZ), BM_SETCHECK, false, 0); SendMessage(GetDlgItem(hDlg, IDC_REFL_OXY), BM_SETCHECK, false, 0); SendMessage(GetDlgItem(hDlg, IDC_REFL_O), BM_SETCHECK, false, 0); } } void BeforeScaling(HWND hDlg) { SetDlgItemText(hDlg, IDC_PAR1_NAME, "Вдоль OX:"); SetDlgItemText(hDlg, IDC_PAR2_NAME, "Вдоль OY:"); SetDlgItemText(hDlg, IDC_PAR3_NAME, "Вдоль OZ:"); SetDlgItemText(hDlg, IDC_PAR1, "1"); SetDlgItemText(hDlg, IDC_PAR2, "1"); SetDlgItemText(hDlg, IDC_PAR3, "1"); } void BeforeTranslate(HWND hDlg) { SetDlgItemText(hDlg, IDC_PAR1_NAME, "Вдоль OX:"); SetDlgItemText(hDlg, IDC_PAR2_NAME, "Вдоль OY:"); SetDlgItemText(hDlg, IDC_PAR3_NAME, "Вдоль OZ:"); SetDlgItemText(hDlg, IDC_PAR1, "0"); SetDlgItemText(hDlg, IDC_PAR2, "0"); SetDlgItemText(hDlg, IDC_PAR3, "0"); HideRadioButtons(hDlg, true); } void BeforeRotation(HWND hDlg) { SetDlgItemText(hDlg, IDC_PAR1_NAME, "Вокруг OX:"); SetDlgItemText(hDlg, IDC_PAR2_NAME, "Вокруг OY:"); SetDlgItemText(hDlg, IDC_PAR3_NAME, "Вокруг OZ:"); SetDlgItemText(hDlg, IDC_PAR1, "0"); SetDlgItemText(hDlg, IDC_PAR2, "0"); SetDlgItemText(hDlg, IDC_PAR3, "0"); HideRadioButtons(hDlg, true);} void BeforeReflection(HWND hDlg) { ShowWindow(GetDlgItem(hDlg, IDC_PAR1_NAME), SW_HIDE); ShowWindow(GetDlgItem(hDlg, IDC_PAR2_NAME), SW_HIDE); ShowWindow(GetDlgItem(hDlg, IDC_PAR3_NAME), SW_HIDE); SetDlgItemText(hDlg, IDC_PAR1, "1"); SetDlgItemText(hDlg, IDC_PAR2, "1"); SetDlgItemText(hDlg, IDC_PAR3, "1"); HideRadioButtons(hDlg, false); } void DoAjustment(int aj, HWND hDlg) { char sx[20], sy[20], sz[20]; float x, y, z; float tmp[16]; glMatrixMode(GL_MODELVIEW); float sm[4][4]={0}; bool oxz=false, oxy=false, oyz=false, o=false; switch(aj) { case 0: GetDlgItemText(hDlg, IDC_PAR1, sx, 19); GetDlgItemText(hDlg, IDC_PAR2, sy, 19); GetDlgItemText(hDlg, IDC_PAR3, sz, 19); if(!strlen(sx)) x=0.; else x=atof(sx); if(!strlen(sy)) y=0.; else y=atof(sy); if(!strlen(sz)) z=0.; else z=atof(sz); glTranslatef(x, y, z); break; case 1: GetDlgItemText(hDlg, IDC_PAR1, sx, 19); GetDlgItemText(hDlg, IDC_PAR2, sy, 19); GetDlgItemText(hDlg, IDC_PAR3, sz, 19); if(!strlen(sx)) x=0.; else x=atof(sx); if(!strlen(sy)) y=0.; else y=atof(sy); if(!strlen(sz)) z=0.; else z=atof(sz); glScalef(x, y, z); break; case 2: GetDlgItemText(hDlg, IDC_PAR1, sx, 19); GetDlgItemText(hDlg, IDC_PAR2, sy, 19); GetDlgItemText(hDlg, IDC_PAR3, sz, 19); if(!strlen(sx)) x=0.; else x=atof(sx); if(!strlen(sy)) y=0.; else y=atof(sy); if(!strlen(sz)) z=0.; else z=atof(sz); sm[0][0]=1; sm[0][1]=x; sm[0][2]=x; sm[1][0]=y; sm[1][1]=1; sm[1][2]=y; sm[2][0]=z; sm[2][1]=z; sm[2][2]=1; sm[3][3]=1; glMultMatrixf((float*)sm); break; case 3: GetDlgItemText(hDlg, IDC_PAR1, sx, 19); GetDlgItemText(hDlg, IDC_PAR2, sy, 19); GetDlgItemText(hDlg, IDC_PAR3, sz, 19); if(!strlen(sx)) x=0.; else x=atof(sx); if(!strlen(sy)) y=0.; else y=atof(sy); if(!strlen(sz)) z=0.; else z=atof(sz); glMatrixMode(GL_MODELVIEW); glGetFloatv(GL_MODELVIEW_MATRIX, (float*)tmp); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); glRotatef(x, 1, 0, 0); glRotatef(y, 0, 1, 0); glRotatef(z, 0, 0, 1); glMultMatrixf((float*)tmp); break; case 4: oxz=SendMessage(GetDlgItem(hDlg, IDC_REFL_OXZ), BM_GETCHECK, 0, 0); oyz=SendMessage(GetDlgItem(hDlg, IDC_REFL_OYZ), BM_GETCHECK, 0, 0); oxy=SendMessage(GetDlgItem(hDlg, IDC_REFL_OXY), BM_GETCHECK, 0, 0); o=SendMessage(GetDlgItem(hDlg, IDC_REFL_O), BM_GETCHECK, 0, 0); memset(sm, 0, sizeof(sm)); sm[0][0]=(oyz || o)?-1:1; sm[1][1]=(oxz || o)?-1:1; sm[2][2]=(oxy || o)?-1:1; sm[3][3]=1; glMatrixMode(GL_MODELVIEW); glGetFloatv(GL_MODELVIEW_MATRIX, (float*)tmp); glLoadMatrixf((float*)sm); glMultMatrixf((float*)tmp); break; } } BOOL WINAPI AffajParamsProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) { int CurSel; POINT pt; switch(msg) { case WM_INITDIALOG: SendMessage(GetDlgItem(hDlg, IDC_AJ_NAME), CB_RESETCONTENT, 0, 0); SendMessage(GetDlgItem(hDlg, IDC_AJ_NAME), CB_ADDSTRING, 0, (LPARAM)"Перенос"); SendMessage(GetDlgItem(hDlg, IDC_AJ_NAME), CB_ADDSTRING, 0, (LPARAM)"Масштабирование"); SendMessage(GetDlgItem(hDlg, IDC_AJ_NAME), CB_ADDSTRING, 0, (LPARAM)"Сдвиг"); SendMessage(GetDlgItem(hDlg, IDC_AJ_NAME), CB_ADDSTRING, 0, (LPARAM)"Вращение"); SendMessage(GetDlgItem(hDlg, IDC_AJ_NAME), CB_ADDSTRING, 0, (LPARAM)"Отражение"); SendMessage(GetDlgItem(hDlg, IDC_AJ_NAME), CB_SETCURSEL, 0, 0); EnableWindow(GetDlgItem(hDlg, IDC_AJ_RESET_PREV), ajusted && !JustLoaded); EnableWindow(GetDlgItem(hDlg, IDC_AJ_RESET), ajusted); BeforeTranslate(hDlg); hAffAjWnd=hDlg; break; case WM_COMMAND: if(LOWORD(wParam)==IDC_AF_AJ_HELP) { GetCursorPos(&pt); CurSel=SendMessage(GetDlgItem(hDlg, IDC_AJ_NAME), CB_GETCURSEL, 0, 0); LoadHelpText(HelpFiles[CurSel+HLP_AFF_AJ], helpText, 1500); TIPWND::ShowHelp(pt.x, pt.y, HelpCaptions[CurSel+HLP_AFF_AJ], helpText); } if(LOWORD(wParam)==IDC_AJ_RESET) { glMatrixMode(GL_MODELVIEW); glLoadIdentity(); EnableWindow(GetDlgItem(hDlg, IDC_AJ_RESET), false); EnableWindow(GetDlgItem(hDlg, IDC_AJ_RESET_PREV), false); } if(LOWORD(wParam)==IDC_AJ_RESET_PREV) { glMatrixMode(GL_MODELVIEW); glLoadMatrixf(PrevAjustment); ajusted=false; EnableWindow(GetDlgItem(hDlg, IDC_AJ_RESET_PREV), false); } if(LOWORD(wParam)==IDC_AJ_DO) { CurSel=SendMessage(GetDlgItem(hDlg, IDC_AJ_NAME), CB_GETCURSEL, 0, 0); glGetFloatv(GL_MODELVIEW_MATRIX, PrevAjustment); DoAjustment(CurSel, hDlg); ajusted=true; JustLoaded=false; EnableWindow(GetDlgItem(hDlg, IDC_AJ_RESET_PREV), ajusted); EnableWindow(GetDlgItem(hDlg, IDC_AJ_RESET), ajusted); } if(LOWORD(wParam)==IDC_AJ_NAME && HIWORD(wParam)==CBN_SELCHANGE) { CurSel=SendMessage((HWND)lParam, CB_GETCURSEL, 0, 0); if(CurSel==0 || CurSel==2) BeforeTranslate(hDlg); if(CurSel==1 ) BeforeScaling(hDlg); if(CurSel==3) BeforeRotation(hDlg); if(CurSel==4) BeforeReflection(hDlg); } break; } return 0; } #endif _______panel camera_________ #ifndef CAMERAPANEL_ #define CAMERAPANEL_ #include "globals.h" void UpdateCamPanel() { if(!IsWindow(hCamDlg)) return; char sx[20], sy[20], sz[20]; float x, y, z; camera.GetPosition(&x, &y, &z); float cp[]={x, y, z, 1}; float a=3.14*camera.settings.xrot/180. + (acos(1.f/sqrt(3))/3.14)*180; float b=3.14*camera.settings.zrot/180. + (acos(1.f/sqrt(3))/3.14)*180; float rotx[]= { 1, 0, 0, 0, 0, cos(a), sin(a), 0, 0, -sin(a), cos(a), 0, 0, 0, 0, 1 }; float roty[]= { cos(b), 0, -sin(b), 0, 0, 1, 0, 0, sin(b), 0, cos(b), 0, 0, 0, 0, 1 }; MultMatrix(cp, rotx); MultMatrix(cp, roty); x=cp[0]; y=cp[1]; z=cp[2]; sprintf(sx, "%.2f", x); sprintf(sy, "%.2f", y); sprintf(sz, "%.2f", z); SetDlgItemText(hCamDlg, IDC_CAM_POSX, sx); SetDlgItemText(hCamDlg, IDC_CAM_POSY, sy); SetDlgItemText(hCamDlg, IDC_CAM_POSZ, sz); camera.GetDirection(&x, &y, &z); sprintf(sx, "%.2f", x); sprintf(sy, "%.2f", y); sprintf(sz, "%.2f", z); SetDlgItemText(hCamDlg, IDC_CAM_DIRX, sx); SetDlgItemText(hCamDlg, IDC_CAM_DIRY, sy); SetDlgItemText(hCamDlg, IDC_CAM_DIRZ, sz); } BOOL WINAPI CameraParamsProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) { switch(msg) { char sx[20], sy[20], sz[20]; float x, y, z; case WM_INITDIALOG: hCamDlg=hDlg; UpdateCamPanel(); break; case WM_COMMAND: if(LOWORD(wParam)==IDC_CAM_SET) { GetDlgItemText(hDlg, IDC_CAM_POSX, sx, 19); GetDlgItemText(hDlg, IDC_CAM_POSY, sy, 19); GetDlgItemText(hDlg, IDC_CAM_POSZ, sz, 19); camera.Dispose(atof(sx), atof(sy), atof(sz)); GetDlgItemText(hDlg, IDC_CAM_DIRX, sx, 19); GetDlgItemText(hDlg, IDC_CAM_DIRY, sy, 19); GetDlgItemText(hDlg, IDC_CAM_DIRZ, sz, 19); camera.Direct(atof(sx), atof(sy), atof(sz)); } break; } return 0; } #endif _______panel_light___________________ #ifndef LIGHTPANEL_ #define LIGHTPANEL_ #include "globals.h" void SetLightColor(LIGHT& light, 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; light.SetColor(GetRValue(cc.rgbResult)/255.f, GetGValue(cc.rgbResult)/255.f, GetBValue(cc.rgbResult)/255.f); char sr[20], sg[20], sb[20]; sprintf(sr, "%i", GetRValue(cc.rgbResult)); sprintf(sg, "%i", GetGValue(cc.rgbResult)); sprintf(sb, "%i", GetBValue(cc.rgbResult)); SetWindowText(hR, sr); SetWindowText(hG, sg); SetWindowText(hB, sb); } void FillPos(LIGHT& light, HWND hX, HWND hY, HWND hZ) { char sx[20]; char sy[20]; char sz[20]; float x, y, z; light.GetPosition(&x, &y, &z); sprintf(sx, "%.2f", x); sprintf(sy, "%.2f", y); sprintf(sz, "%.2f", z); SetWindowText(hX, sx); SetWindowText(hY, sy); SetWindowText(hZ, sz); } void FillColor(LIGHT& light, HWND hR, HWND hG, HWND hB) { char sr[20]; char sg[20]; char sb[20]; float r, g, b; light.GetColor(&r, &g, &b); sprintf(sr, "%.0f", r*255); sprintf(sg, "%.0f", g*255); sprintf(sb, "%.0f", b*255); SetWindowText(hR, sr); SetWindowText(hG, sg); SetWindowText(hB, sb); } void SetLightPos(LIGHT& light, HWND hX, HWND hY, HWND hZ) { char sx[20], sy[20], sz[20]; GetWindowText(hX, sx, 19); GetWindowText(hY, sy, 19); GetWindowText(hZ, sz, 19); light.Dispose(atof(sx), atof(sy), atof(sz), light.settings.pos[3]); } void SetLightDir(LIGHT& light, HWND hX, HWND hY, HWND hZ) { char sx[20], sy[20], sz[20]; GetWindowText(hX, sx, 19); GetWindowText(hY, sy, 19); GetWindowText(hZ, sz, 19); light.Direct(atof(sx), atof(sy), atof(sz)); |