Главная страница

Курсовой проект 106 страниц, 42 рисунка, 2 таблицы, 18 фомул, 15 матриц, 4 приложения


Скачать 5.65 Mb.
НазваниеКурсовой проект 106 страниц, 42 рисунка, 2 таблицы, 18 фомул, 15 матриц, 4 приложения
АнкорKursach.doc
Дата17.08.2018
Размер5.65 Mb.
Формат файлаdoc
Имя файлаKursach.doc
ТипКурсовой проект
#23097
страница6 из 10
1   2   3   4   5   6   7   8   9   10


glLoadIdentity();

glTranslatef(settings.pos[0], settings.pos[1], settings.pos[2]);

glColor3f(settings.color[0], settings.color[1], settings.color[2]);

auxSolidSphere(1);

glPopMatrix();

glEnable(GL_LIGHTING);

}
GLenum GetIndex() {return index;}
bool Shining()

{

glGetBooleanv(index, &settings.shining);

return settings.shining;

}

LIGHT& TurnOn()

{

glEnable(index);

settings.shining=true;

return *this;

}
LIGHT& TurnOff()

{

glDisable(index);

settings.shining=false;

return *this;

}
LIGHT(int gllight):index(gllight)

{

index=gllight;

};

LIGHT(){glDisable(index);}
void SetLightModelType(int lmt)

{

switch(lmt)

{

case LMT_POINT:

Dispose(settings.pos[0], settings.pos[1], settings.pos[2], 0);

glLightf(index, GL_SPOT_CUTOFF, 180);

break;
case LMT_REMOTE:

Dispose(settings.pos[0], settings.pos[1], settings.pos[2], -1);

glLightf(index, GL_SPOT_CUTOFF, 180);

break;
case LMT_CYL:

Dispose(settings.pos[0], settings.pos[1], settings.pos[2], 1);

glLightf(index, GL_SPOT_CUTOFF, 85);

break;

}
settings.lightmodeltype=lmt;

}
void Dispose(float PosX, float PosY, float PosZ, float PosT)

{

settings.pos[0]=PosX;

settings.pos[1]=PosY;

settings.pos[2]=PosZ;

settings.pos[3]=PosT;
glLightfv(index, GL_POSITION, settings.pos);

}
LIGHT& Direct(float DirX, float DirY, float DirZ)

{

settings.dir[0]=DirX;

settings.dir[1]=DirY;

settings.dir[2]=DirZ;
glLightfv(index, GL_SPOT_DIRECTION, settings.pos);
return *this;

}
LIGHT& SetColor(float r, float g, float b)

{

settings.color[0]=r;

settings.color[1]=g;

settings.color[2]=b;

settings.color[3]=0;
glLightfv(index, GL_SPECULAR, settings.color);

glLightfv(index, GL_DIFFUSE, settings.color);

return *this;

}
void GetPosition(float *x, float *y, float *z)

{

if(x)

*x=settings.pos[0];

if(y)

*y=settings.pos[1];

if(z)

*z=settings.pos[2];

}


void GetDirection(float *x, float *y, float *z)

{

if(x)

*x=settings.dir[0];

if(y)

*y=settings.dir[1];

if(z)

*z=settings.dir[2];

}

void GetColor(float *r, float *g, float *b)

{

*r=settings.color[0];

*g=settings.color[1];

*b=settings.color[2];

}

};
#endif

________________mainwnd_____________
#ifndef MAINWND_

#define MAINWND_

#include

#include

#include "menu.h"
#define WM_MOUSEWHEEL 0x020A
float angx=0, angz=0;

float rho=20;

float fi, t;
#include "glsetup.h"

#include "resource.h"

#include "panel_camera.h"

#include "light.h"
int oldx, oldz;

bool pr=false;

char s[20];
bool rbfs=false;
void ObjMenuHandler(int cmd)

{

HMENU hMenu=GetMenu(hWndMain);

switch(cmd)

{

case ID_SP_COLOR:

SetPrimitiveColor(0, GetDlgItem(hPrimParams, IDC_OBJ_COLORR),

GetDlgItem(hPrimParams, IDC_OBJ_COLORR), GetDlgItem(hPrimParams, IDC_OBJ_COLORB));

break;
case ID_HSP_COLOR:

SetPrimitiveColor(1, GetDlgItem(hPrimParams, IDC_OBJ_COLORR),

GetDlgItem(hPrimParams, IDC_OBJ_COLORR), GetDlgItem(hPrimParams, IDC_OBJ_COLORB));
break;
case ID_CUBE_COLOR:

SetPrimitiveColor(PR_IKO, GetDlgItem(hPrimParams, IDC_OBJ_COLORR),

GetDlgItem(hPrimParams, IDC_OBJ_COLORR), GetDlgItem(hPrimParams, IDC_OBJ_COLORB));
break;


case ID_PRISM3_COLOR:

SetPrimitiveColor(3, GetDlgItem(hPrimParams, IDC_OBJ_COLORR),

GetDlgItem(hPrimParams, IDC_OBJ_COLORR), GetDlgItem(hPrimParams, IDC_OBJ_COLORB));
break;

case ID_ELIPS_COLOR:

SetPrimitiveColor(4, GetDlgItem(hPrimParams, IDC_OBJ_COLORR),

GetDlgItem(hPrimParams, IDC_OBJ_COLORR), GetDlgItem(hPrimParams, IDC_OBJ_COLORB));
break;
case ID_CYL_COLOR:

SetPrimitiveColor(5, GetDlgItem(hPrimParams, IDC_OBJ_COLORR),

GetDlgItem(hPrimParams, IDC_OBJ_COLORR), GetDlgItem(hPrimParams, IDC_OBJ_COLORB));
break;
case ID_KOSPR_COLOR:

SetPrimitiveColor(7, GetDlgItem(hPrimParams, IDC_OBJ_COLORR),

GetDlgItem(hPrimParams, IDC_OBJ_COLORR), GetDlgItem(hPrimParams, IDC_OBJ_COLORB));
break;
/////MODEL
case ID_SP_SOLID:

CheckItem(GetMenu(hWndMain), PR_SPHERE, PARAM_MODEL, MODEL_SOLID);

break;
case ID_SP_WIRE:

CheckItem(GetMenu(hWndMain), PR_SPHERE, PARAM_MODEL, MODEL_WIRE);

break;

case ID_HSP_SOLID:

CheckItem(GetMenu(hWndMain), PR_HALFSPHERE, PARAM_MODEL, MODEL_SOLID);

break;
case ID_HSP_WIRE:

CheckItem(GetMenu(hWndMain), PR_HALFSPHERE, PARAM_MODEL, MODEL_WIRE);

break;

case ID_CYL_SOLID:

CheckItem(GetMenu(hWndMain), PR_CYL, PARAM_MODEL, MODEL_SOLID);

break;
case ID_CYL_WIRE:

CheckItem(GetMenu(hWndMain), PR_CYL, PARAM_MODEL, MODEL_WIRE);

break;

case ID_CUBE_SOLID:

CheckItem(GetMenu(hWndMain), PR_IKO, PARAM_MODEL, MODEL_SOLID);

break;
case ID_CUBE_WIRE:

CheckItem(GetMenu(hWndMain), PR_IKO, PARAM_MODEL, MODEL_WIRE);

break;

case ID_PIR3_SOLID:

CheckItem(GetMenu(hWndMain), PR_PIRAMID3, PARAM_MODEL, MODEL_SOLID);

break;
case ID_PIR3_WIRE:

CheckItem(GetMenu(hWndMain), PR_PIRAMID3, PARAM_MODEL, MODEL_WIRE);

break;
case ID_ELIPS_SOLID:

CheckItem(GetMenu(hWndMain), PR_ELIPS, PARAM_MODEL, MODEL_SOLID);

break;
case ID_ELIPS_WIRE:

CheckItem(GetMenu(hWndMain), PR_ELIPS, PARAM_MODEL, MODEL_WIRE);

break;
case ID_KOSPR_SOLID:

CheckItem(GetMenu(hWndMain), PR_KOSPR, PARAM_MODEL, MODEL_SOLID);

break;
case ID_KOSPR_WIRE:

CheckItem(GetMenu(hWndMain), PR_KOSPR, PARAM_MODEL, MODEL_WIRE);

break;
case ID_PRISM3_SOLID:

CheckItem(GetMenu(hWndMain), PR_PRISM3, PARAM_MODEL, MODEL_SOLID);

break;
case ID_PRISM3_WIRE:

CheckItem(GetMenu(hWndMain), PR_PRISM3, PARAM_MODEL, MODEL_WIRE);

break;
////MATERIAL
case ID_SP_MAT_DIFF:

CheckItem(GetMenu(hWndMain), PR_SPHERE, PARAM_MAT, MAT_DIFF);

break;
case ID_SP_MAT_SPEC:

CheckItem(GetMenu(hWndMain), PR_SPHERE, PARAM_MAT, MAT_SPEC);

break;

case ID_HSP_MAT_DIFF:

CheckItem(GetMenu(hWndMain), PR_HALFSPHERE, PARAM_MAT, MAT_DIFF);

break;
case ID_HSP_MAT_SPEC:

CheckItem(GetMenu(hWndMain), PR_HALFSPHERE, PARAM_MAT, MAT_SPEC);

break;
case ID_CYL_MAT_DIFF:

CheckItem(GetMenu(hWndMain), PR_CYL, PARAM_MAT, MAT_DIFF);

break;
case ID_CYL_MAT_SPEC:

CheckItem(GetMenu(hWndMain), PR_CYL, PARAM_MAT, MAT_SPEC);

break;
case ID_CUBE_MAT_DIFF:

CheckItem(GetMenu(hWndMain), PR_IKO, PARAM_MAT, MAT_DIFF);

break;
case ID_CUBE_MAT_SPEC:

CheckItem(GetMenu(hWndMain), PR_IKO, PARAM_MAT, MAT_SPEC);

break;
case ID_PIR3_MAT_DIFF:

CheckItem(GetMenu(hWndMain), PR_PIRAMID3, PARAM_MAT, MAT_DIFF);

break;
case ID_PIR3_MAT_SPEC:

CheckItem(GetMenu(hWndMain), PR_PIRAMID3, PARAM_MAT, MAT_SPEC);

break;
case ID_ELIPS_MAT_DIFF:

CheckItem(GetMenu(hWndMain), PR_ELIPS, PARAM_MAT, MAT_DIFF);

break;
case ID_ELIPS_MAT_SPEC:

CheckItem(GetMenu(hWndMain), PR_ELIPS, PARAM_MAT, MAT_SPEC);

break;
case ID_KOSPR_MAT_DIFF:

CheckItem(GetMenu(hWndMain), PR_KOSPR, PARAM_MAT, MAT_DIFF);

break;
case ID_KOSPR_MAT_SPEC:

CheckItem(GetMenu(hWndMain), PR_KOSPR, PARAM_MAT, MAT_SPEC);

break;

case ID_PRISM3_MAT_DIFF:

CheckItem(GetMenu(hWndMain), PR_PRISM3, PARAM_MAT, MAT_DIFF);

break;
case ID_PRISM3_MAT_SPEC:

CheckItem(GetMenu(hWndMain), PR_PRISM3, PARAM_MAT, MAT_SPEC);

break;

}

}

LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)

{

switch(msg)

{

case WM_COMMAND:

if(LOWORD(wParam)==ID_ABOUT)

MessageBox(hWnd, TEXT("Данная программа является курсовым проектом")

TEXT(" по дисциплине\n \"Графическое геометрическое ")

TEXT("моделирование.\""), "О программе", MB_OK|MB_ICONINFORMATION);

if(LOWORD(wParam)==ID_CLEARSCENE)

{

for(int i=0; i<12; i++)

Objects[i]->settings.visible=false;

SendMessage(hPrimParams, WM_INITDIALOG, 0, 0);

}
if(LOWORD(wParam)==ID_AUTOR)

MessageBox(hWnd, "Курсовой проект выполнен студентом 3-го курса гр. ИС-08а Билыком Н.О.",

"Об авторе", MB_OK|MB_ICONINFORMATION);

if(LOWORD(wParam)==ID_SAVESCENE) SaveScene();

if(LOWORD(wParam)==ID_LOADSCENE) LoadScene();

if(LOWORD(wParam)>=IDC_LIGHT0 && LOWORD(wParam)<=IDC_LIGHT7)

{

int lightind=LOWORD(wParam)-IDC_LIGHT0;

if(lights[lightind].Shining())

lights[lightind].TurnOff();

else lights[lightind].TurnOn();

HMENU hMenu=GetMenu(hWnd);

CheckMenuItem(hMenu, LOWORD(wParam), MF_BYCOMMAND|(lights[lightind].Shining())?

MF_CHECKED:MF_UNCHECKED);

if(SendMessage(GetDlgItem(hLightParams, IDC_LIGHTS), CB_GETCURSEL, 0, 0)==lightind)

SendMessage(GetDlgItem(hLightParams, IDC_LIGHT_ON), BM_SETCHECK,

lights[lightind].Shining(), 0);

}
if(HIWORD(wParam)==0) ObjMenuHandler(LOWORD(wParam));

break;
case WM_DESTROY: PostQuitMessage(0);

break;
case WM_LBUTTONDOWN:

if(PtInViewport(LOWORD(lParam), HIWORD(lParam), VP_RIGHTBOTTOM) || FullScreenVP!=-1)

{

SetCapture(hWnd);

oldz=HIWORD(lParam);

oldx=LOWORD(lParam);

pr=true;

}

break;
case WM_LBUTTONUP: ReleaseCapture();

pr=false;

break;
case WM_MOUSEMOVE:

if(pr){

angx=(oldx-LOWORD(lParam))/10.f;

camera.SetZRot(camera.settings.zrot-angx);

camera.SetXRot(camera.settings.xrot+angz);

UpdateCamPanel();

camera.Direct(0, 0, 0);

}
break;
case WM_KEYDOWN:

if(LOWORD(wParam)==VK_ADD) rho--;

if(LOWORD(wParam)==VK_SUBTRACT) rho++;

break;
case WM_RBUTTONDBLCLK:

if(FullScreenVP!=-1) {FullScreenVP=-1; ShowSeparators(SW_SHOW); break;}

if(PtInViewport(LOWORD(lParam), HIWORD(lParam), VP_LEFTTOP))

{

FullScreenVP=VP_LEFTTOP;

ShowSeparators(SW_HIDE);

}
if(PtInViewport(LOWORD(lParam), HIWORD(lParam), VP_LEFTBOTTOM))

{

FullScreenVP=VP_LEFTBOTTOM;

ShowSeparators(SW_HIDE);

}

if(PtInViewport(LOWORD(lParam), HIWORD(lParam), VP_RIGHTTOP))

{

FullScreenVP=VP_RIGHTTOP;

ShowSeparators(SW_HIDE);

}

if(PtInViewport(LOWORD(lParam), HIWORD(lParam), VP_RIGHTBOTTOM))

{

FullScreenVP=VP_RIGHTBOTTOM;

ShowSeparators(SW_HIDE);

}

break;

}

return DefWindowProc(hWnd, msg, wParam, lParam);

}
void InitMainWindow(HINSTANCE hInstance, char *caption, int wdth)

