zoukankan      html  css  js  c++  java
  • 龙书9 chapter13 14 地形绘制的过程和terrain类的实现、 粒子系统入门笔记

    地形笔记:

    实现过程关键点:1.高度图的读取(得到Y值)-->创建平面网格(得到x z值)-->生成vertex和index

                           2.纹理映射和预设light:创建空texture-->映射vertex对应的纹理坐标-->映射不同height对应的color-->根据lightDirection计算单位网格对应的明暗程度

                           3.camera的height:  得到单位网格中xz已知,推导出相应的y坐标

    高度图看成一个矩阵, 高度图 中元素需要>=vertex数

    camera的height:书中的计算没看明白, 这种方式也可求出height,即EE‘的长度为AA’乘以FE‘除以FA’

    例子中的terrain头文件:

    class Terrain
    {
    public:
    	Terrain(
    		IDirect3DDevice9* device,
    		std::string heightmapFileName, 
    		int numVertsPerRow,  
    		int numVertsPerCol, 
    		int cellSpacing,    // space between cells
    		float heightScale);   
    
    	~Terrain();
    
    	int  getHeightmapEntry(int row, int col);
    	void setHeightmapEntry(int row, int col, int value);
    
    	float getHeight(float x, float z);
    
    	bool  loadTexture(std::string fileName);
    	bool  genTexture(D3DXVECTOR3* directionToLight);
    	bool  draw(D3DXMATRIX* world, bool drawTris);
    
    private:
    	IDirect3DDevice9*       _device;
    	IDirect3DTexture9*      _tex;
    	IDirect3DVertexBuffer9* _vb;
    	IDirect3DIndexBuffer9*  _ib;
    
    	int _numVertsPerRow;
    	int _numVertsPerCol;
    	int _cellSpacing;
    
    	int _numCellsPerRow;
    	int _numCellsPerCol;
    	int _width;
    	int _depth;
    	int _numVertices;
    	int _numTriangles;
    	float _heightScale;//超越0-255的限制
    	std::vector<int> _heightmap;//vertex Y
    	// helper methods
    	bool  readRawFile(std::string fileName);//读取灰度图
    	bool  computeVertices();
    	bool  computeIndices();
    	bool  lightTerrain(D3DXVECTOR3* directionToLight);
    	float computeShade(int cellRow, int cellCol, D3DXVECTOR3* directionToLight);//计算单位网格中纹理在light方向光下的明暗程度
    
    	struct TerrainVertex//内嵌类 只与terrain使用
    	{
    		TerrainVertex(){}
    		TerrainVertex(float x, float y, float z, float u, float v)
    		{
    			_x = x; _y = y; _z = z; _u = u; _v = v;
    		}
    		float _x, _y, _z;
    		float _u, _v;
    		static const DWORD FVF;
    	};
    };
    

    粒子系统笔记:

    点精灵,单个点怎么映射纹理呢?? 两种模式:一.对应整个纹理  二.vertex FVF属性中有纹理坐标,对应纹理坐标;

    关键点:1.划分为若干片段的vertexBuffer,保证图形卡的充分利用。    cpu拷贝vertex数据到图形处理器中去,图形卡进行显示操作。

                 比如有10000个粒子vertex,我们创建一个2000vertex的buffer,划分为4个片段,定义片段索引index

                 将vertexBuffer指定为动态的,这样可以lock还没有绘制的buffer区域,同时不影响其他部分的绘

  • 相关阅读:
    四种PHP异步执行的常用方式
    PHP 多进程和多线程的优缺点
    试着用workerman开发一个在线聊天应用
    Python代码报错看不懂?记住这20个报错提示单词轻松解决bug
    PHP面试题大全(值得收藏)
    常见排序算法(三)
    常见排序算法(二)
    常见排序算法(一)
    NumPy 学习笔记(四)
    JavaScript 事件
  • 原文地址:https://www.cnblogs.com/dust-fly/p/4201284.html
Copyright © 2011-2022 走看看