polygon.h

来自「<B>DirectX9.0 3D游戏编程</B>」· C头文件 代码 · 共 78 行

H
78
字号
/*******************************************************************
 *         Advanced 3D Game Programming using DirectX 9.0
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * copyright (c) 2003 by Peter A Walsh and Adrian Perez
 * See license.txt for modification and distribution information
 ******************************************************************/

#ifndef _POLYGON3_H
#define _POLYGON3_H

template <class type>
struct polygon 
{
	int nElem; // number of elements in the polygon
	int maxElem;

	type *pList;

	polygon()
	{
		nElem = 0;
		maxElem = 0;
		pList = NULL;
	}

	polygon( int maxSize )
	{
		maxElem = maxSize;
		pList = new type[maxSize];
	}

	polygon( const polygon &in )
	{
		CloneData( in );
	}

	~polygon()
	{
		DestroyData();
	}

	void CloneData( const polygon &in )
	{
		if( !in.pList ) 
			return;

		pList = new type[in.maxElem];
		maxElem = in.maxElem;
		nElem = in.nElem;
		for( int i=0; i<in.nElem; i++ )
		{
			pList[i] = in.pList[i];
		}
	}

	void DestroyData( )
	{
		if( pList )
		{
			delete[] pList;
		}
		pList = NULL;
	}

	polygon& operator=( const polygon<type> &in )
	{
		if( &in != this )
		{
			DestroyData();

			CloneData( in );
		}
		
		return *this;
	}
};

#endif /*_POLYGON3_H*/

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?