📄 mlrlightmap.cpp
字号:
//---------------------------------------------------------
//
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
);
DoClipTrick(dstPolygon.coords[dstPolygon.length], l);
//
//-----------------------------------------------------
// 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
);
dstPolygon.colors[dstPolygon.length].Lerp
(
srcPolygon.colors[k],
srcPolygon.colors[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
);
DoClipTrick(dstPolygon.coords[dstPolygon.length], l);
//
//-----------------------------------------------------
// 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
);
dstPolygon.colors[dstPolygon.length].Lerp
(
srcPolygon.colors[k1],
srcPolygon.colors[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.texCoords = clipBuffer[dstBuffer].texCoords.GetData();
srcPolygon.colors = clipBuffer[dstBuffer].colors.GetData();
srcPolygon.clipPerVertex = clipBuffer[dstBuffer].clipPerVertex.GetData();
srcPolygon.length = dstPolygon.length;
dstBuffer = !dstBuffer;
dstPolygon.coords = clipBuffer[dstBuffer].coords.GetData();
dstPolygon.texCoords = clipBuffer[dstBuffer].texCoords.GetData();
dstPolygon.colors = clipBuffer[dstBuffer].colors.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];
}
theOr == theNewOr;
loop++;
} while (theNewOr != 0 && loop--);
Verify(theNewOr == 0);
//
//--------------------------------------------------
// Move the most recent polygon into the clip buffer
//--------------------------------------------------
//
for(k=0;k<srcPolygon.length;k++)
{
(*clipExtraCoords)[k] = srcPolygon.coords[k];
Verify((*clipExtraCoords)[k].x >= 0.0f && (*clipExtraCoords)[k].x <= (*clipExtraCoords)[k].w );
Verify((*clipExtraCoords)[k].y >= 0.0f && (*clipExtraCoords)[k].y <= (*clipExtraCoords)[k].w );
Verify((*clipExtraCoords)[k].z >= 0.0f && (*clipExtraCoords)[k].z <= (*clipExtraCoords)[k].w );
(*clipExtraTexCoords)[k] = srcPolygon.texCoords[k];
(*clipExtraColors)[k] = srcPolygon.colors[k];
}
numberVerticesPerPolygon = srcPolygon.length;
}
// clip
for(i=1;i<numberVerticesPerPolygon-1;i++)
{
Verify((vertexPool->GetLast() + 3 + numGOSVertices) < vertexPool->GetLength());
GOSCopyTriangleData(
&gos_vertices[numGOSVertices],
clipExtraCoords->GetData(),
clipExtraColors->GetData(),
clipExtraTexCoords->GetData(),
0, i + 1, i
);
numGOSVertices+=3;
}
}
}
}
break;
}
ptr = stream->GetPointer();
}
if(numGOSVertices)
{
vertexPool->Increase(numGOSVertices);
SortData *sd = sorter->SetRawData
(
gos_vertices,
numGOSVertices,
currentState,
SortData::TriList
);
if(currentState.GetDrawNowMode()==MLRState::DrawNowOnMode)
{
SortData::DrawFunc drawFunc = sd->Draw[sd->type];
(sd->*drawFunc)();
}
else
{
sorter->AddSortRawData(sd);
}
}
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
MLRShape*
MLRLightMap::CreateLightMapShape()
{
Check_Object(stream);
gos_PushCurrentHeap(Heap);
MLRShape *ret = new MLRShape(20);
Register_Object(ret);
MLR_I_C_TMesh *ctmesh = NULL;
void *ptr, *end = stream->GetPointer();
MLRClippingState currentClippingState;
MLRState currentState, masterState;
unsigned short stride;
int i;
Stuff::Point3D *coords = NULL;
Stuff::RGBAColor color;
Stuff::RGBAColor *colors = NULL;
Vector2DScalar *texCoords = NULL;
int numGOSVertices = 0;
int msd;
MemoryStreamData type;
stream->Rewind();
ptr = stream->GetPointer();
while(ptr < end)
{
*stream >> msd;
type = static_cast<MemoryStreamData>(msd);
switch(msd)
{
case Matrix4D:
// not this time
*stream >> i;
break;
case ClippingState:
// not this time
*stream >> i;
break;
case MasterRenderState:
// not this time
masterState.Load(stream, Current_MLR_Version);
break;
case LightMapRenderState:
{
MLRState state;
state.Load(stream, Current_MLR_Version);
if(numGOSVertices && (state != currentState))
{
if(ctmesh!=NULL)
{
ctmesh->SetSubprimitiveLengths(NULL, numGOSVertices/3);
ctmesh->FlashClipCoords(numGOSVertices);
ctmesh->FlashClipTexCoords(numGOSVertices);
ctmesh->FlashClipColors(numGOSVertices);
ctmesh->SetReferenceState(currentState);
ctmesh->TheIndexer(numGOSVertices);
ctmesh->FindFacePlanes();
ret->Add(ctmesh);
ctmesh->DetachReference();
ctmesh = NULL;
}
}
currentState = state;
}
break;
case Polygon:
{
if(ctmesh == NULL)
{
ctmesh = new MLR_I_C_TMesh;
numGOSVertices = 0;
}
*stream >> stride;
Verify(stride==3);
*stream >> color;
#if COLOR_AS_DWORD
DWORD argb = 0xffffffff;
argb = GOSCopyColor(&color);
#endif
coords = (Stuff::Point3D *)stream->GetPointer();
stream->AdvancePointer(stride*sizeof(Stuff::Point3D));
texCoords = (Vector2DScalar *)stream->GetPointer();
stream->AdvancePointer(stride*sizeof(Vector2DScalar));
for(i=0;i<stride;i++,numGOSVertices++)
{
ctmesh->SetClipCoord(coords[i], numGOSVertices);
ctmesh->SetClipTexCoord(texCoords[i], numGOSVertices);
#if COLOR_AS_DWORD
ctmesh->SetClipColor(argb, numGOSVertices);
#else
ctmesh->SetClipColor(color, numGOSVertices);
#endif
}
}
break;
case PolygonWithColor:
{
if(ctmesh == NULL)
{
ctmesh = new MLR_I_C_TMesh;
numGOSVertices = 0;
}
*stream >> stride;
Verify(stride<=Limits::Max_Number_Vertices_Per_Polygon);
coords = (Stuff::Point3D *)stream->GetPointer();
stream->AdvancePointer(stride*sizeof(Stuff::Point3D));
colors = (Stuff::RGBAColor *)stream->GetPointer();
stream->AdvancePointer(stride*sizeof(Stuff::RGBAColor));
texCoords = (Vector2DScalar *)stream->GetPointer();
stream->AdvancePointer(stride*sizeof(Vector2DScalar));
for(i=0;i<stride;i++,numGOSVertices++)
{
ctmesh->SetClipCoord(coords[i], numGOSVertices);
ctmesh->SetClipTexCoord(texCoords[i], numGOSVertices);
#if COLOR_AS_DWORD
#error not implemented yet
#else
ctmesh->SetClipColor(colors[i], numGOSVertices);
#endif
}
}
break;
}
ptr = stream->GetPointer();
}
if(ctmesh!=NULL)
{
ctmesh->SetSubprimitiveLengths(NULL, numGOSVertices/3);
ctmesh->FlashClipCoords(numGOSVertices);
ctmesh->FlashClipTexCoords(numGOSVertices);
ctmesh->FlashClipColors(numGOSVertices);
ctmesh->SetReferenceState(currentState);
ctmesh->TheIndexer(numGOSVertices);
ctmesh->FindFacePlanes();
ret->Add(ctmesh);
ctmesh->DetachReference();
}
gos_PopCurrentHeap();
return ret;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -