9. cNodeTreeMesh::IsPolygonContained

 

 

BOOL cNodeTreeMesh::IsPolygonContained(sPolygon *Polygon, /

float XPos, float YPos, float ZPos, /

float Size)

{

float XMin, XMax, YMin, YMax, ZMin, ZMax;

sVertex *Vertex[3];

// Get the polygons vertices

Vertex[0] = (sVertex*)&m_VertexPtr[m_VertexSize * /

Polygon->Vertex[0]];

Vertex[1] = (sVertex*)&m_VertexPtr[m_VertexSize * /

Polygon->Vertex[1]];

Vertex[2] = (sVertex*)&m_VertexPtr[m_VertexSize * /

Polygon->Vertex[2]];

// Check the X-axis of specified 3-D space

XMin = min(Vertex[0]->x, min(Vertex[1]->x, Vertex[2]->x));

XMax = max(Vertex[0]->x, max(Vertex[1]->x, Vertex[2]->x));

if(XMax < (XPos - Size / 2.0f))

return FALSE;

if(XMin > (XPos + Size / 2.0f))

return FALSE;

 

这段代码(包括接下来的代码)决定了一个顶点在x轴的最远范围。如果多边形被验证为在盒子中太远,返回FALSE。同样的,其他两个轴:

// Check the Y-axis of specified 3-D space (if octree)

if(m_TreeType == OCTREE) {

YMin = min(Vertex[0]->y, min(Vertex[1]->y, Vertex[2]->y));

YMax = max(Vertex[0]->y, max(Vertex[1]->y, Vertex[2]->y));

if(YMax < (YPos - Size / 2.0f))

return FALSE;

if(YMin > (YPos + Size / 2.0f))

return FALSE;

}

// Check the Z-axis of specified 3-D space

ZMin = min(Vertex[0]->z, min(Vertex[1]->z, Vertex[2]->z));

ZMax = max(Vertex[0]->z, max(Vertex[1]->z, Vertex[2]->z));

if(ZMax < (ZPos - Size / 2.0f))

return FALSE;

if(ZMin > (ZPos + Size / 2.0f))

return FALSE;

return TRUE;

}

unsigned long cNodeTreeMesh::CountPolygons( /

float XPos, float YPos, float ZPos, float Size)

{

unsigned long i, Num;

// Return if no polygons to process

if(!m_NumPolygons)

return 0;

// Go through every polygon and keep count of those

// contained in the specified 3-D space.

Num = 0;

for(i=0;i<m_NumPolygons;i++) {

if(IsPolygonContained(&m_PolygonList[i],XPos,YPos,ZPos, /

Size) == TRUE)

Num++;

}

return Num;

}

 

你可以看到,CountPolygons循环只有在通网格的每个多边形,并验证验证他是否在盒子里边。每个多边形包含他的数目,和返回一个最后记录。你使用这个函数,当分裂和保存节点时要决定在一个节点中有多少多边形。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值