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

Курсовой проект 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
страница9 из 10
1   2   3   4   5   6   7   8   9   10

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=false;

EnablePrimitiveAttrs(obj, false, hDlg);

return;

break;
}
if(pobj)

pobj->settings.visible=false;
EnablePrimitiveAttrs(obj, false, hDlg);

}
void SetAttrsVisibility(int obj, HWND hDlg)

{

OBJECT3D *pobj;

bool visible=false;

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:

visible=kospr[0].settings.visible;

EnablePrimitiveAttrs(obj, visible, hDlg);

return;

break;
}
if(pobj)

visible=pobj->settings.visible;
EnablePrimitiveAttrs(obj, visible, hDlg);

}

BOOL WINAPI ParamsProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)

{

int CurSel;

int CurMaterial;

POINT pt;
switch(msg)

{

case WM_COMMAND:

if(LOWORD(wParam)==IDC_OBJ_FIND)

{

GetCursorPos(&pt);

TIPWND::ShowHelp(pt.x, pt.y, "Пока не работает", "sdf");

}

if(LOWORD(wParam)==IDC_PRIM_HELP)

{

CurSel=SendMessage(GetDlgItem(hDlg, IDC_OBJECTS_LIST), CB_GETCURSEL, 0, 0);

GetCursorPos(&pt);

LoadHelpText(HelpFiles[CurSel+HLP_PRIM], helpText, 1500);

TIPWND::ShowHelp(pt.x, pt.y, HelpCaptions[CurSel+HLP_PRIM], helpText);

}
if(LOWORD(wParam)==IDC_SETPRIMCOLOR )

{

SetPrimitiveColor(SendMessage(GetDlgItem(hDlg, IDC_OBJECTS_LIST), CB_GETCURSEL, 0, 0),

GetDlgItem(hDlg, IDC_OBJ_COLORR), GetDlgItem(hDlg, IDC_OBJ_COLORG),

GetDlgItem(hDlg, IDC_OBJ_COLORB));

return true;

}

CurSel=SendMessage(GetDlgItem(hDlg, IDC_OBJECTS_LIST), CB_GETCURSEL, 0, 0);

if(LOWORD(wParam)==IDC_SOLID || LOWORD(wParam)==IDC_WIRE)

SetModelType(CurSel, GetDlgItem(hDlg, IDC_SOLID));

if(LOWORD(wParam)==IDC_OBJECTS_LIST && HIWORD(wParam)==CBN_SELCHANGE)

{

GetPartitions(CurSel, GetDlgItem(hDlg, IDC_WPARTS), GetDlgItem(hDlg, IDC_HPARTS));

SetModelRadio(CurSel,GetDlgItem(hDlg, IDC_SOLID), GetDlgItem(hDlg, IDC_WIRE));

GetColor(CurSel, hDlg);

SetAttrsVisibility(CurSel, hDlg);

GetMaterial(ObjectsNotAll[CurSel]->settings.material, hDlg);

}
if(LOWORD(wParam)==IDC_WPARTS && HIWORD(wParam)==EN_CHANGE)

SetWParts(CurSel, GetDlgItem(hDlg, IDC_WPARTS), GetDlgItem(hDlg, IDC_HPARTS));
if(LOWORD(wParam)==IDC_HPARTS && HIWORD(wParam)==EN_CHANGE)

SetHParts(CurSel, GetDlgItem(hDlg, IDC_HPARTS));
if(LOWORD(wParam)==IDC_OBJ_MATERIAL && HIWORD(wParam)==CBN_SELCHANGE)

{

CurMaterial=SendMessage(GetDlgItem(hDlg, IDC_OBJ_MATERIAL), CB_GETCURSEL, 0, 0);

SetPrimitiveMaterial(CurSel, CurMaterial?GL_SPECULAR:GL_DIFFUSE);

}

if(LOWORD(wParam)==IDC_OBJ_ADD)

{

AddPrimitive(CurSel, hDlg);

FillObjectsList(GetDlgItem(hDlg, IDC_OBJECTS_LIST));

SendMessage(GetDlgItem(hDlg, IDC_OBJECTS_LIST), CB_SETCURSEL, CurSel, 0);

}

if(LOWORD(wParam)==IDC_OBJ_DEL)

{

DelPrimitive(CurSel, hDlg);

FillObjectsList(GetDlgItem(hDlg, IDC_OBJECTS_LIST));

SendMessage(GetDlgItem(hDlg, IDC_OBJECTS_LIST), CB_SETCURSEL, CurSel, 0);

}

break;
case WM_INITDIALOG:

RECT rct;

hPrimParams=hDlg;

GetWindowRect(GetDlgItem(hDlg, IDC_OBJ_MATERIAL), &rct);

MoveWindow(GetDlgItem(hDlg, IDC_OBJ_MATERIAL), 10, 370, rct.right-rct.left, 200, true);
SendMessage(GetDlgItem(hDlg, IDC_OBJ_MATERIAL), CB_RESETCONTENT, 0, 0);
SendMessage(GetDlgItem(hDlg, IDC_OBJ_MATERIAL), CB_ADDSTRING, 0, (WPARAM)"Матовый");

SendMessage(GetDlgItem(hDlg, IDC_OBJ_MATERIAL), CB_ADDSTRING, 0, (WPARAM)"Пропускающий свет");

SendMessage(GetDlgItem(hDlg, IDC_OBJ_MATERIAL), CB_SETCURSEL, sp.settings.material==GL_SPECULAR?1:0, 0);


SendMessage(GetDlgItem(hDlg, IDC_OBJECTS_LIST), CB_RESETCONTENT, 0, 0);
FillObjectsList(GetDlgItem(hDlg, IDC_OBJECTS_LIST));

SetModelRadio(0,

GetDlgItem(hDlg, IDC_SOLID), GetDlgItem(hDlg, IDC_WIRE));

GetPartitions(0, GetDlgItem(hDlg, IDC_WPARTS), GetDlgItem(hDlg, IDC_HPARTS));
GetColor(0, hDlg);

EnablePrimitiveAttrs(0, sp.settings.visible, hDlg);

GetMaterial(sp.settings.material, hDlg);

for(int i=PR_SPHERE; i<8; i++)

CheckItem(GetMenu(hWndMain), i, PARAM_MAT,

(ObjectsNotAll[i]->settings.material==GL_DIFFUSE)?MAT_DIFF:MAT_SPEC, false);
for(i=PR_SPHERE; i<8; i++)

CheckItem(GetMenu(hWndMain), i, PARAM_MODEL,

(ObjectsNotAll[i]->settings.model==GL_FILL)?MODEL_SOLID:MODEL_WIRE, false);
break;
}

return 0;

}
#endif