{

WNDCLASS wcl;

memset(&wcl, 0, sizeof(wcl));
wcl.hbrBackground=(HBRUSH)COLOR_WINDOW;

wcl.hIcon=LoadIcon(NULL, IDI_APPLICATION);

wcl.hCursor=LoadCursor(NULL, IDC_ARROW);

wcl.hInstance=hInstance;

wcl.lpszClassName="main_wnd";

wcl.lpfnWndProc=WndProc;

wcl.lpszMenuName="menu";

wcl.style=CS_DBLCLKS;
RegisterClass(&wcl);
int height=2*GetSystemMetrics(SM_CYFIXEDFRAME)+GetSystemMetrics(SM_CYCAPTION)+GetSystemMetrics(SM_CYMENU)+wdth;

int width=2*GetSystemMetrics(SM_CXFIXEDFRAME)+wdth+200;

hWndMain=CreateWindow("main_wnd", caption, WS_MINIMIZEBOX|WS_CLIPCHILDREN|

WS_CLIPSIBLINGS|WS_POPUPWINDOW|WS_CAPTION|WS_SYSMENU, 0, 0, width, height, NULL, NULL, hInstance, NULL);
SetMenu(hHorSeparator=CreateWindow( "main_wnd", "", WS_VISIBLE|WS_CHILD,

0, wdth/2, 500, 3, hWndMain, NULL, hInstance, NULL), 0);
SetMenu(hVertSeparator=CreateWindow( "main_wnd", "", WS_VISIBLE|WS_CHILD,

wdth/2, 0, 3, 500, hWndMain, NULL, hInstance, NULL), 0);
int cxscr=GetSystemMetrics(SM_CXSCREEN);

int cyscr=GetSystemMetrics(SM_CYSCREEN);
MoveWindow( hWndMain, (cxscr-width)/2, (cyscr-height)/2, width, height, true);

ShowWindow(hWndMain, SW_SHOW);

UpdateWindow(hWndMain);
HMENU hMenu=GetMenu(hWndMain);

CheckMenuRadioItem( hMenu, ID_PRISM3_SOLID, ID_PRISM3_SOLID, ID_PRISM3_SOLID, MF_BYCOMMAND);

CheckMenuRadioItem(hMenu, ID_CYL_SOLID, ID_CYL_SOLID, ID_CYL_SOLID, MF_BYCOMMAND);
SetMenuItemBitmaps(hMenu, IDC_LIGHT0, 0, LoadBitmap(hInstance, "light_off"), LoadBitmap(hInstance, "light_on"));

SetMenuItemBitmaps(hMenu, IDC_LIGHT1, 0, LoadBitmap(hInstance, "light_off"), LoadBitmap(hInstance, "light_on"));

SetMenuItemBitmaps(hMenu, IDC_LIGHT2, 0, LoadBitmap(hInstance, "light_off"), LoadBitmap(hInstance, "light_on"));

SetMenuItemBitmaps(hMenu, IDC_LIGHT3, 0, LoadBitmap(hInstance, "light_off"), LoadBitmap(hInstance, "light_on"));
SetMenuItemBitmaps(hMenu, ID_LOADSCENE, 0,

LoadBitmap(hInstance, "open"), LoadBitmap(hInstance, "open"));
SetMenuItemBitmaps(hMenu, ID_SAVESCENE, 0,

LoadBitmap(hInstance, "save"), LoadBitmap(hInstance, "save"));
SetMenuItemBitmaps(hMenu, ID_CLEARSCENE, 0,

LoadBitmap(hInstance, "clear"), LoadBitmap(hInstance, "clear"));
SetMenuItemBitmaps(hMenu, ID_ABOUT, 0,

LoadBitmap(hInstance, "?"), LoadBitmap(hInstance, "?"));
SetMenuItemBitmaps(hMenu, ID_HELP_CONTENT, 0,

LoadBitmap(hInstance, "help"), LoadBitmap(hInstance, "help"));
HDC hdc=GetDC(hWndMain);

SetPF(hdc);

HGLRC gldc=wglCreateContext(hdc);

wglMakeCurrent(hdc, gldc);
}

#endif

___________menu________________
#ifndef MENU_

#define MENU_
#include "resource.h"

#include "globals.h"

#include
#define MODEL_SOLID 0

#define MODEL_WIRE 1
#define MAT_DIFF 0

#define MAT_SPEC 1

#define PARAM_MODEL 0

#define PARAM_MAT 1
int GetMenuItem(int obj, int param, int value)

{

int mi[8][2][2];
mi[PR_SPHERE][PARAM_MODEL][MODEL_SOLID]=ID_SP_SOLID;

mi[PR_SPHERE][PARAM_MODEL][MODEL_WIRE]=ID_SP_WIRE;
mi[PR_HALFSPHERE][PARAM_MODEL][MODEL_SOLID]=ID_HSP_SOLID;

mi[PR_HALFSPHERE][PARAM_MODEL][MODEL_WIRE]=ID_HSP_WIRE;
mi[PR_CYL][PARAM_MODEL][MODEL_SOLID]=ID_CYL_SOLID;

mi[PR_CYL][PARAM_MODEL][MODEL_WIRE]=ID_CYL_WIRE;
mi[PR_PIRAMID3][PARAM_MODEL][MODEL_SOLID]=ID_PIR3_SOLID;

mi[PR_PIRAMID3][PARAM_MODEL][MODEL_WIRE]=ID_PIR3_WIRE;
mi[PR_ELIPS][PARAM_MODEL][MODEL_SOLID]=ID_ELIPS_SOLID;

mi[PR_ELIPS][PARAM_MODEL][MODEL_WIRE]=ID_ELIPS_WIRE;
mi[PR_PRISM3][PARAM_MODEL][MODEL_SOLID]=ID_PRISM3_SOLID;

mi[PR_PRISM3][PARAM_MODEL][MODEL_WIRE]=ID_PRISM3_WIRE;
mi[PR_KOSPR][PARAM_MODEL][MODEL_SOLID]=ID_KOSPR_SOLID;

mi[PR_KOSPR][PARAM_MODEL][MODEL_WIRE]=ID_KOSPR_WIRE;
mi[PR_IKO][PARAM_MODEL][MODEL_SOLID]=ID_CUBE_SOLID;

mi[PR_IKO][PARAM_MODEL][MODEL_WIRE]=ID_CUBE_WIRE;
//////////////////////////////////////////////////
mi[PR_SPHERE][PARAM_MAT][MAT_DIFF]=ID_SP_MAT_DIFF;

mi[PR_SPHERE][PARAM_MAT][MAT_SPEC]=ID_SP_MAT_SPEC;
mi[PR_HALFSPHERE][PARAM_MAT][MAT_DIFF]=ID_HSP_MAT_DIFF;

mi[PR_HALFSPHERE][PARAM_MAT][MAT_SPEC]=ID_HSP_MAT_SPEC;
mi[PR_CYL][PARAM_MAT][MAT_DIFF]=ID_CYL_MAT_DIFF;

mi[PR_CYL][PARAM_MAT][MAT_SPEC]=ID_CYL_MAT_SPEC;
mi[PR_PIRAMID3][PARAM_MAT][MAT_DIFF]=ID_PIR3_MAT_DIFF;

mi[PR_PIRAMID3][PARAM_MAT][MAT_SPEC]=ID_PIR3_MAT_SPEC;
mi[PR_ELIPS][PARAM_MAT][MAT_DIFF]=ID_ELIPS_MAT_DIFF;

mi[PR_ELIPS][PARAM_MAT][MAT_SPEC]=ID_ELIPS_MAT_SPEC;
mi[PR_PRISM3][PARAM_MAT][MAT_DIFF]=ID_PRISM3_MAT_DIFF;

mi[PR_PRISM3][PARAM_MAT][MAT_SPEC]=ID_PRISM3_MAT_SPEC;
mi[PR_KOSPR][PARAM_MAT][MAT_DIFF]=ID_KOSPR_MAT_DIFF;

mi[PR_KOSPR][PARAM_MAT][MAT_SPEC]=ID_KOSPR_MAT_SPEC;
mi[PR_IKO][PARAM_MAT][MAT_DIFF]=ID_CUBE_MAT_DIFF;

mi[PR_IKO][PARAM_MAT][MAT_SPEC]=ID_CUBE_MAT_SPEC;
return mi[obj][param][value];

}

void CheckItem(HMENU hMenu, int obj, int param, int value, bool setup=true)

{

int value2=(!value)?(value+1):(value-1);

int gr1=GetMenuItem(obj, param, value);

int gr2=GetMenuItem(obj, param, value2);

if(value>value2)

CheckMenuRadioItem( hMenu, gr2, gr1, gr1, MF_BYCOMMAND);

else

CheckMenuRadioItem( hMenu, gr1, gr2, gr1, MF_BYCOMMAND);
if(!setup) return;

if(param==PARAM_MAT)

1   2   3   4   5   6   7   8   9   10


написать администратору сайта