www.pudn.com > roam.rar > Patch.h
// Patch.h: interface for the Patch class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_PATCH_H__557A5E51_212C_495E_9FBF_E72A4E41B0AD__INCLUDED_)
#define AFX_PATCH_H__557A5E51_212C_495E_9FBF_E72A4E41B0AD__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "math.h"
// Predefines...
class Landscape;
// Depth of variance tree: should be near SQRT(PATCH_SIZE) + 1
#define VARIANCE_DEPTH (10)
/////////////////////////////////
//////// 树结构 ///////////
/////////////////////////////////
struct TriTreeNode
{
TriTreeNode *LeftChild;
TriTreeNode *RightChild;
TriTreeNode *BaseNeighbor;
TriTreeNode *LeftNeighbor;
TriTreeNode *RightNeighbor;
};
class Patch
{
public:
virtual void Tessellate();
virtual void Render();
virtual void ComputeVariance();
// Some encapsulation functions & extras
TriTreeNode *GetBaseLeft() { return &m_BaseLeft; }
TriTreeNode *GetBaseRight() { return &m_BaseRight; }
char isDirty() { return m_VarianceDirty; }
int isVisibile( ) { return m_isVisible; }
virtual void SetVisibility( int eyeX, int eyeY, int leftX, int leftY, int rightX, int rightY );
virtual void Reset();
virtual void Init( int heightX, int heightY, int worldX, int worldY, double *hMap );
// The recursive half of the Patch Class
virtual void Split( TriTreeNode *tri);
virtual void RecursTessellate( TriTreeNode *tri, int leftX, int leftY, int rightX, int rightY, int apexX, int apexY, int node );
virtual void RecursRender( TriTreeNode *tri, int leftX, int leftY, int rightX, int rightY, int apexX, int apexY );
virtual unsigned char RecursComputeVariance( int leftX, int leftY, double leftZ,
int rightX, int rightY, double rightZ,
int apexX, int apexY, double apexZ,
int node);
Patch();
unsigned char m_isVisible; // Is this patch visible in the current frame?
virtual ~Patch();
protected:
int eyeX;
int eyeY;
double *m_HeightMap; // 指向高程数据的指针
int m_WorldX,m_WorldY; // 每一个字块偏移原始坐标的大小
unsigned char m_VarianceLeft[ 1<<(VARIANCE_DEPTH)]; // Left variance tree
unsigned char m_VarianceRight[1<<(VARIANCE_DEPTH)]; // Right variance tree
unsigned char *m_CurrentVariance; // Which varience we are currently using. [Only valid during the Tessellate and ComputeVariance passes]
unsigned char m_VarianceDirty; // Does the Varience Tree need to be recalculated for this Patch?
TriTreeNode m_BaseLeft; // Left base triangle tree node
TriTreeNode m_BaseRight; // Right base triangle tree node
};
#endif // !defined(AFX_PATCH_H__557A5E51_212C_495E_9FBF_E72A4E41B0AD__INCLUDED_)