📄 mgcgpedgebuffers.h
字号:
// Magic Software, Inc.
// http://www.magic-software.com
// Copyright (c) 2000, All Rights Reserved
//
// Source code from Magic Software is supplied under the terms of a license
// agreement and may not be copied or disclosed except in accordance with the
// terms of that agreement. The various license agreements may be found at
// the Magic Software web site. This file is subject to the license
//
// RESTRICTED USE SOURCE CODE
// http://www.magic-software.com/License/restricted.pdf
#ifndef MGCGPEDGEBUFFERS_H
#define MGCGPEDGEBUFFERS_H
//---------------------------------------------------------------------------
#define EdgeSetupParameters \
MgcVector3& rkV0 = m_kMesh.Vertex(uiV0); \
MgcVector3& rkV1 = m_kMesh.Vertex(uiV1); \
int iX0 = int(rkV0.x); \
int iY0 = int(rkV0.y); \
int iX1 = int(rkV1.x); \
int iY1 = int(rkV1.y); \
int iIndex = iX0 + m_iWidth*iY0; \
\
int iSx, iIx, iDx, iAx, iSy, iIy, iDy, iAy; \
if ( iX1 > iX0 ) \
{ \
iSx = 1; \
iIx = 1; \
iDx = iX1 - iX0; \
iAx = 2*iDx; \
} \
else if ( iX1 < iX0 ) \
{ \
iSx = -1; \
iIx = -1; \
iDx = iX0 - iX1; \
iAx = 2*iDx; \
} \
else \
{ \
iSx = 0; \
iIx = 0; \
iDx = 0; \
iAx = 0; \
} \
\
if ( iY1 > iY0 ) \
{ \
iSy = 1; \
iIy = m_iWidth; \
iDy = iY1 - iY0; \
iAy = 2*iDy; \
} \
else if ( iY1 < iY0 ) \
{ \
iSy = -1; \
iIy = -m_iWidth; \
iDy = iY0 - iY1; \
iAy = 2*iDy; \
} \
else \
{ \
iSy = 0; \
iIy = 0; \
iDy = 0; \
iAy = 0; \
} \
\
if ( iDx == 0 && iDy == 0 ) \
return;
//---------------------------------------------------------------------------
#define EdgeInitX \
if ( iDx >= iDy ) \
{
//---------------------------------------------------------------------------
#define EdgePrologTraverseX \
int iDecY = iAy - iDx; \
while ( 1 ) \
{ \
//---------------------------------------------------------------------------
#define EdgeReturnX \
if ( iX0 == iX1 ) return;
//---------------------------------------------------------------------------
#define EdgeEpilogTraverseX \
if ( iDecY >= 0 ) \
{ \
iDecY -= iAx; \
iY0 += iSy; \
iIndex += iIy; \
} \
iDecY += iAy; \
iX0 += iSx; \
iIndex += iIx; \
}
//---------------------------------------------------------------------------
#define EdgeExitX \
} \
//---------------------------------------------------------------------------
#define EdgeInitY \
else \
{
//---------------------------------------------------------------------------
#define EdgePrologTraverseY \
int iDecX = iAx - iDy; \
while ( 1 ) \
{ \
//---------------------------------------------------------------------------
#define EdgeReturnY \
if ( iY0 == iY1 ) return;
//---------------------------------------------------------------------------
#define EdgeEpilogTraverseY \
if ( iDecX >= 0 ) \
{ \
iDecX -= iAy; \
iX0 += iSx; \
iIndex += iIx; \
} \
iDecX += iAx; \
iY0 += iSy; \
iIndex += iIy; \
}
//---------------------------------------------------------------------------
#define EdgeExitY \
} \
//---------------------------------------------------------------------------
#define TriangleSetupParameters \
MgcVector3& rkV0 = m_kMesh.Vertex(uiV0); \
MgcVector3& rkV1 = m_kMesh.Vertex(uiV1); \
MgcVector3& rkV2 = m_kMesh.Vertex(uiV2); \
m_aiX[0] = int(rkV0.x); \
m_aiY[0] = int(rkV0.y); \
m_aiX[1] = int(rkV1.x); \
m_aiY[1] = int(rkV1.y); \
m_aiX[2] = int(rkV2.x); \
m_aiY[2] = int(rkV2.y);
//---------------------------------------------------------------------------
#define LinAttrSetup(n) \
const int iMax = n; \
int i, iDeltaA, aiA0[iMax], aiA1[iMax], aiSc[iMax]; \
int aiIntPart[iMax], aiFrcPart[iMax], aiDecZ[iMax];
//---------------------------------------------------------------------------
#define InitLinAttrX \
for (i = 0; i < iMax; i++) \
{ \
iDeltaA = aiA1[i] - aiA0[i]; \
aiIntPart[i] = iDeltaA / iDx; \
aiFrcPart[i] = iDeltaA % iDx; \
if ( aiFrcPart[i] >= 0 ) \
{ \
aiSc[i] = 1; \
} \
else \
{ \
aiSc[i] = -1; \
aiFrcPart[i] = -aiFrcPart[i]; \
} \
aiDecZ[i] = aiFrcPart[i]; \
}
//---------------------------------------------------------------------------
#define InitLinAttrY \
for (i = 0; i < iMax; i++) \
{ \
iDeltaA = aiA1[i] - aiA0[i]; \
aiIntPart[i] = iDeltaA / iDy; \
aiFrcPart[i] = iDeltaA % iDy; \
if ( aiFrcPart[i] >= 0 ) \
{ \
aiSc[i] = 1; \
} \
else \
{ \
aiSc[i] = -1; \
aiFrcPart[i] = -aiFrcPart[i]; \
} \
aiDecZ[i] = aiFrcPart[i]; \
}
//---------------------------------------------------------------------------
#define UpdateLinAttrX \
for (i = 0; i < iMax; i++) \
{ \
aiA0[i] += aiIntPart[i]; \
aiDecZ[i] += aiFrcPart[i]; \
if ( aiDecZ[i] >= iDx ) \
{ \
aiA0[i] += aiSc[i]; \
aiDecZ[i] -= iDx; \
} \
}
//---------------------------------------------------------------------------
#define UpdateLinAttrY \
for (i = 0; i < iMax; i++) \
{ \
aiA0[i] += aiIntPart[i]; \
aiDecZ[i] += aiFrcPart[i]; \
if ( aiDecZ[i] >= iDy ) \
{ \
aiA0[i] += aiSc[i]; \
aiDecZ[i] -= iDy; \
} \
}
//---------------------------------------------------------------------------
#define PerAttrSetup \
MgcReal fU0, fV0, fW0, fU1, fV1, fW1, fW0U1, fW1U0, fW0V1, fW1V0; \
MgcReal afA[2], afB[2], fC, fD, fInv, fU, fV, fX0, fX1, fY0, fY1;
//---------------------------------------------------------------------------
#define InitPerAttrX \
fW0U1 = fW0*fU1; \
fW1U0 = fW1*fU0; \
fW0V1 = fW0*fV1; \
fW1V0 = fW1*fV0; \
afA[0] = fW0U1 - fW1U0; \
afA[1] = fW0V1 - fW1V0; \
fC = fW0 - fW1; \
fX0 = MgcReal(iX0); \
fX1 = MgcReal(iX1); \
afB[0] = fW1U0*fX1 - fW0U1*fX0; \
afB[1] = fW1V0*fX1 - fW0V1*fX0; \
fD = fW1*fX1 - fW0*fX0;
//---------------------------------------------------------------------------
#define InitPerAttrY \
fW0U1 = fW0*fU1; \
fW1U0 = fW1*fU0; \
fW0V1 = fW0*fV1; \
fW1V0 = fW1*fV0; \
afA[0] = fW0U1 - fW1U0; \
afA[1] = fW0V1 - fW1V0; \
fC = fW0 - fW1; \
fY0 = MgcReal(iY0); \
fY1 = MgcReal(iY1); \
afB[0] = fW1U0*fY1 - fW0U1*fY0; \
afB[1] = fW1V0*fY1 - fW0V1*fY0; \
fD = fW1*fY1 - fW0*fY0;
//---------------------------------------------------------------------------
#define UpdatePerAttrX \
fX0 = MgcReal(iX0); \
fInv = 1/(fC*fX0+fD); \
fU = (afA[0]*fX0+afB[0])*fInv; \
fV = (afA[1]*fX0+afB[1])*fInv;
//---------------------------------------------------------------------------
#define UpdatePerAttrY \
fY0 = MgcReal(iY0); \
fInv = 1/(fC*fY0+fD); \
fU = (afA[0]*fY0+afB[0])*fInv; \
fV = (afA[1]*fY0+afB[1])*fInv;
//---------------------------------------------------------------------------
#define TriPerAttrSetup \
MgcReal fW0A1, fW1A0, afA[2], afB[2], fC, fD, fInv, fU, fV; \
MgcReal fX0, fX1, fX; \
MgcReal* afT0; \
MgcReal* afT1;
//---------------------------------------------------------------------------
#define TriInitPerAttr \
fX0 = MgcReal(iX0); \
fX1 = MgcReal(iX1); \
fC = afT0[2] - afT1[2]; \
fD = afT1[2]*fX1 - afT0[2]*fX0; \
fW0A1 = afT0[2]*afT1[0]; \
fW1A0 = afT1[2]*afT0[0]; \
afA[0] = fW0A1 - fW1A0; \
afB[0] = fW1A0*fX1 - fW0A1*fX0; \
fW0A1 = afT0[2]*afT1[1]; \
fW1A0 = afT1[2]*afT0[1]; \
afA[1] = fW0A1 - fW1A0; \
afB[1] = fW1A0*fX1 - fW0A1*fX0;
//---------------------------------------------------------------------------
#define TriUpdatePerAttr \
fX = MgcReal(iX); \
fInv = 1/(fC*fX+fD); \
fU = (afA[0]*fX+afB[0])*fInv; \
fV = (afA[1]*fX+afB[1])*fInv;
//---------------------------------------------------------------------------
#define TriBeginLoop \
if ( !ComputeEdgeBuffers() ) \
return; \
for (int iY = m_iYMin; iY <= m_iYMax; iY++) \
{ \
int iX0 = m_aiXMin[iY]; \
int iX1 = m_aiXMax[iY]; \
int iIndex = iX0+m_iWidth*iY; \
int iDx = iX1 - iX0;
//---------------------------------------------------------------------------
#define TriPerLoopSetup \
afT0 = m_aafPerAttrMin[iY]; \
afT1 = m_aafPerAttrMax[iY];
//---------------------------------------------------------------------------
#define TriEndLoop \
}
//---------------------------------------------------------------------------
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -