week04 directx9 프로그래밍의 기초2 -...

35
DirectX9 프로그래밍의 기초2

Upload: others

Post on 31-Aug-2019

9 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Week04 DirectX9 프로그래밍의 기초2 - cfs7.tistory.comcfs7.tistory.com/upload_control/download.blog?fhandle=YmxvZzIwOTc5... · DirectX9 프로그래밍의기초2. 목차 XFile

DirectX9 프로그래밍의 기초2

Page 2: Week04 DirectX9 프로그래밍의 기초2 - cfs7.tistory.comcfs7.tistory.com/upload_control/download.blog?fhandle=YmxvZzIwOTc5... · DirectX9 프로그래밍의기초2. 목차 XFile

목 차

XFilXFile

파일 포맷ID3DXBufferID3DXBufferXFile 사용하기

경계 볼륨경계 볼륨

애니메이션및 게임 실습 2

Page 3: Week04 DirectX9 프로그래밍의 기초2 - cfs7.tistory.comcfs7.tistory.com/upload_control/download.blog?fhandle=YmxvZzIwOTc5... · DirectX9 프로그래밍의기초2. 목차 XFile

XFile

3D Modeler

3DS MaxLightWave 3DMayaMaya

메쉬 데이터

기하정보재질애니메이션

애니메이션및 게임 실습 3

Page 4: Week04 DirectX9 프로그래밍의 기초2 - cfs7.tistory.comcfs7.tistory.com/upload_control/download.blog?fhandle=YmxvZzIwOTc5... · DirectX9 프로그래밍의기초2. 목차 XFile

XFile

XFile

.XDirectX에서 사용하는 파일 포맷

파일 처리 함수를 DirectX가 제공

파일 종류파일 종류

ASCIIBinaryBi C dBinary Compressed

애니메이션및 게임 실습 4

Page 5: Week04 DirectX9 프로그래밍의 기초2 - cfs7.tistory.comcfs7.tistory.com/upload_control/download.blog?fhandle=YmxvZzIwOTc5... · DirectX9 프로그래밍의기초2. 목차 XFile

XFile

파일 포맷

사용자 정의 데이터 형

X파일은 사용자에 의해 정의된 템플릿에 의해 동작X파일은 사용자에 의해 정의된 템플릿에 의해 동작템플릿은 데이터 개체가 어떻게 저장되어야 하는 지를 정의

계층적 관계

선택적 멤버 : 템플릿이 허용하는 데이터 타입들. 선택적 멤버들은 데이터 개체의 자식 멤버로 저장됨자식 멤버 : 다른 데이터 개체 다른 개체의 참조 이진 데이터자식 멤버 : 다른 데이터 개체, 다른 개체의 참조, 이진 데이터

애니메이션및 게임 실습 5

Page 6: Week04 DirectX9 프로그래밍의 기초2 - cfs7.tistory.comcfs7.tistory.com/upload_control/download.blog?fhandle=YmxvZzIwOTc5... · DirectX9 프로그래밍의기초2. 목차 XFile

XFile

square.xq

애니메이션및 게임 실습 6

Page 7: Week04 DirectX9 프로그래밍의 기초2 - cfs7.tistory.comcfs7.tistory.com/upload_control/download.blog?fhandle=YmxvZzIwOTc5... · DirectX9 프로그래밍의기초2. 목차 XFile

XFile

헤더

xof 0303txt 0032

파일의 시작 : xof파일의 시작 : xof버전 : 03.03파일 포맷 : txt, bin, tzip, bzip부동 소수점 데이터 타입 : 0032, 0064

애니메이션및 게임 실습 7

Page 8: Week04 DirectX9 프로그래밍의 기초2 - cfs7.tistory.comcfs7.tistory.com/upload_control/download.blog?fhandle=YmxvZzIwOTc5... · DirectX9 프로그래밍의기초2. 목차 XFile

XFile

메시

Mesh Square {정점의 수

Mesh Square {8; // 정점의 수정점의 수

정점정보면의 수면 정보메시 재질 리스트

8; // 정점의 수1.0; 1.0; 0.0;, // vertice 0-1.0; 1.0; 0.0;, // vertice 1-1.0;-1.0; 0.0;, // vertice 21 0 1 0 0 0 // i 3메시 재질 리스트

}1.0;-1.0; 0.0; // vertice 31.0; 1.0; 0.0;, // vertice 41.0;-1.0; 0.0;, // vertice 5-1.0;-1.0; 0.0;, // vertice 6; ; ;,-1.0; 1.0; 0.0;; // vertice 74; // 면의 수3;0,1,2;, // triangle #13 0 2 3 // t i l #23;0,2,3;, // triangle #23;4,5,6;, // triangle #33;4,6,7;; // triangle #4

}

