📄 mlrindexedtrianglecloud.cpp
字号:
dstPolygon.texCoords = clipBuffer[dstBuffer].texCoords.GetData();
dstPolygon.clipPerVertex = clipBuffer[dstBuffer].clipPerVertex.GetData();
dstPolygon.length = 0;
//
//-----------------------------------------------------------
// Spin through each plane that clipped the primitive and use
// it to actually clip the primitive
//-----------------------------------------------------------
//
mask = 1;
MLRClippingState theNewOr(0);
int loop = 4;
#if HUNT_CLIP_ERROR
for(k=0;k<srcPolygon.length;k++)
{
DEBUG_STREAM << setiosflags( ios::scientific) << setprecision(20)
<< srcPolygon.coords[k].x << " "
<< srcPolygon.coords[k].y << " "
<< srcPolygon.coords[k].z << " "
<< srcPolygon.coords[k].w << '\n';
}
#endif
#if HUNT_CLIP_ERROR
DEBUG_STREAM << "TheOriginalOR: " << hex << theOr.GetClippingState() << dec << '\n';
#endif
do
{
for(l=0; l<MLRClippingState::NextBit; l++)
{
if(theOr.IsClipped(mask))
{
//
//-----------------------------------
// Clip each vertex against the plane
//-----------------------------------
//
#if HUNT_CLIP_ERROR
DEBUG_STREAM << l << ": " << '\n';
#endif
for(k=0;k<srcPolygon.length;k++)
{
k1 = (k+1) < srcPolygon.length ? k+1 : 0;
theTest = srcPolygon.clipPerVertex[k];
//
//----------------------------------------------------
// If this vertex is inside the viewing space, copy it
// directly to the clipping buffer
//----------------------------------------------------
//
if(theTest.IsClipped(mask) == 0)
{
firstIsIn = true;
dstPolygon.coords[dstPolygon.length] =
srcPolygon.coords[k];
#if HUNT_CLIP_ERROR
DEBUG_STREAM << k << " goes " << setiosflags( ios::scientific) << setprecision(20)
<< srcPolygon.coords[k].x << " "
<< srcPolygon.coords[k].y << " "
<< srcPolygon.coords[k].z << " "
<< srcPolygon.coords[k].w << '\n';
#endif
dstPolygon.clipPerVertex[dstPolygon.length] =
srcPolygon.clipPerVertex[k];
dstPolygon.colors[dstPolygon.length] =
srcPolygon.colors[k];
dstPolygon.texCoords[dstPolygon.length] =
srcPolygon.texCoords[k];
dstPolygon.length++;
//
//-------------------------------------------------------
// We don't need to clip this edge if the next vertex is
// also in the viewing space, so just move on to the next
// vertex
//-------------------------------------------------------
//
if(srcPolygon.clipPerVertex[k1].IsClipped(mask) == 0)
{
continue;
}
}
//
//---------------------------------------------------------
// This vertex is outside the viewing space, so if the next
// vertex is also outside the viewing space, no clipping is
// needed and we throw this vertex away. Since only one
// clipping plane is involved, it must be in the same space
// as the first vertex
//---------------------------------------------------------
//
else
{
firstIsIn = false;
if(srcPolygon.clipPerVertex[k1].IsClipped(mask) != 0)
{
Verify(
srcPolygon.clipPerVertex[k1].IsClipped(mask)
== srcPolygon.clipPerVertex[k].IsClipped(mask)
);
continue;
}
}
//
//-------------------------------------------
// Find the clipping interval from bc0 to bc1
//-------------------------------------------
//
if(firstIsIn == true)
{
a = GetLerpFactor (l, srcPolygon.coords[k], srcPolygon.coords[k1]);
Verify(a >= 0.0f && a <= 1.0f);
//
//------------------------------
// Lerp the homogeneous position
//------------------------------
//
dstPolygon.coords[dstPolygon.length].Lerp(
srcPolygon.coords[k],
srcPolygon.coords[k1],
a
);
#if HUNT_CLIP_ERROR
DEBUG_STREAM << "True " << a << " " << k << " " << k1 << " we get " << dstPolygon.length << '\n';
DEBUG_STREAM << setiosflags( ios::scientific) << setprecision(20)
<< dstPolygon.coords[dstPolygon.length].x << " "
<< dstPolygon.coords[dstPolygon.length].y << " "
<< dstPolygon.coords[dstPolygon.length].z << " "
<< dstPolygon.coords[dstPolygon.length].w << '\n';
#endif
DoClipTrick(dstPolygon.coords[dstPolygon.length], l);
//
//----------------------------------------------------------
// If there are colors, lerp them in screen space for now as
// most cards do that anyway
//----------------------------------------------------------
//
#if COLOR_AS_DWORD
dstPolygon.colors[dstPolygon.length] = Color_DWORD_Lerp(
srcPolygon.colors[k],
srcPolygon.colors[k1],
a
);
#else
dstPolygon.colors[dstPolygon.length].Lerp(
srcPolygon.colors[k],
srcPolygon.colors[k1],
a
);
#endif
//
//-----------------------------------------------------
// If there are texture uv's, we need to lerp them in a
// perspective correct manner
//-----------------------------------------------------
//
dstPolygon.texCoords[dstPolygon.length].Lerp
(
srcPolygon.texCoords[k],
srcPolygon.texCoords[k1],
a
);
}
else
{
a = GetLerpFactor (l, srcPolygon.coords[k1], srcPolygon.coords[k]);
Verify(a >= 0.0f && a <= 1.0f);
//
//------------------------------
// Lerp the homogeneous position
//------------------------------
//
dstPolygon.coords[dstPolygon.length].Lerp(
srcPolygon.coords[k1],
srcPolygon.coords[k],
a
);
#if HUNT_CLIP_ERROR
DEBUG_STREAM << "False " << a << " " << k << " " << k1 << " we get " << dstPolygon.length << '\n';
DEBUG_STREAM << setiosflags( ios::scientific) << setprecision(20)
<< dstPolygon.coords[dstPolygon.length].x << " "
<< dstPolygon.coords[dstPolygon.length].y << " "
<< dstPolygon.coords[dstPolygon.length].z << " "
<< dstPolygon.coords[dstPolygon.length].w << '\n';
#endif
DoClipTrick(dstPolygon.coords[dstPolygon.length], l);
//
//----------------------------------------------------------
// If there are colors, lerp them in screen space for now as
// most cards do that anyway
//----------------------------------------------------------
//
#if COLOR_AS_DWORD
dstPolygon.colors[dstPolygon.length] = Color_DWORD_Lerp(
srcPolygon.colors[k1],
srcPolygon.colors[k],
a
);
#else
dstPolygon.colors[dstPolygon.length].Lerp(
srcPolygon.colors[k1],
srcPolygon.colors[k],
a
);
#endif
//
//-----------------------------------------------------
// If there are texture uv's, we need to lerp them in a
// perspective correct manner
//-----------------------------------------------------
//
dstPolygon.texCoords[dstPolygon.length].Lerp
(
srcPolygon.texCoords[k1],
srcPolygon.texCoords[k],
a
);
}
//
//-------------------------------------
// We have to generate a new clip state
//-------------------------------------
//
dstPolygon.clipPerVertex[dstPolygon.length].Clip4dVertex(&dstPolygon.coords[dstPolygon.length]);
//
//----------------------------------
// Bump the new polygon vertex count
//----------------------------------
//
dstPolygon.length++;
}
//
//-----------------------------------------------
// Swap source and destination buffer pointers in
// preparation for the next plane test
//-----------------------------------------------
//
srcPolygon.coords = clipBuffer[dstBuffer].coords.GetData();
srcPolygon.colors = clipBuffer[dstBuffer].colors.GetData();
srcPolygon.texCoords = clipBuffer[dstBuffer].texCoords.GetData();
srcPolygon.clipPerVertex = clipBuffer[dstBuffer].clipPerVertex.GetData();
srcPolygon.length = dstPolygon.length;
dstBuffer = !dstBuffer;
dstPolygon.coords = clipBuffer[dstBuffer].coords.GetData();
dstPolygon.colors = clipBuffer[dstBuffer].colors.GetData();
dstPolygon.texCoords = clipBuffer[dstBuffer].texCoords.GetData();
dstPolygon.clipPerVertex = clipBuffer[dstBuffer].clipPerVertex.GetData();
dstPolygon.length = 0;
}
mask = mask << 1;
}
theNewOr = 0;
for(k=0;k<srcPolygon.length;k++)
{
theNewOr |= srcPolygon.clipPerVertex[k];
}
#if HUNT_CLIP_ERROR
DEBUG_STREAM << "TheOR: " << hex << theNewOr.GetClippingState() << dec << '\n';
#endif
theOr = theNewOr;
} while (theNewOr != 0 && loop--);
//
//--------------------------------------------------
// could not clip this rare case, just ignore it
//--------------------------------------------------
//
if(theNewOr != 0)
{
testList[i] = 0;
continue;
}
//
//--------------------------------------------------
// Move the most recent polygon into the clip buffer
//--------------------------------------------------
//
#if HUNT_CLIP_ERROR
DEBUG_STREAM << "Final: " << srcPolygon.length << '\n';
#endif
for(k=0;k<srcPolygon.length;k++)
{
int clipped_index = myNumberUsedClipVertex + k;
#if HUNT_CLIP_ERROR
DEBUG_STREAM << setiosflags( ios::scientific) << setprecision(20)
<< srcPolygon.coords[k].x << " "
<< srcPolygon.coords[k].y << " "
<< srcPolygon.coords[k].z << " "
<< srcPolygon.coords[k].w << '\n';
#endif
(*clipExtraCoords)[clipped_index] = srcPolygon.coords[k];
(*clipExtraColors)[clipped_index] = srcPolygon.colors[k];
(*clipExtraTexCoords)[clipped_index] = srcPolygon.texCoords[k];
}
numberVerticesPerPolygon = srcPolygon.length;
#if HUNT_CLIP_ERROR
DEBUG_STREAM << "---" << '\n';
#endif
(*clipExtraLength)[myNumberUsedClipLength] = numberVerticesPerPolygon;
#ifdef _ARMOR
(*clipExtraLength)[myNumberUsedClipLength] |= 0x8000;
#endif
}
myNumberUsedClipVertex += numberVerticesPerPolygon;
myNumberUsedClipLength++;
ret++;
// clip
// dont draw the original
testList[i] = 0;
}
}
Check_Object(vt);
gos_vertices = vt->GetActualVertexPool();
numGOSVertices = 0;
gos_indices = vt->GetActualIndexPool();
numGOSIndices = 0;
unsigned short strideIndex;
for(j=0,strideIndex=0;j<*usedNrOfPoints;j++)
{
if((*visibleIndexedVertices)[j] == 0)
{
strideIndex++;
}
else
{
indexOffset[j] = static_cast<unsigned short>(j-strideIndex);
GOSCopyData(
&gos_vertices[numGOSVertices],
transformedCoords->GetData(),
colors,
texCoords,
j
);
#ifdef LAB_ONLY
if(gShowClippedPolys)
{
gos_vertices[numGOSVertices].argb = 0xff0000ff;
gos_vertices[numGOSVertices].u = 0.0f;
gos_vertices[numGOSVertices].v = 0.0f;
}
#endif
numGOSVertices++;
}
}
for(i=0,j=0;i<*usedNrOfTriangles;j+=3,++i)
{
if(testList[i] == 0)
{
continue;
}
Verify((vt->GetLastIndex() + 3 + numGOSIndices) < vt->GetLength());
Verify(indexOffset[index[j]] < numGOSVertices);
gos_indices[numGOSIndices] = indexOffset[index[j]];
Verify(indexOffset[index[j+2]] < numGOSVertices);
gos_indices[numGOSIndices+1] = indexOffset[index[j+2]];
Verify(indexOffset[index[j+1]] < numGOSVertices);
gos_indices[numGOSIndices+2] = indexOffset[index[j+1]];
numGOSIndices += 3;
}
unsigned short stride;
if(myNumberUsedClipLength > 0)
{
for(i=0,j=0;i<myNumberUsedClipLength;i++)
{
#ifdef _ARMOR
stride = static_cast<unsigned short>((*clipExtraLength)[i] & 0x7fff);
#else
stride = static_cast<unsigned short>((*clipExtraLength)[i]);
#endif
for(k=1;k<stride-1;k++)
{
Verify((vt->GetLast() + 3 + numGOSVertices) < vt->GetLength());
Verify((vt->GetLastIndex() + 3 + numGOSIndices) < vt->GetLength());
GOSCopyTriangleData(
&gos_vertices[numGOSVertices],
clipExtraCoords->GetData(),
clipExtraColors->GetData(),
clipExtraTexCoords->GetData(),
j, j+k+1, j+k
);
#ifdef LAB_ONLY
if(gShowClippedPolys)
{
if((*clipExtraLength)[i] & 0x8000)
{
gos_vertices[numGOSVertices].argb = 0xffff0000;
gos_vertices[numGOSVertices].u = 0.0f;
gos_vertices[numGOSVertices].v = 0.0f;
gos_vertices[numGOSVertices+1].argb = 0xffff0000;
gos_vertices[numGOSVertices+1].u = 0.0f;
gos_vertices[numGOSVertices+1].v = 0.0f;
gos_vertices[numGOSVertices+2].argb = 0xffff0000;
gos_vertices[numGOSVertices+2].u = 0.0f;
gos_vertices[numGOSVertices+2].v = 0.0f;
}
else
{
gos_vertices[numGOSVertices].argb = 0xffff9999;
gos_vertices[numGOSVertices].u = 0.0f;
gos_vertices[numGOSVertices].v = 0.0f;
gos_vertices[numGOSVertices+1].argb = 0xffff9999;
gos_vertices[numGOSVertices+1].u = 0.0f;
gos_vertices[numGOSVertices+1].v = 0.0f;
gos_vertices[numGOSVertices+2].argb = 0xffff9999;
gos_vertices[numGOSVertices+2].u = 0.0f;
gos_vertices[numGOSVertices+2].v = 0.0f;
}
}
#endif
Verify((vt->GetLastIndex() + 3 + numGOSIndices) < vt->GetLength());
Verify(numGOSIndices%3 == 0);
gos_indices[numGOSIndices] = (unsigned short)numGOSVertices;
gos_indices[numGOSIndices+1] = (unsigned short)(numGOSVertices + 1);
gos_indices[numGOSIndices+2] = (unsigned short)(numGOSVertices + 2);
numGOSVertices += 3;
numGOSIndices += 3;
}
j += stride;
}
#if HUNT_CLIP_ERROR
DEBUG_STREAM << "***" << endl << endl;
#endif
}
vt->Increase(numGOSVertices);
vt->IncreaseIndex(numGOSIndices);
return numGOSIndices;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void
MLRIndexedTriangleCloud::TestInstance() const
{
if (usedNrOfTriangles)
{
Check_Pointer(usedNrOfTriangles);
Verify(*usedNrOfTriangles >= 0);
Verify(*usedNrOfTriangles <= maxNrOf);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -