DirecX学习一:重新认识D3DFVF_XYZRHW、D3DPT_POINTLIST、D3DPT_LINELIST

D3DFVF_XYZRHW:

之前都没有深入了解D3DFVF_XYZRHW,昨天开始认真做了下实验,D3DFVF_XYZRHW小小参数,包含了挺多东西的:

DirectX and XNA解释:

Vertex fromat includes the position of a transformed vertex.This flag cannot be used with the D3DFVF_XYZ or D3DFVF_NORMAL flags

D3DFVF_XYZRHW该格式:指示使用sizeof(float) * 4的空间。


也就是说D3DFVF_XYZRHW所输入的数值就是屏幕空间的坐标值,不再需要进行坐标转换。D3DFVF_XYZRHW不支持与D3DFVF_XYZ、D3DFVF_NORMAL共同使用。

RHW这个值的说明:

If you use D3DFVF_XYZRHW, then your vertex format needs to have 4 floats in it, for x, y, z and rhw. X and Y are used to define a vertex position in 2D space, 
Z is  ignored (I think, it may be used for fog and such, but I don't recall just now - I always set it to 0.0f), and rhw is the Reciprocal of Homogenous W - which is 
basically 1 / the depth of the vertex.

[1] RHW表示投影空间中顶点所在的齐次点(x,y,z,w)(homogeneous point)的w坐标的倒数(reciprocal)。

rhw就是w的倒数,可以认为w是一个系数,用以将一个n次元空间扩展到n+1次元空间,这里重要的就是齐次坐标的概念,当w为1的时候,就是在齐次空间中的原n次元空间,
当w小于1时,其影射到n次元空间时将被放大,当w大于1时,影射到n次元空间将会被缩小...,当w等于0时,表示一个无限远点...

使用D3DPT_LINELIST实验Z、RHW值在D3DFVF_XYZRHW中起的作用:

D3DFVF_CUSTOMVERTEX = (D3DFVF_XYZRHW|D3DFVF_DIFFUSE)

struct CUSTOMVERTEX
{
     float x, y, z, rhw;
     DWORD color;
};

顶点数据:
{ 50.f, 250.f, 0.5f, 1.f, 0xff00ffff,},
{150.f,  50.f, 0.5f, 1.f, 0xffff0000,},
{250.f, 250.f, 0.5f, 1.f, 0xff00ff00,},
{350.f,   50.f, 0.5f, 1.f, 0xff0000ff,},
{450.f, 250.f, 0.5f, 1.f, 0xffff00ff,}

1. Z值作用:既然D3DFVF_XYZRHW所得到的值是转换后的坐标值,那么z值合理范围[0.f, 1.f],Z值超出此范围的点将被裁减掉。

                      结论:a. Z值超出[0.f, 1.f],该点被裁减

                                  b. 在同一点上,Z值得大小没有作用。虽然已经启用了ZBuffer。


2. RHW值作用:当相邻顶点的RHW值相同时,看不出差别。但是,使用戈劳德着色模式,相邻顶点的颜色差值将偏向RHW值高的一边,也就是说RHW高的一边在图元渲染的过程中占据较多的比重,该颜色看见的范围也大。如果某个点的RHW值为0,则直接使用另一个顶点的颜色值。


D3DFVF_POINTLIST:

Your application can use them in 3D scenes for star fields, or dotted lines on the surfaces of a polygon.
The colors in the materials or texture appear only at the points drawn, and not anywhere between the points

D3DFVF_LINELIST:

You can apply materials and textures to a line list.The colors in the materials or textures appear only along the lines drawn, not at any point in between 
the lines.
Line lists are useful for such tasks as adding sleet or heavy rain to a 3D scene.
注意:绘制直线图元时,顶点的数量必须为2的倍数,否则奇数点不被绘制。使用DrawPrimitive(D3DFVF_LINELIST, 0, 直线个数); (直线个数:顶点个数 / 2, 不含奇数点个数)



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值