애니메이션및 게임 실습 8

}

Page 9: Week04 DirectX9 프로그래밍의 기초2 - cfs7.tistory.comcfs7.tistory.com/upload_control/download.blog?fhandle=YmxvZzIwOTc5... · DirectX9 프로그래밍의기초2. 목차 XFile

XFile

메시 재질 리스트

MeshMaterialList는 매시 개체의 자식 개체로서 메시 개체의 일부로 동작재질의 개수, 면의 개수, 재질

MeshMaterialList {{1; // one material4; // one face0, // face #0 use material #00 // face #1 use material #00, // face #1 use material #00, // face #2 use material #00;; // face #3 use material #0

}

애니메이션및 게임 실습 9

Page 10: Week04 DirectX9 프로그래밍의 기초2 - cfs7.tistory.comcfs7.tistory.com/upload_control/download.blog?fhandle=YmxvZzIwOTc5... · DirectX9 프로그래밍의기초2. 목차 XFile

XFile

재질

재질의 색, 힘, 반사광 색상, 발광 색상

Material { // material #00 0;1 0;0 5;1 0;; // face color0.0;1.0;0.5;1.0;; // face color0.0; // power0.0;0.0;0.0;; // specular color0.0;0.0;0.0;; // emissive color

}

애니메이션및 게임 실습 10

Page 11: Week04 DirectX9 프로그래밍의 기초2 - cfs7.tistory.comcfs7.tistory.com/upload_control/download.blog?fhandle=YmxvZzIwOTc5... · DirectX9 프로그래밍의기초2. 목차 XFile

XFile

square2.xq

애니메이션및 게임 실습 11

Page 12: Week04 DirectX9 프로그래밍의 기초2 - cfs7.tistory.comcfs7.tistory.com/upload_control/download.blog?fhandle=YmxvZzIwOTc5... · DirectX9 프로그래밍의기초2. 목차 XFile

XFile

VertexDuplicationIndicesp

메시 한 개 당 하나씩 생성

메시 내의 어떤 정점들이 중복되는지에 대한 정보메시 내의 어떤 정점들이 중복되는지에 대한 정보

매끄러운 부분 혹은 재질 경계에서 발생

메시 단순화 프로그램에서 사용

애니메이션및 게임 실습 12

Page 13: Week04 DirectX9 프로그래밍의 기초2 - cfs7.tistory.comcfs7.tistory.com/upload_control/download.blog?fhandle=YmxvZzIwOTc5... · DirectX9 프로그래밍의기초2. 목차 XFile

XFile

법선 벡터

MeshNormals {8;8;0.000000;0.000000;1.000000;,0.000000;0.000000;1.000000;,0.000000;0.000000;1.000000;,0.000000;0.000000;1.000000;,0.000000;0.000000;-1.000000;,0.000000;0.000000;-1.000000;,0 000000;0 000000;-1 000000;0.000000;0.000000;-1.000000;,0.000000;0.000000;-1.000000;;4;3;0,1,2;,3;0,2,3;,3;4,5,6;,3;4,6,7;;

}

애니메이션및 게임 실습 13

}

Page 14: Week04 DirectX9 프로그래밍의 기초2 - cfs7.tistory.comcfs7.tistory.com/upload_control/download.blog?fhandle=YmxvZzIwOTc5... · DirectX9 프로그래밍의기초2. 목차 XFile

XFile

텍스처

Material 개체의 멤버로 TextureFilename 개체 생성

Material GreenMat {0.0;1.0;0.0;1.0;;0.0;0.0;0.0;0.0;;0.0;0.0;0.0;;

TextureFilename {"wall.bmp";

}}

애니메이션및 게임 실습 14

Page 15: Week04 DirectX9 프로그래밍의 기초2 - cfs7.tistory.comcfs7.tistory.com/upload_control/download.blog?fhandle=YmxvZzIwOTc5... · DirectX9 프로그래밍의기초2. 목차 XFile

