-
Notifications
You must be signed in to change notification settings - Fork 0
/
CGeom.h
154 lines (115 loc) · 4.96 KB
/
CGeom.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
//--------------------------------------------------------------------------------------
// File: MeshUtils.cpp
//
// Mesh processing utilities
// this file contains mesh load routines
// in the future it will contain code to generate additional supporting geometry
// such as degenerate quads used for smoothies, or Haines style plateus.
//
//--------------------------------------------------------------------------------------
// (C) 2005 ATI Research, Inc., All rights reserved.
//--------------------------------------------------------------------------------------
#pragma once
#ifndef CGEOM_H
#define CGEOM_H
#include "ObjReader.h"
#include "LocalDXUT\\dxstdafx.h"
#include "types.h"
#include "VectorMacros.h"
//do not allow "dxstdafx.h" to depricate any core string functions
#pragma warning( disable : 4995 )
#define MAX_GEOM_OBJECTS 1000
#define ADJACENCY_EPSILON 0.0001f
//IB/VB created manually by the application
#define GEOM_SOURCE_MANUAL 0
//IB/VB stored in an ID3DXMesh
#define GEOM_SOURCE_D3DXMESH 1
//CGeom stores object information as either a ID3DXMesh or as explicit IB/VB
// the resons for supporting explicit VB/IB is to allow for rendering of line based objects
// such as a cube outline, or a frustum outline
class CGeom
{
public:
bool8 m_bInit;
IDirect3DDevice9 *m_pDevice;
uint32 m_uGeomSource; //source of geometry
uint32 m_GeomListIdx; //index of this object in the geometry list
ID3DXMesh *m_pMesh; //mesh structure to store geometry
uint32 m_uNumVertices;
uint32 m_uNumIndices;
uint32 m_uNumOutlineIndices;
uint32 m_uOffset; //offset into vertex buffer
uint32 m_uStride; //stride between vertex buffer elements
DWORD m_FVF;
D3DXVECTOR3 m_BBoxMin; //bounding box min
D3DXVECTOR3 m_BBoxMax; //bounding box max
D3DXVECTOR3 m_CenterPoint; //centerpoint
LPDIRECT3DINDEXBUFFER9 m_pibIndices;
LPDIRECT3DINDEXBUFFER9 m_pibOutlineIndices;
LPDIRECT3DVERTEXBUFFER9 m_pvbVertices;
CGeom(void);
~CGeom();
HRESULT Init(IDirect3DDevice9 *a_pDevice);
HRESULT LoadMesh(IDirect3DDevice9 *a_pDevice, WCHAR* a_Filename);
HRESULT LoadDotX(WCHAR *a_Filename);
HRESULT SaveDotX(WCHAR *a_Filename);
HRESULT LoadObj(WCHAR *a_Filename);
HRESULT GenerateQuad(void);
HRESULT GenerateCube(void);
HRESULT GenerateSphere(IDirect3DDevice9 *a_pDevice, float32 a_Radius, uint32 a_Slices, uint32 a_Stacks);
HRESULT GenerateShadowVolumeMesh(CGeom *a_InputMesh);
HRESULT GenerateDegenEdgeQuads(CGeom *a_InputMesh);
HRESULT GenerateSmoothieQuads(CGeom *a_InputMesh);
HRESULT GenerateSmoothieQuadsTex(CGeom *a_InputMesh);
HRESULT GenerateBaryTestMesh(CGeom *a_InputMesh);
HRESULT GenerateDegenQuadsDualPos(CGeom *a_InputMesh);
HRESULT AddCompPRTVertexData(LPD3DXPRTCOMPBUFFER a_CompPrtBuffer);
HRESULT GenerateCPCAPRTMesh(CGeom *a_InputMesh, LPD3DXPRTCOMPBUFFER a_CompPRTBuffer);
HRESULT GenerateLDPRTMesh(CGeom *a_InputMesh, LPD3DXPRTBUFFER a_PRTBuffer);
HRESULT Draw(void);
HRESULT DrawOutline(void);
void OnResetDevice(void);
void OnLostDevice(void);
void OnDestroyDevice(void);
void SafeRelease(void);
};
//edge structure : adapted from D3D ShadowVolumes Example
struct CEdgeMapping
{
public:
int m_anOldEdge[2]; // vertex index of the original edge
int m_aanNewEdge[2][2]; // vertex indexes of the new edge
// First subscript = index of the new edge
// Second subscript = index of the vertex for the edge
CEdgeMapping()
{
FillMemory( m_anOldEdge, sizeof(m_anOldEdge), -1 );
FillMemory( m_aanNewEdge, sizeof(m_aanNewEdge), -1 );
}
};
//from the .obj file
struct SSphereVert
{
D3DXVECTOR3 m_Position; //Position
D3DXVECTOR3 m_VertexNormal; //Vertex normal
D3DXVECTOR2 m_TexCoord; //Tex coords
D3DXVECTOR3 m_TangentU; //TangentU
D3DXVECTOR3 m_TangentV; //TangentV
const static D3DVERTEXELEMENT9 Decl[6];
};
//from the .obj file
struct FROMOBJVERT
{
D3DXVECTOR3 Position; //Position
D3DXVECTOR3 VertexNormal; //Vertex normal
D3DXVECTOR2 TexCoord; //Tex coords
D3DXVECTOR3 TangentU; //TangentU
D3DXVECTOR3 TangentV; //TangentV
const static D3DVERTEXELEMENT9 Decl[6];
};
void GeomListOnResetDevice(void);
void GeomListOnLostDevice(void);
void GeomListOnDestroyDevice(void);
//used for generating degenerate edge quads
int FindEdgeInMappingTable(int nV1, int nV2, CEdgeMapping *pMapping, int nCount );
#endif //CGEOM_H