-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSkyBox.cpp
136 lines (93 loc) · 3.19 KB
/
SkyBox.cpp
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
// SkyBox.cpp: implementation of the CSkyBox class.
//
//////////////////////////////////////////////////////////////////////
#include "SkyBox.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CSkyBox::CSkyBox()
{
pTex = NULL;
pMesh = NULL;
}
CSkyBox::~CSkyBox()
{
}
//--------------------------------------------------------------------------
// Name:
// Desc:
//--------------------------------------------------------------------------
HRESULT CSkyBox::Init(LPDIRECT3DDEVICE9 device, LPD3DXEFFECT g_pEffect, LPCWSTR meshpath)
{
//setting device
m_pd3dDevice = device;
m_pEffect = g_pEffect;
LPD3DXMESH dummy;
//loading mesh
if(FAILED( D3DXLoadMeshFromX(meshpath,
D3DXMESH_MANAGED,
m_pd3dDevice,
0,
0,
0,
0,
&dummy)))
return E_FAIL;
dummy->CloneMeshFVF( D3DXMESH_MANAGED, SBVERTEX_FVF, m_pd3dDevice, &pMesh );
dummy->Release();
return S_OK;
}
//--------------------------------------------------------------------------
// Name:
// Desc:
//--------------------------------------------------------------------------
HRESULT CSkyBox::Render(D3DXVECTOR3 CameraCoord, float m_fElapsedTime, D3DXMATRIX* AdditionalMatrix,
D3DXMATRIX matView, D3DXMATRIX matProj)
{
DWORD i;
//setting matrix
D3DXMATRIX trans;
D3DXMatrixTranslation( &trans, CameraCoord.x, CameraCoord.y, CameraCoord.z);
if( AdditionalMatrix != NULL ) //D3DXMatrixMultiply(&trans, &trans, AdditionalMatrix);
trans = (*AdditionalMatrix) * trans;
//m_pd3dDevice->SetTransform( D3DTS_WORLD, &trans);
m_pEffect->SetMatrix( "mViewProj", &(matView * matProj) );
m_pEffect->SetMatrix( "mWorld", &trans);
m_pd3dDevice->SetRenderState( D3DRS_LIGHTING, FALSE );
m_pd3dDevice->SetRenderState( D3DRS_ZWRITEENABLE, FALSE );
m_pd3dDevice->SetRenderState(D3DRS_SRCBLEND,D3DBLEND_SRCALPHA);
m_pd3dDevice->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_INVSRCALPHA);
m_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE,TRUE);
m_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSU, D3DTADDRESS_MIRROR );
m_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSV, D3DTADDRESS_MIRROR );
if(FAILED(m_pEffect->SetTexture( "tColorMap", pTex))) return E_FAIL;
m_pEffect->CommitChanges();
for( i = 0; i < pMesh->GetNumFaces(); i++)
pMesh->DrawSubset(i);
m_pd3dDevice->SetRenderState( D3DRS_ZWRITEENABLE, TRUE );
m_pd3dDevice->SetRenderState( D3DRS_LIGHTING, TRUE );
m_pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, FALSE);
return S_OK;
}
//--------------------------------------------------------------------------
// Name:
// Desc:
//--------------------------------------------------------------------------
HRESULT CSkyBox::LoadTexture(LPCWSTR temp)
{
if( pTex != NULL) pTex->Release();
D3DXCreateTextureFromFile(m_pd3dDevice,
temp,
&pTex);
return S_OK;
}
//--------------------------------------------------------------------------
// Name:
// Desc:
//--------------------------------------------------------------------------
HRESULT CSkyBox::Release()
{
if(pMesh != NULL) pMesh->Release();
if(pTex != NULL) pTex->Release();
return S_OK;
}