class Terrain public cont num Cells Per Row
지형 기하정보 생성 class Terrain { 클래스 정의 public: (cont’) 초기화 _num. Cells. Per. Row = _num. Verts. Per. Row - 1; Terrain( _num. Cells. Per. Col = _num. Verts. Per. Col - 1; IDirect 3 DDevice 9* device, _width = _num. Cells. Per. Row * _cell. Spacing; std: : string heightmap. File. Name, _depth = _num. Cells. Per. Col * _cell. Spacing; int num. Verts. Per. Row, _num. Vertices = _num. Verts. Per. Row * _num. Verts. Per. Col; _num. Triangles = _num. Cells. Per. Row * _num. Cells. Per. Col * 2; int cell. Spacing, int num. Verts. Per. Col, // space between cells float height. Scale); // value to scale heights by. . . methods snipped private: . . . device/vertex buffer etc snipped 버텍스 구조체 정의 struct Terrain. Vertex { Terrain. Vertex(){} int _num. Verts. Per. Row; Terrain. Vertex(float x, float y, float z, float u, float v) int _num. Verts. Per. Col; { int _cell. Spacing; _x = x; _y = y; _z = z; _u = u; _v = v; int _num. Cells. Per. Row; } int _num. Cells. Per. Col; float _x, _y, _z; int _width; float _u, _v; int _depth; int _num. Vertices; static const DWORD FVF; int _num. Triangles; float _height. Scale; }; const DWORD Terrain: : Terrain. Vertex: : FVF = D 3 DFVF_XYZ | D 3 DFVF_TEX 1;
실습 l 지형 기하정보 생성 – 다음 함수의 내용을 관찰 – bool Terrain: : compute. Vertices() – bool Terrain: : compute. Indices()
지형 기하정보 생성 l (cont’) 인덱스 계산 – 삼각형 정의하기 – 삼각형 ABC l l l – Vertex. Buffer[i*num. Verts. Per. Row + j] Vertex. Buffer[i*num. Verts. Per. Row + (j+1)] Vertex. Buffer[(i+1)*num. Verts. Per. Row + j] 행i 열j 열j+1 A B C D 삼각형 CDB l l l Vertex. Buffer[(i+1)*num. Verts. Per. Row + j] Vertex. Buffer[i*num. Verts. Per. Row + (j+1)] Vertex. Buffer[(i+1)*num. Verts. Per. Row + (j+1)] 행i+1 셀ij
실습 l Init. Data() 함수 – 활성화 l g_p. Terrain->load. Texture (". /images/ desert. bmp"); – 주석처리 l g_p. Terrain->gen. Texture(&direction. To. Light); 실행 후 Image 폴더의 desert. bmp 관찰 bool Terrain: : load. Texture(std: : string file. Name) – 텍스처 load부분 관찰 – l
실습 l l l bool Terrain: : gen. Texture(D 3 DXVECTOR 3* direction. To. Light) – 텍스처 생성부분 관찰 – 색상 변경 g_p. Terrain->gen. Texture(&direction. To. Light); – 활성화 후 실행 bool Terrain: : draw(D 3 DXMATRIX* world, bool draw. Tris) – 텍스처 필터 활성화 – _device->Set. Sampler. State(0, D 3 DSAMP_MAGFILTER, D 3 DTEXF_LINEAR);
실습 l l 조명관련 함수 관찰 – float Terrain: : compute. Shade(int cell. Row, int cell. Col, D 3 DXVECTOR 3* direction. To. Light) 지형 걷기 관련 함수 관찰 – float Terrain: : get. Height(float x, float z)
- Slides: 31