Компьютерная графика. Лекция 5

Embed Size (px)

DESCRIPTION

Компьютерная графика. Лекция 5. Моделирование трехмерных поверхностей . Закрашивание. Моделирование поверхностей. Компьютерная графика. Лекция 5. Результатом решения задачи моделирования является множество вершин, однозначно определяющих набор геометрических объектов. - PowerPoint PPT Presentation

Text of Компьютерная графика. Лекция 5

PowerPoint

. 5 ..1 , .

. 5

. 5 (Polygonal meshes) (),

3

. 5 : 4

. 5

5

. 5 : (solid) : , , : z=f(x,y)6

. 5

7

. 5

8

. 5 struct Vertex{GLfloatx;GLfloaty;GLfloatz;};

9

. 5

, 10

. 5 struct Normal{GLfloatx;GLfloaty;GLfloatz;};

11 , ,

. 512

. 5 OpenGL .. : ( )

13

. 5 struct Vector3d{GLfloat x, y, z;};struct Mesh{GLuint numVertices;Vertex *pVertices;GLuint numFaces;Face *pFaces;};struct Vertex{Vector3dposition;Vector3dnormal;// };struct Face{GLushort v0;GLushortv1;GLushortv2;};14

. 5 , , , .

, 15

. 5struct Vector3d{GLfloat x, y, z;};struct Mesh{GLuint numVertices;Vertex *pVertices;GLenum primitiveType;GLuint numIndices;GLushort *pIndices;};struct Vertex{Vector3dposition;Vector3dnormal;// };void DrawMesh(Mesh *pMesh){glBegin(pMesh->primitiveType);for (GLuint i = 0; i < pMesh.numIndices; ++i){GLushort v = pIndices[i];glNormalfv(&(pMesh->pVertices[v].normal.x));glVertex3fv(&(pMesh->pVertices[v].position.x));}glEnd();}16

. 5 () : ( ) ( ) OpenGL , 17

. 5 , , OpenGL OpenGL ,

18

. 5

19

. 5 glFrontFace , (Front face):void glFrontFace(GLenum mode) mode:GL_CW (Clockwise) GL_CCW (Counter clockwise), 20

. 5 (Face culling) , , OpenGL

21

. 5 glEnable(GL_CULL_FACE)glDisable(GL_CULL_FACE)void glCullFace(GLenum mode) mode:GL_FRONTGL_BACKGL_FRONT_AND_BACK22

. 5 () : ( ) ( , ) 23

. 5 ,

24

. 5 3D Studio Max

25

. 5 :

26

. 5 (1,1) :Z = x2 + y2:

( )27

. 5 , : , 3 28

. 5 ,

29

. 5 , , ,

30

. 5 , 31

. 5 C , 32

. 5

33

. 5 , :y=f(x, z) y x z, 34

. 5 , sinc

35

. 5 x y

36

. 5 z

37

. 5

38

. 5

39

. 5

40

. 5 , , .

: , .

. 5

. 5 , : ; ; . 43 . , .

. 5 , , .. . , , .

. 5 , . , , , . .

. 5

. 5 :

( ) , : 47 : ; ;.

. 5 , , , . .

. 5 , .

. 5

: 50

. 5 51

. 5 52

. 5 53 , , .

- . , , .

. 5

. 5 " , " , , , , 55

. 5

, . 56

. 5

57 , , . . , .

. 5

. 5 : .

- , 3D , ( Lighting/Shading: , , ). 59

. 5 () 60

. 5

61

. 5 ( ) : , . , . 62

. 5

, 63

. 5

, . , . , 64

. 5 , , , , . , . , , . , , . .65

. 5 , , .

, .66

. 5 . .

, , . 67

. 5 68

. 5 . , . .69

. 5

, . . .70

. 5

71 OpenGL 8 . ( )

. 572, OpenGL

. 573 , , OpenGL : (GL_AMBIENT) (GL_DIFFUSE) (GL_SPECULAR) (GL_EMISSION) (GL_SHININESS)

. 574 OpenGL glMaterial:glMaterial[f i](GLenum face, GLenum pname, type param)glMaterial[f i]v(GLenum face, GLenum pname, const type *params)face GL_FRONT, GL_BACK GL_FRONT_AND_BACKpname GL_AMBIENT, GL_DIFFUSE, GL_SPECULAR, GL_EMISSION, GL_SHININESS

. 575 glColor glMaterial* glColorMaterial glColor :glEnable(GL_COLOR_MATERIAL)

. 576glColorMaterial glColorglColorMaterial(GLenum face, GLenum mode)face GL_FRONT, GL_BACK, GL_FRONT_AND_BACKmode GL_AMBIENT, GL_DIFFUSE, GL_SPECULAR, GL_EMISSION, GL_AMBIENT_AND_DIFFUSE

. 577void SetCubeMaterial(){glEnable(GL_COLOR_MATERIAL);glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);float specular[4] = {0.7f, 0.7f, 0.7f, 1};glMaterialfv(GL_FRONT, GL_SPECULAR, specular);glMaterialf(GL_FRONT, GL_SHININESS, 10);}

. 578 OpenGL :glEnable(GL_LIGHTING) :glEnable(GL_LIGHTi), i 0 GL_MAX_LIGHTS ( 8) :glLight[i f](GLenum light, GLenum pname, type param)glLight[i f]v(GLenum light, GLenum pname, const type* params)

. 579 GL_SPOT_EXPONENT ( 0 128). GL_SPOT_CUTOFF [0, 90] 180 GL_CONSTANT_ATTENUATION, GL_LINEAR_ATTENUATION, GL_QUADRATIC_ATTENUATION, :1/(k0 + k1*S + k2*S2)

. 580 GL_SPOT_CUTOFF

. 581 GL_AMBIENT GL_DIFFUSE GL_SPECULAR GL_POSITION w 0, . . .GL_SPOT_DIRECTION params

. 582 void SetLights(){glEnable(GL_LIGHTING);glEnable(GL_LIGHT0);

const float diffuseColor[4] = {0.8f, 0.8f, 0.8f, 1};const float ambientColor[4] = {0.2f, 0.2f, 0.2f, 1};const float specularColor[4] = {1.2f, 1.2f, 1.2f, 1};const float lightDirection[4] = {0.0f, 0.0f, 1.0f, 0};glLightfv(GL_LIGHT0, GL_AMBIENT, ambientColor);glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseColor);glLightfv(GL_LIGHT0, GL_POSITION, lightDirection);}

. 583

. 584