zyb_debug
posts - 15, comments - 30, trackbacks - 0, articles - 0
首页
新随笔
联系
管理
聚合
材质和灯光的辅助函数
http://hi.baidu.com/zyb_debug/blog/item/aee40a12b5877c896438db9d.html
不多说了,龙书的材质灯光函数。可重用代码
//
=========================================
/**/
/*
*
@brief
@param 定义一些颜色常量
@return
*/
//
=========================================
const
D3DXCOLOR WHITE(D3DCOLOR_XRGB(
255
,
255
,
255
));
const
D3DXCOLOR BLACK(D3DCOLOR_XRGB(
0
,
0
,
0
));
const
D3DXCOLOR RED(D3DCOLOR_XRGB(
255
,
0
,
0
));
const
D3DXCOLOR GREEN(D3DCOLOR_XRGB(
0
,
255
,
0
));
const
D3DXCOLOR BLUE(D3DCOLOR_XRGB(
0
,
0
,
255
));
const
D3DXCOLOR YELLOW(D3DCOLOR_XRGB(
255
,
255
,
0
));
const
D3DXCOLOR CYAN(D3DCOLOR_XRGB(
0
,
255
,
255
));
const
D3DXCOLOR MAGENTA(D3DCOLOR_XRGB(
255
,
0
,
255
));
D3DMATERIAL9 InitMtrl(D3DXCOLOR a,D3DXCOLOR d,D3DXCOLOR s,D3DXCOLOR e,
float
p);
//
=========================================
/**/
/*
*
@brief
@param 定义一些基本常用材质
@return
*/
//
=========================================
const
D3DMATERIAL9 WHITE_MTRL
=
InitMtrl(WHITE,WHITE,WHITE,BLACK,
8.0f
);
const
D3DMATERIAL9 RED_MTRL
=
InitMtrl(RED,RED,RED,BLACK,
8.0f
);
const
D3DMATERIAL9 GREEN_MTRL
=
InitMtrl(GREEN,GREEN,GREEN,BLACK,
8.0f
);
const
D3DMATERIAL9 BLUE_MTRL
=
InitMtrl(BLUE,BLUE,BLUE,BLACK,
8.0f
);
const
D3DMATERIAL9 YELLOW_MTRL
=
InitMtrl(YELLOW,YELLOW,YELLOW,BLACK,
8.0f
);
//
=========================================
/**/
/*
*
@brief
@param 灯光
@return
*/
//
=========================================
D3DLIGHT9 InitDirectionalLight(D3DXVECTOR3
*
direction, D3DXCOLOR
*
color);
D3DLIGHT9 InitPointLight(D3DXVECTOR3
*
position, D3DXCOLOR
*
color);
D3DLIGHT9 InitSpotLight(D3DXVECTOR3
*
position, D3DXVECTOR3
*
direction, D3DXCOLOR
*
color);
//
=========================================
/**/
/*
*
@brief
@param 初始化材质
@return
*/
//
=========================================
D3DMATERIAL9 InitMtrl(D3DXCOLOR a,D3DXCOLOR d,D3DXCOLOR s,D3DXCOLOR e,
float
p)
{
D3DMATERIAL9 mtrl;
mtrl.Ambient
=
a;
mtrl.Diffuse
=
d;
mtrl.Specular
=
s;
mtrl.Emissive
=
e;
mtrl.Power
=
p;
return
mtrl;
}
//
=========================================
/**/
/*
*
@brief
@param 灯光
@return
*/
//
=========================================
D3DLIGHT9 InitDirectionalLight(D3DXVECTOR3
*
direction, D3DXCOLOR
*
color)
{
D3DLIGHT9 light;
::ZeroMemory(
&
light,
sizeof
(light));
light.Type
=
D3DLIGHT_DIRECTIONAL;
light.Ambient
=
*
color
*
0.4f
;
light.Diffuse
=
*
color;
light.Specular
=
*
color
*
0.6f
;
light.Direction
=
*
direction;
return
light;
}
D3DLIGHT9 InitPointLight(D3DXVECTOR3
*
position, D3DXCOLOR
*
color)
{
D3DLIGHT9 light;
::ZeroMemory(
&
light,
sizeof
(light));
light.Type
=
D3DLIGHT_POINT;
light.Ambient
=
*
color
*
0.4f
;
light.Diffuse
=
*
color;
light.Specular
=
*
color
*
0.6f
;
light.Position
=
*
position;
light.Range
=
1000.0f
;
light.Falloff
=
1.0f
;
light.Attenuation0
=
1.0f
;
light.Attenuation1
=
0.0f
;
light.Attenuation2
=
0.0f
;
return
light;
}
D3DLIGHT9 InitSpotLight(D3DXVECTOR3
*
position, D3DXVECTOR3
*
direction, D3DXCOLOR
*
color)
{
D3DLIGHT9 light;
::ZeroMemory(
&
light,
sizeof
(light));
light.Type
=
D3DLIGHT_SPOT;
light.Ambient
=
*
color
*
0.4f
;
light.Diffuse
=
*
color;
light.Specular
=
*
color
*
0.6f
;
light.Position
=
*
position;
light.Direction
=
*
direction;
light.Range
=
1000.0f
;
light.Falloff
=
1.0f
;
light.Attenuation0
=
1.0f
;
light.Attenuation1
=
0.0f
;
light.Attenuation2
=
0.0f
;
light.Theta
=
0.5f
;
light.Phi
=
0.7f
;
return
light;
}
}
Posted on 2009-08-15 17:15
zyb_debug
阅读(1081)
评论(0)
编辑
收藏
引用
只有注册用户
登录
后才能发表评论。
【推荐】100%开源!大型工业跨平台软件C++源码提供,建模,组态!
网站导航:
博客园
IT新闻
BlogJava
博问
Chat2DB
管理
留言簿
(2)
给我留言
查看公开留言
查看私人留言
随笔档案
(15)
2009年9月 (10)
2009年8月 (5)
相册
default
搜索
最新评论
1. re: 理解SkinWeights 骨骼动画
GameDev上总会有人在n年前讨论过我们现在遇到的问题……尤其是3D渲染以外的那些不好找资料的……
--柒笑侠
2. re: 扩充完路径库
评论内容较长,点击标题查看
--zyb_debug
3. re: 扩充完路径库
@路过
我错了,知道了。
--zyb_debug
4. re: 扩充完路径库
已经移出首页。
cppblog基本上比较自由,是否发首页由作者自己决定,发的时候最好斟酌下,谢谢!
--cppexplore
5. re: 扩充完路径库
评论内容较长,点击标题查看
--路过
阅读排行榜
1. 关于while(cin)(2096)
2. 理解SkinWeights 骨骼动画(1951)
3. (转)预编译头文件(1851)
4. 实作ADTvector2 vector3 vector4 matrix44 matrix33(1586)
5. 扩充D3DXMESHCONTAINER和D3DXFrame(1384)
评论排行榜
1. 扩充完路径库(8)
2. 解析xfile 结束 找出问题了 恢复CEGUI渲染状态(4)
3. 实作ADTvector2 vector3 vector4 matrix44 matrix33(4)
4. 上自习(3)
5. 一个灵活的camera类(3)