按自己的思路整一整程序(3)

terrain.h terrain.cpp
建立一个地形类:类图
 
概述:地形需要的属性和方法
属性:
范围,x,y方向: m_xscale,m_yscale
高度图数组:   m_heightmap[ ][ ]
纹理对象:    LPDirect3DTexture9 m_texture
材质:         m_meterial??(是否有纹理即不需要材质?)
-------6月18日追加-------
terrain类应该有的成员
1,IDirect3DDevice9*       _device;(?IDirect3D9接口是用来得到设备的功能以及获得IDirect3DDevice9接口,而IDirect3DDevice9是用于渲染的。方法最多的一个接口。为什么terrain类要这个device私有对象呢?
从一般的观点来看IDirect3DDevice9是表示3D设备,全局唯一的一个3D设备。样例中的是有一个全局的IDirect3DDevice9,然后作为参数传给terrain类的构造函数。然后terrain即可用此device进行creatvertexbuffer等操作。
TheTerrain = new Terrain(Device, "coastMountain64.raw", 110, 110, 10, 0.5f);
~~~~~引用msdn~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

一个接口可从一个或多个基接口继承。在下例中,接口 IMyInterface 从两个基接口 IBase1IBase2 继承:

interface IMyInterface: IBase1, IBase2
{
   void MethodA();
   void MethodB();
}

接口可以由类和结构实现。实现的接口的标识符出现在类的基列表中。例如:

class Class1: Iface1, Iface2
{
   // class members
}
~~~~~~~~~end~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
IDirecxt3DDevice9接口继承IUnknown接口,IUnknown 有几个方法。
把IDirect3DDevice9作为私有成员,(应该来说,不用其作私有成员也可以。(试试)把IDirect3DDevice9作为私有成员的好处是,draw函数就不需要device参数了!!!!直接用device成员)
 
2,vertex buffer;index buffer:确实这两个是对一个确定的对象而言的。应该是其私有成员。
3,其他```(漏这么多ToT!!!!)
 
 int _cellSpacing;     
 int _numCellsPerRow;  _numVertsPerRow - 1
 int _numCellsPerCol; _numVertsPerCol - 1
 int _width; _width = _numCellsPerRow * _cellSpacing;
 int _depth;
 int _numVertices;
_numVertices  = _numVertsPerRow * _numVertsPerCol;

 int _numTriangles; _numCellsPerRow * _numCellsPerCol * 2;
 float _heightScale;(灰度图灰度值的除数,用于控制地形的突兀程度,越大地形表现的越平坦)
imageData[i * lockedRect.Pitch / 4 + j] = (D3DCOLOR)c;
D3DLOCKED_RECT
It now refers to the number of bytes in a row of blocks
 
------end 6月18日追加----
 
 
方法:
画地形: draw() 描述:CreatVertexBuffer(),CreatIndexBuffer(),DrawPrimitive()
读heightmap: loadHeightmap()
 
-----6月18日追加---------
 
------end 6月18日追加----
 
 
----------------回顾--------------
纹理寻址

Wrap Texture Address Mode

 

 

------------学习--------------------

texture warping (SDK: Texture Wrapping)

 

By definition, texture wrapping causes the rasterizer to take the shortest route between texture coordinate sets, assuming that 0.0 and 1.0 are coincident. The last bit is the tricky part: You can imagine that enabling texture wrapping in one direction causes the system to treat a texture as though it were wrapped around a cylinder. For example, consider the following illustration.

 

不明白的几个地方:

1,texture warping的纹理光栅化时,面向的单元不再是三角形的primitive了,而是这样一个圆柱体,或者立方体??

先放一放,以后再查其他资料详细了解。

 

明白了的几个地方:

1,texture warping 和warp mode的区别:先进行texture warping后进行warp mode,texture warping 的取值不会超过(0,1)的范围。

 

 

-------------6月18日追加------------------------------------------

texture wrapping 再仔细看了下SDK,其中有一句话

Enabling u-texture or v-texture coordinate wrapping changes how Direct3D perceives the shortest route between texture coordinates in the u-direction and v-direction

 

 

也就是说:在进行光栅化插值的时候。A,B之间光栅化插值所选取的路径不再是沿着这个纹理表面;而是穿过了seam(纹理卷起来的接合线)。

 

综上所述,回答问题1,应该来说,texture wrapping面向的还是三角形的primitive,只是在进行光栅化的时候,对于u,v值,然后进行插值的时候,如果可以找到渲染标识为texture wrapping,就采用texture wrapping 的插值方式。

 

以后有时间,尝试使用使用此技术。

 

原文:

This diagram shows how wrapping in the u - direction affects how the system interpolates texture coordinates. Using the same points as in the example for normal, or nonwrapped, textures, you can see that the shortest route between points A and B is no longer across the middle of the texture; it's now across the border where 0.0 and 1.0 exist together. Wrapping in the v-direction is similar, except that it wraps the texture around a cylinder that is lying on its side. Wrapping in both the u-direction and v-direction is more complex. In this situation, you can envision the texture as a torus, or doughnut.

-------------end 6月18日追加------------------------------------------

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值