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

📄 roam.h

📁 体现了lod(level of detail)算法 包括网格细分,空间层次
💻 H
字号:
#ifndef ROAM_H
#define ROAM_H

#include "3DMath.h"
#include "glFrustum.h"

#define SQR(x) ((x) * (x))
#define MAX(a,b) ((a < b) ? (b) : (a))
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define DEG2RAD(a)	(((a) * M_PI) / 180.0f)
#define M_PI (3.14159265358979323846f)

#define TF_ALLOUT	1

extern int m_tris;
extern int count_nodes;//, max_nodes;

// TriTreeNode Struct
// Store the triangle tree data, but no coordinates!
struct TriNode
{
	TriNode *left_child;
	TriNode *right_child;
	TriNode *base_neigh;
	TriNode *left_neigh;
	TriNode *right_neigh;
	unsigned char flags;
};



//
// Patch Class
// Store information needed at the Patch level
class Patch
{
protected:
	unsigned char m_isVisible;	// Is this patch visible in the current frame?

public:
	float min, max;
	float m_pviewX, m_pviewY, m_pviewZ;
	int m_culls;

	BBOX box;
	
	bool collide;

	void CalculateBounds(int X, int Y);

	TriNode m_leftRoot;
	TriNode m_rightRoot;
	
	// Some encapsulation functions & extras
	TriNode *GetBaseLeft()  { return &m_leftRoot; }
	TriNode *GetBaseRight() { return &m_rightRoot; }

	int  isVisibile( ) { return m_isVisible; }
	void PatchCulling(float max, float min);
	bool PatchClipping(int leftX,		int leftY,
						int rightX,		int rightY,
						int apexX,		int apexY,
						float fcenterX,	float fcenterY,
						float min,		float max);
	
	void DrawBoxes(float max, float min);

	// The static half of the Patch Class
	void Init( int heightX, int heightY);
	void Reset();
	void Render(int X, int Y);

	// The recursive half of the Patch Class
	void		splitNode(TriNode *const target);

	void Tesselate(int X, int Y, float viewX, float viewY, float viewZ);

	void RecursTessellate(TriNode *tri, int level, 
							int leftX, int leftY, 
							int rightX, int rightY, 
							int apexX, int apexY);

	void RecursRender( TriNode *tri, int level, bool collide,
											int leftX, int leftY, 
											int rightX, int rightY, 
											int apexX, int apexY );
	void PerformCollide(CVector3 vTri[3]);

	float CheckCollision(float x, float y, int pX, int pY);

};

// Landscape Class
class Landscape
{
protected:
	Patch *m_Patches;

	float m_viewX, m_viewY, m_viewZ, radius;
	static int	m_NextTriNode;						// Index to next free TriTreeNode
	static TriNode *m_TriPool;						// Pool of TriTree nodes for splitting

	static int GetNextTriNode() { return m_NextTriNode; }
	static void SetNextTriNode( int nNextNode ) { m_NextTriNode = nNextNode; }

public:

	static TriNode *allocNode();
	void Init();
	void Reset(float threshold, float radius, float viewX, float viewY, float viewZ);
	void Tessellate();
	void Render();
	void Exit();
	void updateVariance();
	unsigned char updateVarianceRecurse(int apexX,int apexY,int leftX,int leftY,int rightX,int rightY);
	
	float clipPoint(float x, float y);
};
#endif

⌨️ 快捷键说明

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