本篇是创建游戏内核(6)【C风格版】的续篇,关于该内核的细节说明请参考创建游戏内核(7)。
接口:
void set_material_diffuse(D3DMATERIAL9_PTR material,
uchar red, uchar green, uchar blue);
void get_material_diffuse(const D3DMATERIAL9_PTR material,
uchar_ref red, uchar_ref green, uchar_ref blue);
void set_material_ambient(D3DMATERIAL9_PTR material,
uchar red, uchar green, uchar blue);
void get_material_ambient(const D3DMATERIAL9_PTR material,
uchar_ref red, uchar_ref green, uchar_ref blue);
void set_material_specular(D3DMATERIAL9_PTR material,
uchar red, uchar green, uchar blue);
void get_material_specular(const D3DMATERIAL9_PTR material,
uchar_ref red, uchar_ref green, uchar_ref blue);
void set_material_emissive(D3DMATERIAL9_PTR material,
uchar red, uchar green, uchar blue);
void get_material_emissive(const D3DMATERIAL9_PTR material,
uchar_ref red, uchar_ref green, uchar_ref blue);
实现:
//-------------------------------------------------------------------------
// set diffuse color.
//-------------------------------------------------------------------------
void set_material_diffuse(D3DMATERIAL9_PTR material,
uchar red, uchar green, uchar blue)
{
material->Diffuse.r = red / 255.0f;
material->Diffuse.g = green / 255.0f;
material->Diffuse.b = blue / 255.0f;
}
//-------------------------------------------------------------------------
// Get diffuse color.
//-------------------------------------------------------------------------
void get_material_diffuse(const D3DMATERIAL9_PTR material,
uchar_ref red, uchar_ref green, uchar_ref blue)
{
red = (uchar)(255.0 * material->Diffuse.r);
green = (uchar)(255.0 * material->Diffuse.g);
blue = (uchar)(255.0 * material->Diffuse.b);
}
//-------------------------------------------------------------------------
// set ambient color.
//-------------------------------------------------------------------------
void set_material_ambient(D3DMATERIAL9_PTR material,
uchar red, uchar green, uchar blue)
{
material->Ambient.r = red / 255.0f;
material->Ambient.g = green / 255.0f;
material->Ambient.b = blue / 255.0f;
}
//-------------------------------------------------------------------------
// Get ambient color.
//-------------------------------------------------------------------------
void get_material_ambient(const D3DMATERIAL9_PTR material,
uchar_ref red, uchar_ref green, uchar_ref blue)
{
red = (uchar)(255.0f * material->Ambient.r);
green = (uchar)(255.0f * material->Ambient.g);
blue = (uchar)(255.0f * material->Ambient.b);
}
//-------------------------------------------------------------------------
// set specular color.
//-------------------------------------------------------------------------
void set_material_specular(D3DMATERIAL9_PTR material,
uchar red, uchar green, uchar blue)
{
material->Specular.r = red / 255.0f;
material->Specular.g = green / 255.0f;
material->Specular.b = blue / 255.0f;
}
//-------------------------------------------------------------------------
// Get specular color.
//-------------------------------------------------------------------------
void get_material_specular(const D3DMATERIAL9_PTR material,
uchar_ref red, uchar_ref green, uchar_ref blue)
{
red = (uchar)(255.0 * material->Specular.r);
green = (uchar)(255.0 * material->Specular.g);
blue = (uchar)(255.0 * material->Specular.b);
}
//-------------------------------------------------------------------------
// set emissive color.
//-------------------------------------------------------------------------
void set_material_emissive(D3DMATERIAL9_PTR material,
uchar red, uchar green, uchar blue)
{
material->Emissive.r = red / 255.0f;
material->Emissive.g = green / 255.0f;
material->Emissive.b = blue / 255.0f;
}
//-------------------------------------------------------------------------
// Get emmisive color.
//-------------------------------------------------------------------------
void get_material_emissive(const D3DMATERIAL9_PTR material,
uchar_ref red, uchar_ref green, uchar_ref blue)
{
red = (uchar)(255.0 * material->Emissive.r);
green = (uchar)(255.0 * material->Emissive.g);
blue = (uchar)(255.0 * material->Emissive.b);
}