XFile

텍스처 좌표 매핑

MeshTextureCoords { MeshTextureCoords {MeshTextureCoords {8; // 4 texture coords1.0; 1.0;, // coord 01.0; 0.0;, // coord 1

// d

MeshTextureCoords {4; 1.0; 1.0;, // coord 01.0; 0.0;, // coord 1

// d0.0; 0.0;, // coord 20.0; 1.0;; // coord 31.0; 1.0;, // coords 41.0;-1.0;, // coords 5

0.0; 0.0;, // coord 20.0; 1.0;; // coord 3

}1.0; 1.0;, // coords 5-1.0;-1.0;, // coords 6-1.0; 1.0;; // coords 7

}

MeshTextureCoords {4; 1.0; 1.0;, // coord 0-1.0; 0.0;, // coord 1-1.0; -1.0;, // coord 21.0; -1.0;; // coord 3

}

애니메이션및 게임 실습 15

}

Page 16: Week04 DirectX9 프로그래밍의 기초2 - cfs7.tistory.comcfs7.tistory.com/upload_control/download.blog?fhandle=YmxvZzIwOTc5... · DirectX9 프로그래밍의기초2. 목차 XFile

XFile

square3.xq

애니메이션및 게임 실습 16

Page 17: Week04 DirectX9 프로그래밍의 기초2 - cfs7.tistory.comcfs7.tistory.com/upload_control/download.blog?fhandle=YmxvZzIwOTc5... · DirectX9 프로그래밍의기초2. 목차 XFile

XFile

boidy.xy

애니메이션및 게임 실습 17

Page 18: Week04 DirectX9 프로그래밍의 기초2 - cfs7.tistory.comcfs7.tistory.com/upload_control/download.blog?fhandle=YmxvZzIwOTc5... · DirectX9 프로그래밍의기초2. 목차 XFile

XFile

boidy.xy

애니메이션및 게임 실습 18

Page 19: Week04 DirectX9 프로그래밍의 기초2 - cfs7.tistory.comcfs7.tistory.com/upload_control/download.blog?fhandle=YmxvZzIwOTc5... · DirectX9 프로그래밍의기초2. 목차 XFile

XFile

변환 행렬

프레임 : 물체의 각 부분을 별개로 움직이게 하려면 모델을 여러 개의 프레임으로구분전차 : 포 상하좌우 바퀴 궤도전차 : 포 – 상하좌우, 바퀴, 궤도

Frame SQUARE_Root {FrameTransformMatrix {

1.000000, 0.000000, 0.000000, 0.000000,0.000000, 1.000000, 0.000000, 0.000000,0.000000, 0.000000, 1.000000, 0.000000,0.000000, 0.000000, 0.000000, 1.000000;;

}}}

애니메이션및 게임 실습 19

Page 20: Week04 DirectX9 프로그래밍의 기초2 - cfs7.tistory.comcfs7.tistory.com/upload_control/download.blog?fhandle=YmxvZzIwOTc5... · DirectX9 프로그래밍의기초2. 목차 XFile

XFile

AnimationSet

Positionkey

0 : scaling0 : scaling1 : rotation2 : translation4 : matrix

애니메이션및 게임 실습 20

Page 21: Week04 DirectX9 프로그래밍의 기초2 - cfs7.tistory.comcfs7.tistory.com/upload_control/download.blog?fhandle=YmxvZzIwOTc5... · DirectX9 프로그래밍의기초2. 목차 XFile

XFile

AnimationSet

AnimationSetMoveX{Animation{{

AnimationKey{4;//Positionkeys5;//5keys0;16;1 0 0 0 0 0 0 00;16;1.0,0.0,0.0,0.0,

0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.1,0.0,0.0,1.0;;,, , , ;;,

80;16;1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0 2 0 0 0 0 1 0;;0.2,0.0,0.0,1.0;;,

애니메이션및 게임 실습 21

Page 22: Week04 DirectX9 프로그래밍의 기초2 - cfs7.tistory.comcfs7.tistory.com/upload_control/download.blog?fhandle=YmxvZzIwOTc5... · DirectX9 프로그래밍의기초2. 목차 XFile

XFile

AnimationSet

160;16;1.0,0.0,0.0,0.0,0 0 1 0 0 0 0 00.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.3,0.0,0.0,1.0;;,

240;16;1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.2,0.0,0.0,1.0;;,

320;16;1 0 0 0 0 0 0 0320;16;1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.1,0.0,0.0,1.0;;,

}{SQUARE_Root}

}}

애니메이션및 게임 실습 22

}

Page 23: Week04 DirectX9 프로그래밍의 기초2 - cfs7.tistory.comcfs7.tistory.com/upload_control/download.blog?fhandle=YmxvZzIwOTc5... · DirectX9 프로그래밍의기초2. 목차 XFile

XFile

square4.xq

애니메이션및 게임 실습 23

Page 24: Week04 DirectX9 프로그래밍의 기초2 - cfs7.tistory.comcfs7.tistory.com/upload_control/download.blog?fhandle=YmxvZzIwOTc5... · DirectX9 프로그래밍의기초2. 목차 XFile

XFile

ID3DXBuffer

연속적인 메모리 블록에 데이터를 저장하기 위해 이용하는 범용 데이터 구조체

LPVOID GetBufferPointer() : 데이터의 시작 포인터LPVOID GetBufferPointer() : 데이터의 시작 포인터DWORD GetBufferSize() : 버퍼 크기

데이터 형 변환

DWORD* info = (DWORD*)adjacencyInfo->GetBufferPointer();( ) j y ()D3DXMATERIAL* mtrl = (D3DXMATERIAL*)mtrlBuffer->GetBufferPointer();

adjacencyInfo->Release();mtrlBuffer->Release();

애니메이션및 게임 실습 24

Page 25: Week04 DirectX9 프로그래밍의 기초2 - cfs7.tistory.comcfs7.tistory.com/upload_control/download.blog?fhandle=YmxvZzIwOTc5... · DirectX9 프로그래밍의기초2. 목차 XFile

XFile

ID3DXBuffer

HRESULT D3DXCreateBuffer((

DWORD NumBytes, // 버퍼의 크기LPD3DXBUFFER *ppBuffer // 생성된 버퍼

);

ID3DXBuffer* buffer = 0;D3DXCreateBuffer(4*sizeof(int), &buffer);

애니메이션및 게임 실습 25

Page 26: Week04 DirectX9 프로그래밍의 기초2 - cfs7.tistory.comcfs7.tistory.com/upload_control/download.blog?fhandle=YmxvZzIwOTc5... · DirectX9 프로그래밍의기초2. 목차 XFile

XFile

Load

HRESULT D3DXLoadMeshFromX((

LPCSTR pFileName, // XFile명DWORD Options, // 생성 플래그LPDIRECT3DDEVICE9 pDevice, // 메쉬 연결 장치LPD3DXBUFFER ** Adj // 메쉬 접근 정보LPD3DXBUFFER **ppAdjacency, // 메쉬 접근 정보LPD3DXBUFFER **ppMaterials, // 메쉬 재질 정보LPD3DXBUFFER **ppEffectInstances, // 이펙트 개체 : 0PDWORD pNumMaterials, // 메쉬의 재질 수p ,LPD3DXMESH *ppMesh // 메쉬

)

애니메이션및 게임 실습 26

Page 27: Week04 DirectX9 프로그래밍의 기초2 - cfs7.tistory.comcfs7.tistory.com/upload_control/download.blog?fhandle=YmxvZzIwOTc5... · DirectX9 프로그래밍의기초2. 목차 XFile

XFile

재질

텍스처 데이터의 파일명 소유

typedef struct D3DXMATERIAL {

D3DMATERIAL9 MatD3D; // 재질 구조체LPSTR pTextureFileName; // 텍스처 파일명

}

애니메이션및 게임 실습 27

Page 28: Week04 DirectX9 프로그래밍의 기초2 - cfs7.tistory.comcfs7.tistory.com/upload_control/download.blog?fhandle=YmxvZzIwOTc5... · DirectX9 프로그래밍의기초2. 목차 XFile

XFile

정점 법선 생성

조명을 위해 정점 법선 생성 필요

HRESULT D3DXC t N lHRESULT D3DXComputeNormals(

LPD3DXBASEMESH pMesh, // 메쉬const DWORD *pAdjaceny // 인접 정보

법선 평균 이용인접 정보를 이용하여 중복 정점 제거

p j y)

인접 정보를 이용하여 중복 정점 제거인접 정보 부재시 중복 정점도 같이 계산

정점 포맷 : D3DFVF_NORMAL

애니메이션및 게임 실습 28

Page 29: Week04 DirectX9 프로그래밍의 기초2 - cfs7.tistory.comcfs7.tistory.com/upload_control/download.blog?fhandle=YmxvZzIwOTc5... · DirectX9 프로그래밍의기초2. 목차 XFile

XFile

정점 법선 생성

// 메쉬가 정점 포맷으로 D3DFVF_NORMAL을 가지고 있는가?if(!( M h G tFVF() & D3DFVF NORMAL))if(!(pMesh->GetFVF() & D3DFVF_NORMAL)){

// 새 메쉬를 복제하고 포맷으로 D3DFVF_NORMAL 추가ID3DXMesh* pTempMesh = 0;p p ;pMesh->CloneMeshFVF(

D3DXMESH_MANAGED,pMesh->GetFVF() | D3DFVF_NORMAL,D iDevice,&pTempMesh);

// 법선 계산D3DXComputeNormals(pTempMesh, 0);p (p p , );

pMesh->Release(); // 기존 메쉬 제거pMesh = pTempMesh; // 새 메쉬 저장

}

애니메이션및 게임 실습 29

}

Page 30: Week04 DirectX9 프로그래밍의 기초2 - cfs7.tistory.comcfs7.tistory.com/upload_control/download.blog?fhandle=YmxvZzIwOTc5... · DirectX9 프로그래밍의기초2. 목차 XFile

XFile

예제

애니메이션및 게임 실습 30

Page 31: Week04 DirectX9 프로그래밍의 기초2 - cfs7.tistory.comcfs7.tistory.com/upload_control/download.blog?fhandle=YmxvZzIwOTc5... · DirectX9 프로그래밍의기초2. 목차 XFile

경계 볼륨

경계 볼륨

원기둥, 타원면, 마름모꼴, 캡슐형

구 상자구, 상자

애니메이션및 게임 실습 31

Page 32: Week04 DirectX9 프로그래밍의 기초2 - cfs7.tistory.comcfs7.tistory.com/upload_control/download.blog?fhandle=YmxvZzIwOTc5... · DirectX9 프로그래밍의기초2. 목차 XFile

경계 볼륨

경계 볼륨

가시성 테스트

메쉬의 경계 볼륨이 보이지 않는다면 메쉬 역시 보이지 않음메쉬의 경계 볼륨이 보이지 않는다면 메쉬 역시 보이지 않음

충돌 테스트

미사일과 메쉬의 경계 볼륨간의 충돌 검출

애니메이션및 게임 실습 32

Page 33: Week04 DirectX9 프로그래밍의 기초2 - cfs7.tistory.comcfs7.tistory.com/upload_control/download.blog?fhandle=YmxvZzIwOTc5... · DirectX9 프로그래밍의기초2. 목차 XFile

경계 볼륨

경계 볼륨

HRESULT D3DXComputeBoundingSphere(LPD3DXVECTOR3 Fi tP iti // 정점 배열의 첫번째 정점LPD3DXVECTOR3 pFirstPosition, // 정점 배열의 첫번째 정점DWORD NumVertices, // 정점의 수DWORD dwStride, // 정점 저장 크기D3DXVECTOR3* pCenter, // 경계 구체의 중심p ,FLOAT* pRadius // 경계 구체의 반지름

);

HRESULT D3DXComputeBoundingBox(LPD3DXVECTOR3 pFirstPosition, // 정점 배열의 첫번째 정점DWORD NumVertices, // 정점의 수DWORD dwStride, // 정점 저장 크기D3DXVECTOR3* pMin, // 최소점D3DXVECTOR3* pMax // 최대점

);

애니메이션및 게임 실습 33

);

Page 34: Week04 DirectX9 프로그래밍의 기초2 - cfs7.tistory.comcfs7.tistory.com/upload_control/download.blog?fhandle=YmxvZzIwOTc5... · DirectX9 프로그래밍의기초2. 목차 XFile

경계 볼륨

예제

애니메이션및 게임 실습 34

Page 35: Week04 DirectX9 프로그래밍의 기초2 - cfs7.tistory.comcfs7.tistory.com/upload_control/download.blog?fhandle=YmxvZzIwOTc5... · DirectX9 프로그래밍의기초2. 목차 XFile

Question?Question?Question?Question?

애니메이션및 게임 실습 35