⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mlrpolymesh.cpp

📁 机甲指挥官2源代码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
	if(myNumberUsedClipLength > 0)
	{
		for(i=0,j=0;i<myNumberUsedClipLength;i++)
		{
			stride = clipExtraLength[i];

			for(k=1;k<stride-1;k++)
			{
				Verify((vt->GetLast() + 3 + numGOSVertices) < vt->GetLength());

#if 1
				GOSCopyTriangleData(
					&gos_vertices[numGOSVertices],
					clipExtraCoords.GetData(),
					clipExtraColors.GetData(),
					clipExtraTexCoords.GetData(),
					j, j+k+1, j+k
				);
#else

				gos_vertices[numGOSVertices] = clipExtraCoords[j];
				gos_vertices[numGOSVertices+1] = clipExtraCoords[j+k+1];
				gos_vertices[numGOSVertices+2] = clipExtraCoords[j+k];

				if((*actualColors).GetLength() == coords.GetLength())
				{
					gos_vertices[numGOSVertices] = clipExtraColors[j];
					gos_vertices[numGOSVertices+1] = clipExtraColors[j+k+1];
					gos_vertices[numGOSVertices+2] = clipExtraColors[j+k];
				}

				if(texCoords.GetLength() == coords.GetLength())
				{
					gos_vertices[numGOSVertices] = clipExtraTexCoords[j];
					gos_vertices[numGOSVertices+1] = clipExtraTexCoords[j+k+1];
					gos_vertices[numGOSVertices+2] = clipExtraTexCoords[j+k];
				}
#endif
				numGOSVertices += 3;
			}
			j += stride;
		}
	}
	vt->Increase(numGOSVertices);

	visible = numGOSVertices ? 1 : 0;

	if(visible)
	{
	}
	else
	{
	}

	CLEAR_MLRPOLYMESH_CLIP();
	clipTrace->Stop();

	return ret;
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void
	MLRPolyMesh::Lighting (
		MLRLight **lights,
		int nrLights
	)
{
	Check_Object(this);

	// set the to use colors to the original colors ...
	// only lighting could overwrite this;
	actualColors = &colors;

	if(nrLights == 0)
	{
		return;
	}

	if(normals.GetLength() == 0)
	{
		return;
	}

	if(lights == NULL)
	{
		return;
	}

	switch (GetCurrentState().GetLightingMode())
	{
		case MLRState::LightingOffMode:
			return;
		case MLRState::LightingClassicOnlyMode:
		{
			Verify(colors.GetLength() == litColors.GetLength());
			Verify(normals.GetLength() == colors.GetLength());
			Verify(coords.GetLength() == colors.GetLength());

			int i, j, k, l, stride, len = colors.GetLength();

			MLRVertexData vertexData;

#if COLOR_AS_DWORD
#else
			RGBAColor *color = &colors[0];
			RGBAColor *litColor = &litColors[0];

#if USE_ASSEMBLER_CODE
			_asm {
				push		esi
				push		edi

				mov			esi, color

				mov			edi, litColor
				mov         ecx, len

			_loop1:

				mov			eax, dword ptr [esi]
				mov			ebx, dword ptr [esi+4]

				mov			dword ptr [edi], eax
				mov			dword ptr [edi+ 4], ebx

				mov			eax, dword ptr [esi + 8]
				mov			ebx, dword ptr [esi + 12]

				mov			dword ptr [edi + 8], eax
				mov			dword ptr [edi + 12], ebx

				add			esi,16
				add			edi,16

				dec			ecx
				jnz			_loop1

				pop			edi
				pop			esi
			}
#else	// it doesnt know that ...
			memcpy(litColor, color, (len<<2)*sizeof(Scalar));
#endif
#endif

			len = lengths.GetLength();
			//
			//-----------------------------------
			// Test each light against the vertex
			//-----------------------------------
			//
			for (i=0;i<nrLights;i++)
			{
				MLRLight *light = lights[i];

				Check_Object(light);


				vertexData.point = &coords[0];
				vertexData.color = &litColors[0];
				vertexData.normal = &normals[0];

				for(k=0,j=0;k<len;k++)
				{
					stride = lengths[k];

					if(testList[k] == 0)
					{
						j += stride;
						vertexData.point += stride;
						vertexData.color += stride;
						vertexData.normal += stride;
						continue;
					}

					for(l=j;l<j+stride;j++)
					{
						light->LightVertex(vertexData);

						vertexData.point++;
						vertexData.color++;
						vertexData.normal++;
					}
				}
			}

			#ifdef LAB_ONLY
				Statistics::MLR_LitVertices += len*nrLights;
			#endif

			// set the to use colors to the original colors ...
			// only lighting could overwrite this;
			actualColors = &litColors;
		}
		break;
		case MLRState::LightingLightMapOnlyMode:
		{
			Verify(state.GetAlphaMode() == MLRState::OneZeroMode);
			STOP(("Lightmaps not implemented yet."));
		}
		break;
		case MLRState::LightingClassicAndLightMapMode:
		{
			Verify(state.GetAlphaMode() == MLRState::OneZeroMode);

			Verify(colors.GetLength() == litColors.GetLength());
			Verify(normals.GetLength() == colors.GetLength());
			Verify(coords.GetLength() == colors.GetLength());

			int i, j, k, l, stride, len = colors.GetLength();

			MLRVertexData vertexData;

#if COLOR_AS_DWORD
#else
			RGBAColor *color = &colors[0];
			RGBAColor *litColor = &litColors[0];

#if USE_ASSEMBLER_CODE
			_asm {
				push		esi
				push		edi

				mov			esi, color

				mov			edi, litColor
				mov         ecx, len

			_loop2:

				mov			eax, dword ptr [esi]
				mov			ebx, dword ptr [esi+4]

				mov			dword ptr [edi], eax
				mov			dword ptr [edi+ 4], ebx

				mov			eax, dword ptr [esi + 8]
				mov			ebx, dword ptr [esi + 12]

				mov			dword ptr [edi + 8], eax
				mov			dword ptr [edi + 12], ebx

				add			esi,16
				add			edi,16

				dec			ecx
				jnz			_loop2

				pop			edi
				pop			esi
			}
#else	// it doesnt know that ...
			memcpy(litColor, color, (len<<2)*sizeof(Scalar));
#endif
#endif

			len = lengths.GetLength();
			//
			//-----------------------------------
			// Test each light against the vertex
			//-----------------------------------
			//
			for (i=0;i<nrLights;i++)
			{
				MLRLight *light = lights[i];

				Check_Object(light);


				vertexData.point = &coords[0];
				vertexData.color = &litColors[0];
				vertexData.normal = &normals[0];

				for(k=0,j=0;k<len;k++)
				{
					stride = lengths[k];

					if(testList[k] == 0)
					{
						j += stride;
						vertexData.point += stride;
						vertexData.color += stride;
						vertexData.normal += stride;
						continue;
					}

					for(l=j;l<j+stride;j++)
					{
						light->LightVertex(vertexData);

						vertexData.point++;
						vertexData.color++;
						vertexData.normal++;
					}
				}
			}

			#ifdef LAB_ONLY
				Statistics::MLR_LitVertices += len*nrLights;
			#endif

			// set the to use colors to the original colors ...
			// only lighting could overwrite this;
			actualColors = &litColors;

			STOP(("Lightmaps not implemented yet."));
		}
		break;
	}

}


//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
MLRPolyMesh*
	MidLevelRenderer::CreateCube(
		Scalar half, 
		RGBAColor *eightColors, 
		Vector3D *eightNormals,
		MLRState *state
	)
{
	MLRPolyMesh *ret = new MLRPolyMesh;
	Register_Object(ret);

	Vector3D eightCoords[8] = {
		Vector3D( half, -half,  half),
		Vector3D(-half, -half,  half),
		Vector3D( half, -half, -half),
		Vector3D(-half, -half, -half),
		Vector3D(-half,  half,  half),
		Vector3D( half,  half,  half),
		Vector3D( half,  half, -half),
		Vector3D(-half,  half, -half)
	};

	unsigned char *lengths = new unsigned char [6];

	int i;

	for(i=0;i<6;i++)
	{
		lengths[i] = 4;
	}

	ret->SetPrimitiveLength(lengths, 6);

	Point3D *coords = new Point3D [6*4];

	coords[0] = eightCoords[0];
	coords[1] = eightCoords[2];
	coords[2] = eightCoords[6];
	coords[3] = eightCoords[5];

	coords[4] = eightCoords[0];
	coords[5] = eightCoords[5];
	coords[6] = eightCoords[4];
	coords[7] = eightCoords[1];

	coords[8] = eightCoords[5];
	coords[9] = eightCoords[6];
	coords[10] = eightCoords[7];
	coords[11] = eightCoords[4];

	coords[12] = eightCoords[2];
	coords[13] = eightCoords[3];
	coords[14] = eightCoords[7];
	coords[15] = eightCoords[6];

	coords[16] = eightCoords[1];
	coords[17] = eightCoords[4];
	coords[18] = eightCoords[7];
	coords[19] = eightCoords[3];

	coords[20] = eightCoords[0];
	coords[21] = eightCoords[1];
	coords[22] = eightCoords[3];
	coords[23] = eightCoords[2];


	ret->SetCoordData(coords, 6*4);
	ret->FindFacePlanes();

	if(eightColors!=NULL)
	{
#if COLOR_AS_DWORD
		DWORD *colors = new DWORD[6*4];

		colors[0] = GOSCopyColor(&eightColors[0]);
		colors[1] = GOSCopyColor(&eightColors[2]);
		colors[2] = GOSCopyColor(&eightColors[6]);
		colors[3] = GOSCopyColor(&eightColors[5]);

		colors[4] = GOSCopyColor(&eightColors[0]);
		colors[5] = GOSCopyColor(&eightColors[5]);
		colors[6] = GOSCopyColor(&eightColors[4]);
		colors[7] = GOSCopyColor(&eightColors[1]);

		colors[8] = GOSCopyColor(&eightColors[5]);
		colors[9] = GOSCopyColor(&eightColors[6]);
		colors[10] = GOSCopyColor(&eightColors[7]);
		colors[11] = GOSCopyColor(&eightColors[4]);

		colors[12] = GOSCopyColor(&eightColors[2]);
		colors[13] = GOSCopyColor(&eightColors[3]);
		colors[14] = GOSCopyColor(&eightColors[7]);
		colors[15] = GOSCopyColor(&eightColors[6]);

		colors[16] = GOSCopyColor(&eightColors[1]);
		colors[17] = GOSCopyColor(&eightColors[4]);
		colors[18] = GOSCopyColor(&eightColors[7]);
		colors[19] = GOSCopyColor(&eightColors[3]);

		colors[20] = GOSCopyColor(&eightColors[0]);
		colors[21] = GOSCopyColor(&eightColors[1]);
		colors[22] = GOSCopyColor(&eightColors[3]);
		colors[23] = GOSCopyColor(&eightColors[2]);
#else
		RGBAColor *colors = new RGBAColor[6*4];

		colors[0] = eightColors[0];
		colors[1] = eightColors[2];
		colors[2] = eightColors[6];
		colors[3] = eightColors[5];

		colors[4] = eightColors[0];
		colors[5] = eightColors[5];
		colors[6] = eightColors[4];
		colors[7] = eightColors[1];

		colors[8] = eightColors[5];
		colors[9] = eightColors[6];
		colors[10] = eightColors[7];
		colors[11] = eightColors[4];

		colors[12] = eightColors[2];
		colors[13] = eightColors[3];
		colors[14] = eightColors[7];
		colors[15] = eightColors[6];

		colors[16] = eightColors[1];
		colors[17] = eightColors[4];
		colors[18] = eightColors[7];
		colors[19] = eightColors[3];

		colors[20] = eightColors[0];
		colors[21] = eightColors[1];
		colors[22] = eightColors[3];
		colors[23] = eightColors[2];
#endif

		ret->SetColorData(colors, 6*4);
	}

	if(eightNormals!=NULL)
	{
		Vector3D *normals = new Vector3D[6*4];

		normals[0] = eightNormals[0];
		normals[1] = eightNormals[2];
		normals[2] = eightNormals[6];
		normals[3] = eightNormals[5];

		normals[4] = eightNormals[0];
		normals[5] = eightNormals[5];
		normals[6] = eightNormals[4];
		normals[7] = eightNormals[1];

		normals[8] = eightNormals[5];
		normals[9] = eightNormals[6];
		normals[10] = eightNormals[7];
		normals[11] = eightNormals[4];

		normals[12] = eightNormals[2];
		normals[13] = eightNormals[3];
		normals[14] = eightNormals[7];
		normals[15] = eightNormals[6];

		normals[16] = eightNormals[1];
		normals[17] = eightNormals[4];
		normals[18] = eightNormals[7];
		normals[19] = eightNormals[3];

		normals[20] = eightNormals[0];
		normals[21] = eightNormals[1];
		normals[22] = eightNormals[3];
		normals[23] = eightNormals[2];

		ret->SetNormalData(normals, 6*4);
	}

	if(state->GetTextureHandle() > 0)
	{
		Vector2DScalar *texCoords = new Vector2DScalar[6*4];

		texCoords[0] = Vector2DScalar(0.0f, 0.0f);
		texCoords[1] = Vector2DScalar(0.0f, 1.0f);
		texCoords[2] = Vector2DScalar(1.0f, 1.0f);
		texCoords[3] = Vector2DScalar(1.0f, 0.0f);

		texCoords[4] = Vector2DScalar(0.0f, 0.0f);
		texCoords[5] = Vector2DScalar(0.0f, 1.0f);
		texCoords[6] = Vector2DScalar(1.0f, 1.0f);
		texCoords[7] = Vector2DScalar(1.0f, 0.0f);

		texCoords[8] = Vector2DScalar(0.0f, 0.0f);
		texCoords[9] = Vector2DScalar(0.0f, 1.0f);
		texCoords[10] = Vector2DScalar(1.0f, 1.0f);
		texCoords[11] = Vector2DScalar(1.0f, 0.0f);

		texCoords[12] = Vector2DScalar(0.0f, 0.0f);
		texCoords[13] = Vector2DScalar(0.0f, 1.0f);
		texCoords[14] = Vector2DScalar(1.0f, 1.0f);
		texCoords[15] = Vector2DScalar(1.0f, 0.0f);

		texCoords[16] = Vector2DScalar(0.0f, 0.0f);
		texCoords[17] = Vector2DScalar(0.0f, 1.0f);
		texCoords[18] = Vector2DScalar(1.0f, 1.0f);
		texCoords[19] = Vector2DScalar(1.0f, 0.0f);

		texCoords[20] = Vector2DScalar(0.0f, 0.0f);
		texCoords[21] = Vector2DScalar(0.0f, 1.0f);
		texCoords[22] = Vector2DScalar(1.0f, 1.0f);
		texCoords[23] = Vector2DScalar(1.0f, 0.0f);

		ret->SetTexCoordData(texCoords, 6*4);
	}

	if(state != NULL)
	{
		ret->SetReferenceState(*state);
	}

	return ret;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -