-
Notifications
You must be signed in to change notification settings - Fork 1
/
Material.cpp
executable file
·146 lines (113 loc) · 3.46 KB
/
Material.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
137
138
139
140
141
142
143
144
145
146
// ***********************************************************************
//
// File: Material.cpp
// Programmer: T.J. Eason
// Project: Game Engine
// Description: Lighting and texture properties
// Date: 3-11-10
// Revision 1: 3-24-10
// Revision 2: 3-25-10
//
// ************************************************************************
#include "Engine.h"
// Material class constructor
Material::Material(): Resource < Material >( "noname", "nopath" )
{
// Empty texture
m_texture = NULL;
m_width = 0;
m_height = 0;
// Set lighting properites
m_lighting.Diffuse = D3DXCOLOR( 1.0f, 1.0f, 1.0f, 1.0f );
m_lighting.Ambient = D3DXCOLOR( 1.0f, 1.0f, 1.0f, 1.0f );
m_lighting.Specular = D3DXCOLOR( 0.0f, 0.0f, 0.0f, 0.0f );
m_lighting.Emissive = D3DXCOLOR( 0.0f, 0.0f, 0.0f, 0.0f );
m_lighting.Power = 0;
// Ignore face flag
m_ignoreFace = false;
// Ignore fog flag
m_ignoreFog = false;
// Ignore ray flag
m_ignoreRay = false;
}
// Material constructor
Material::Material( char *name, char *path ) : Resource< Material >( name, path )
{
D3DXIMAGE_INFO info;
// Load script
Script *script = new Script( name, path );
// Check if texture is transparent
if( script ->GetColorData( "transparency" ) ->a == 0.0f )
{
// Load texture without transparency
D3DXCreateTextureFromFileEx( g_engine ->GetDevice(), script ->GetStringData( "texture" ), D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0,
D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_FILTER_TRIANGLE, D3DX_FILTER_TRIANGLE, 0, &info, NULL, &m_texture );
}
else
{
// Load texture with transparency based on color value
D3DCOLORVALUE *color = script ->GetColorData( "transparency" );
D3DCOLOR transparency = D3DCOLOR_COLORVALUE( color ->r, color ->g, color ->b, color ->a );
D3DXCreateTextureFromFileEx( g_engine ->GetDevice(), script ->GetStringData( "texture"), D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0,
D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_FILTER_TRIANGLE, D3DX_FILTER_TRIANGLE, transparency, &info, NULL, &m_texture );
}
// Store texture's width and height
m_width = info.Width;
m_height = info.Height;
// Set lighting properties
m_lighting.Diffuse =*script ->GetColorData( "diffuse" );
m_lighting.Ambient = *script ->GetColorData( "ambient" );
m_lighting.Specular = *script ->GetColorData( "specular" );
m_lighting.Emissive = *script ->GetColorData( "emissive" );
m_lighting.Power = *script ->GetFloatData( "power" );
// Set ignore flags
m_ignoreFace = *script ->GetBoolData( "ignore_face" );
m_ignoreFog = *script ->GetBoolData( "ignore_fog" );
m_ignoreRay = *script ->GetBoolData( "ignore_ray" );
// Delete script
SAFE_DELETE( script );
}
// Material class destructor
Material::~Material()
{
if( m_texture )
{
m_texture ->Release();
m_texture = NULL;
}
}
// Get texture
IDirect3DTexture9 *Material::GetTexture()
{
return m_texture;
}
// Get lighting properties
D3DMATERIAL9 *Material::GetLighting()
{
return &m_lighting;
}
// Get texture width
unsigned long Material::GetWidth()
{
return m_width;
}
// Get texture height
unsigned long Material::GetHeight()
{
return m_height;
}
// Get ignore face flag
bool Material::GetIgnoreFace()
{
return m_ignoreFace;
}
// Get ignore fog flag
bool Material::GetIgnoreFog()
{
return m_ignoreFog;
}
// Get ignore ray flag
bool Material::GetIgnoreRay()
{
return m_ignoreRay;
}