⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lattice.h

📁 《3D游戏引擎设计》的源码
💻 H
字号:
#ifndef LATTICE_H
#define LATTICE_H

#include "coord.h"

class mgcLattice
{
public:
	// constructors, destructor
	mgcLattice (int _dimensions=0, const int* initial=0);
	mgcLattice (int _dimensions, int initial_all);
	mgcLattice (int _dimensions, int initial0, int initial1, ...);
	mgcLattice (const mgcLattice& lattice);
    ~mgcLattice ();

	// data acesss
	int Dimensions () const
		{ return dimensions; }
	const int* Bounds () const
		{ return bound; }
	int Bound (int d) const;
	int Quantity () const
		{ return quantity; }
	const int* Offsets () const
		{ return offset; }
	int Offset (int d) const
    	{ return offset[d]; }

	// assignment
	mgcLattice& operator= (const mgcLattice &lattice);

	// comparisons
	int operator== (const mgcLattice& lattice) const;
	int operator!= (const mgcLattice& lattice) const
		{ return !( *this == lattice ); }

	// conversions between n-dim and 1-dim structures
	int Index (int x, int y) const
		{ return x+bound[0]*y; }
	int Index (int x, int y, int z) const
		{ return x+bound[0]*(y+bound[1]*z); }
	int Index (int x, int y, int z, int w) const
		{ return x+bound[0]*(y+bound[1]*(z+bound[2]*w)); }
	int Index (const mgcCoordinate& coordinate) const;
	mgcCoordinate Coordinate (int index) const;

	// lattice measurements
	int BoundaryDistance (const mgcCoordinate& coordinate) const;
	int BoundaryDistance (int index) const;
	int BoundaryType (const mgcCoordinate& coordinate) const;
	int BoundaryType (int index) const;
	int ClampMin (int d, int i, int ofs) const;
	int ClampMax (int d, int i, int ofs) const;

	friend ostream& operator<< (ostream& ostr, const mgcLattice& lattice);

private:
	void Create (int _dimensions, const int* initial);
protected:
	int dimensions;
	int* bound;
	int quantity;
	int *offset;

// error handling
public:
	static int verbose;
	static unsigned error;
	static void Report (ostream& ostr);
private:
	static const unsigned allocation_failed;
	static const unsigned nonpositive_bound;
	static const unsigned zero_dimension;
	static const unsigned invalid_dimension;
	static const char* message[4];
	static int Number (unsigned single_error);
	static void Report (unsigned single_error);
};

#endif

⌨️ 快捷键说明

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