_______________panel_scens____________
#ifndef SCENE_

#define SCENE_

#include "globals.h"

BOOL WINAPI SceneParamsProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)

{

int lightcount=0, i;

char lc[20];

HWND hListMat=GetDlgItem(hDlg, IDC_OBJ_MATERIAL);

HWND hListModel=GetDlgItem(hDlg, IDC_OBJ_MODEL);

switch(msg)

{

case WM_INITDIALOG:

hSceneParams=hDlg;

for(i=0; i<8; i++)

if(lights[i].Shining()) lightcount++;

sprintf(lc, "Кол-во источников света: %i", lightcount);

SetDlgItemText(hDlg, IDC_LIGHTS_COUNT, lc);
SendMessage(hListMat, CB_RESETCONTENT, 0, 0);

SendMessage(hListModel, CB_RESETCONTENT, 0, 0);
SendMessage(hListMat, CB_ADDSTRING, 0, (LPARAM)"Не проп. свет");

SendMessage(hListMat, CB_ADDSTRING, 0, (LPARAM)"С отражнием");

SendMessage(hListMat, CB_ADDSTRING, 0, (LPARAM)"-");

SendMessage(hListMat, CB_SETCURSEL, !ObjMat?0:( (ObjMat==GL_SPECULAR)?1:2), 0);
SendMessage(hListModel, CB_ADDSTRING, 0, (LPARAM)"Полигональная");

SendMessage(hListModel, CB_ADDSTRING, 0, (LPARAM)"Проволочная");

SendMessage(hListModel, CB_ADDSTRING, 0, (LPARAM)"-");

SendMessage(hListModel, CB_SETCURSEL, (ObjModel==GL_FILL)?0:( (ObjModel==GL_LINE)?1:2), 0);
SendMessage(GetDlgItem(hDlg, IDC_DRAW_AXES), BM_SETCHECK, DrawAxes, 0);
SendMessage(GetDlgItem(hDlg, IDC_AXESALWAYSONTOP), BM_SETCHECK, AxesAlwaysOnTop, 0);
sprintf(lc, "%.2f", ObjHeight);

SetDlgItemText(hDlg, IDC_HEIGHT, lc);

break;
case WM_COMMAND:
if(LOWORD(wParam)==IDC_SAVESCENE) SaveScene();

if(LOWORD(wParam)==IDC_LOADSCENE) LoadScene();
if(LOWORD(wParam)==IDC_HEIGHT && HIWORD(wParam)==EN_CHANGE)

{

GetDlgItemText(hDlg, IDC_HEIGHT, lc, 19);

ObjHeight=atof(lc);

}
if(LOWORD(wParam)==IDC_DRAW_AXES)

DrawAxes=SendMessage(GetDlgItem(hDlg, IDC_DRAW_AXES), BM_GETCHECK, 0, 0);
if(LOWORD(wParam)==IDC_AXESALWAYSONTOP)

AxesAlwaysOnTop=SendMessage(GetDlgItem(hDlg, IDC_AXESALWAYSONTOP), BM_GETCHECK, 0, 0);

if(LOWORD(wParam)==IDC_SCENE_CLEAR)

{

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

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

}
if(LOWORD(wParam)==IDC_OBJ_MODEL && HIWORD(wParam)==CBN_SELCHANGE)

{

int CurSel=SendMessage(hListModel, CB_GETCURSEL, 0, 0);

int oldmodel=ObjModel;

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

ObjModel=Objects[i]->settings.model=!CurSel?GL_FILL:(CurSel==1?GL_LINE:oldmodel);

SendMessage(hListModel, CB_SETCURSEL, (ObjModel==GL_FILL)?0:( (ObjModel==GL_LINE)?1:2), 0);

}
if(LOWORD(wParam)==IDC_OBJ_MATERIAL && HIWORD(wParam)==CBN_SELCHANGE)

{

int CurSel=SendMessage(hListMat, CB_GETCURSEL, 0, 0);

int oldmat=ObjMat;

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

ObjMat=Objects[i]->settings.material=!CurSel?GL_DIFFUSE:(CurSel==1?GL_SPECULAR:oldmat);
SendMessage(hListMat, CB_SETCURSEL, (ObjMat==GL_DIFFUSE)?0:

( (ObjMat==GL_SPECULAR)?1:2), 0);

}

break;

}

return 0;

}
#endif

___________________premetives_________
#ifndef PRIMITIVES

#define PRIMITIVES

#include

#define PI 3.1415

#define PR_SPHERE 0

#define PR_HALFSPHERE 1

#define PR_IKO 2

#define PR_PRISM3 3

#define PR_ELIPS 4

#define PR_CYL 5

#define PR_PIRAMID3 6

#define PR_KOSPR 7
class OBJECT3D

{

public:

struct

{

float r, g, b, a;

int m, n;

int model;

int material;

bool visible;

} settings;
float x, y, z;

OBJECT3D(float x, float y, float z, float r=1, float g=1, float b=1, float a=1)

{this->x=x; this->y=y; this->z=z; settings.r=r; settings.g=g; settings.b=b; settings.a=a;

settings.m=20;

settings.n=20;

settings.model=GL_FILL;

settings.material=GL_DIFFUSE;

settings.visible=false;

}

void SetNormal(float , float , float, float , float , float, float , float , float );

void SetPartitions(int n, int m){settings.n=n; settings.m=m;};

void SetMaterial(int mat) {settings.material=mat;}

virtual void Draw()

{

glPolygonMode(GL_FRONT_AND_BACK, settings.model);

glColor4f(settings.r, settings.g, settings.b, settings.a);

float spc[]={1, 1, 1, 1};

float zero[]={0, 0, 0, 1};

if(settings.material==GL_SPECULAR)

glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, spc);

else glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, zero);
if(settings.material==GL_DIFFUSE)

glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, spc);

else glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, zero);

glMaterialf(GL_FRONT, GL_SHININESS, 12);

};

};
class SPHERE: public OBJECT3D //сфера

{
public:

SPHERE(float x, float y, float z, float radius=1, float r=1, float g=1, float b=1, float a=1):

OBJECT3D(x, y, z, r, g, b, a){this->radius=radius;}

float radius;

void Draw();

};
void SPHERE::Draw()

{

if(!settings.visible) return;

OBJECT3D::Draw();

GLUquadricObj* q=gluNewQuadric();
glPushMatrix();

glTranslated(-4*radius, 3*radius, 8*radius);

gluSphere(q, radius, settings.n, settings.m);

glPopMatrix();
glPushMatrix();

glTranslated(4*radius, 3*radius, 8*radius);

gluSphere(q, radius, settings.n, settings.m);

glPopMatrix();
gluDeleteQuadric(q);

}
class HALFSPHERE: public OBJECT3D //полусфера

{

public:

HALFSPHERE(float x, float y, float z, float radius, float r=1, float g=1, float b=1, float a=1):

OBJECT3D(x, y, z, r, g, b, a){this->radius=radius;}

float radius;

void Draw();

};
void HALFSPHERE::Draw()

{

if(!settings.visible) return;

OBJECT3D::Draw();

GLUquadricObj* q=gluNewQuadric();

glPushMatrix();
double cp0[]={0, 1, 0, -y};

glClipPlane(GL_CLIP_PLANE0, cp0);

glEnable(GL_CLIP_PLANE0);

glTranslated(x, y, z);

gluSphere(q, 9*radius, settings.n, settings.m);

glPopMatrix();

glDisable(GL_CLIP_PLANE0);

}

class PRISM3: public OBJECT3D //3 уг призма

{

public:

PRISM3(float x, float y, float z, float r=1, float g=1, float b=1, float a=1):

OBJECT3D(x, y, z, r, g, b, a){ settings.m=1; settings.n=1;}

void Draw();

};
void PRISM3::Draw()

{

if(!settings.visible) return;

OBJECT3D::Draw();

GLUquadricObj* q=gluNewQuadric();
glPushMatrix();

glRotated(45,0,1,0);

gluCylinder(q, 1, 1, 20, 3, 1);

glPopMatrix();
glPushMatrix();
glRotated(-45,0,1,0);

gluCylinder(q, 1, 1, 20, 3, 1);

glPopMatrix();
glPushMatrix();

glRotated(150,0,1,0);

gluCylinder(q, 1, 1, 20, 3, 1);

glPopMatrix();
glPushMatrix();

glRotated(210,0,1,0);

gluCylinder(q, 1, 1, 20, 3, 1);

glPopMatrix();
gluDeleteQuadric(q);

glShadeModel(GL_SMOOTH);

}

class IKO: public OBJECT3D //икосаэдр

{
float riblen;

public:

IKO(float x, float y, float z, float riblen=1, float r=1, float g=1, float b=1, float a=1):

OBJECT3D(x, y, z, r, g, b, a){this->riblen=riblen; settings.n=1; settings.m=1;};

void Draw();

};
void IKO::Draw()

{

if(!settings.visible) return;

OBJECT3D::Draw();
glPushMatrix();

glRotated(45,0,1,0);

glPushMatrix();

glTranslatef(0, 0, 20*riblen);

auxSolidIcosahedron(riblen);

glPopMatrix();

glPopMatrix();
glPushMatrix();

glRotated(-45,0,1,0);

glPushMatrix();

glTranslatef(0, 0, 20*riblen);

auxSolidIcosahedron(riblen);

glPopMatrix();

glPopMatrix();
glPushMatrix();

glRotated(150,0,1,0);

glPushMatrix();

glTranslatef(0, 0, 20*riblen);

auxSolidIcosahedron(riblen);

glPopMatrix();

glPopMatrix();
glPushMatrix();

glRotated(210,0,1,0);

glPushMatrix();

glTranslatef(0, 0, 20*riblen);

auxSolidIcosahedron(riblen);

glPopMatrix();

glPopMatrix();

}
class ELIPS:public OBJECT3D //эллипсоид

{

public:

ELIPS(float x, float y, float z, float radius=1, float r=1, float g=1, float b=1, float a=1):

OBJECT3D(x, y, z, r, g, b, a){this->radius=radius;}

void Draw();

float radius;

};
void ELIPS::Draw()

{

if(!settings.visible) return;

OBJECT3D::Draw();

glShadeModel(GL_FLAT);

glPushMatrix();

glRotatef(-90, 1, 0 ,0);

glTranslatef(x, y, z);

GLUquadricObj *q=gluNewQuadric();
glPushMatrix();

glScaled(0.8, 1, 0.25);

gluSphere(q, 12*radius, settings.n, settings.m);

glPopMatrix();
glPopMatrix();

gluDeleteQuadric(q);

glShadeModel(GL_SMOOTH);

}
class CYL: public OBJECT3D // кос цилиндр

{

public:

CYL(float x, float y, float z, float radius=1, float r=1, float g=1, float b=1, float a=1):

OBJECT3D(x, y, z, r, g, b, a){this->radius=radius; settings.n=1; settings.m=1;}

void Draw();

float radius;

};
void CYL::Draw()

{

if(!settings.visible) return;

OBJECT3D::Draw();

GLUquadricObj* q=gluNewQuadric();

glPushMatrix();
GLfloat M1[]={1,0.1,0.1,0, 0,1,0,0, 0,0,1,0, 0,0,0,1};

GLfloat M2[]={1,-0.1,-0.1,0, 0,1,0,0, 0,0,1,0, 0,0,0,1};

glPushMatrix();

glMultMatrixf(M1);

glRotated(30,0,1,0);

glPushMatrix();

gluCylinder(q, 1.5*radius, 1.5*radius, 18*radius , 3,1);

glPushMatrix();

glTranslatef(0, 0, 4);

gluDisk(q, 0, 1.5, 3, 1);

glPopMatrix();

glPopMatrix();

glPopMatrix();
glPushMatrix();

glMultMatrixf(M2);

glRotated(-30,0,1,0);

glPushMatrix();

gluCylinder(q, 1.5*radius, 1.5*radius, 18*radius , 3, 1);

glPushMatrix();

glTranslatef(0, 0, 4);

gluDisk(q, 0, 1.5, 3, 1);

glPopMatrix();

glPopMatrix();

glPopMatrix();

glPopMatrix();

gluDeleteQuadric(q);

glShadeModel(GL_SMOOTH);

}
class PIRAMID3: public OBJECT3D //усеченная пирамида

{

public:

PIRAMID3(float x, float y, float z, float r=1., float g=1., float b=1., float a=1):

OBJECT3D(x, y, z, r, g, b, a){settings.m=1;settings.n=1;}

void Draw();

};
void PIRAMID3::Draw()

{

if(!settings.visible) return;

OBJECT3D::Draw();

GLUquadricObj* q=gluNewQuadric();
glPushMatrix();

glRotated(45,0,1,0);
glPushMatrix();

glTranslatef(0, 0, 20);

glRotated(90,1,0,0);
gluCylinder(q, 1, 2, 2, 3, 1);

gluDisk(q, 0, 1, 3, 1);

glPopMatrix();

glPopMatrix();
glPushMatrix();

glRotated(-45,0,1,0);
glPushMatrix();

glTranslatef(0, 0, 20);

glRotated(90,1,0,0);
gluCylinder(q, 1, 2, 2, 3, 1);

gluDisk(q, 0, 1, 3, 1);

glPopMatrix();
glPopMatrix();
glPushMatrix();

glRotated(150,0,1,0);
glPushMatrix();

glTranslatef(0, 0, 20);

glRotated(90,1,0,0);
1   2   3   4   5   6   7   8   9   10


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