void CMeshSelectionConverter::AddSelectedVerts(void)
{
	SSelectionColour*	psSelectionColour;
	int					iIndex;
	int					iCornerNum;
	int					iNumCorners;
	int					iStartVertex;
	CArrayInt			aiSkinIndices;
	BOOL				bSelected;
	
	iStartVertex = mpcObject->GetNumberOfVerticesOfType(D3DFVF_CVERTEX);
	iNumCorners = 0;

	aiSkinIndices.Init();
	for (iCornerNum = 0; iCornerNum < mpcMeshEditor->mcSelections.mcVerts.NumElements(); iCornerNum++)
	{
		bSelected = FixBool(mpcMeshEditor->mcSelections.mcVerts.Get(iCornerNum));
		iIndex = mpcSelectionColours->FindWithIntKey(bSelected, 0);
		if (iIndex != -1)
		{
			iNumCorners++;
			psSelectionColour = mpcSelectionColours->Get(iIndex);

			AssignCorner(iCornerNum, psSelectionColour->iColour, mfZOffset*3, &aiSkinIndices);
		}
	}
	aiSkinIndices.Kill();

	mpcObject->GrowPrimitive(iNumCorners, D3DPT_POINTLIST, iNumCorners, 0, miMaterialIndex, 0, 0);
}
void CMeshSmoothGroups::GenerateSmoothingFromNames(CMeshEditor* pcMeshEditor)
{
	int				i;
	int				iNumPolygons;
	CMeshPolygon*	pcPolygon;
	int				iNumFaces;
	int				j;
	int				iFace;
	CArrayInt		aiUniqueNames;
	unsigned int	uiFaceName;
	unsigned int	uiSmoothingGroup;

	iNumPolygons = pcMeshEditor->mcPolygons.mcPolygons.NumElements();

	aiUniqueNames.Init();
	pcMeshEditor->mcPolygons.GetUniqueNames(&aiUniqueNames);

	if (aiUniqueNames.NumElements() >= 32)
	{
		//Too many face names to deal with.
		mcSmoothingGroups.SetArrayValues(1);
	}
	else
	{
		for (i = 0; i < iNumPolygons; i++)
		{
			pcPolygon = pcMeshEditor->mcPolygons.Get(i);
			iNumFaces = pcPolygon->maiFaces.NumElements();
			uiFaceName = pcPolygon->miName;
			if (uiFaceName != 0)
			{
				uiSmoothingGroup = 1 << (uiFaceName-1);
			}
			else
			{
				uiSmoothingGroup = 0;
			}

			for (j = 0; j < iNumFaces; j++)
			{
				iFace = pcPolygon->maiFaces.GetValue(j);
				mcSmoothingGroups.SetValue(iFace, uiSmoothingGroup);
			}
		}
	}

	aiUniqueNames.Kill();
}
void CMeshSmoothGroups::GenerateSmoothingFromAngles(CMeshEditor* pcMeshEditor)
{
	int				i;
	int				iNumPolygons;
	CMeshPolygon*	pcPolygon;
	CArrayFloat3	asNormals;
	CArrayInt		aiAdjPolys;
	SFloat3*		psThisNormal;
	SFloat3*		psOtherNormal;
	int				j;
	int				iOtherGon;
	float			fDot;
	float			fResult;

	fDot = Deg2Dot(mfSharpAngle);

	asNormals.Init();
	pcMeshEditor->mcPolygons.GetNormals(&asNormals, &pcMeshEditor->mpcMesh->mcNormals);

	mcSmoothingGroups.SetArrayValues(0);

	iNumPolygons = pcMeshEditor->mcPolygons.mcPolygons.NumElements();
	for (i = 0; i < iNumPolygons; i++)
	{
		psThisNormal = asNormals.Get(i);
		pcPolygon = pcMeshEditor->mcPolygons.Get(i);
		aiAdjPolys.Init();
		pcMeshEditor->mcPolygons.GetAdjacentPolygons(pcMeshEditor->mpcMesh->GetConnectivity(), i, &aiAdjPolys);

		for (j = 0; j < aiAdjPolys.NumElements(); j++)
		{
			iOtherGon = aiAdjPolys.GetValue(j);
			psOtherNormal = asNormals.Get(iOtherGon);

			fResult = Float3Dot(psThisNormal, psOtherNormal);
			if (fResult >= fDot)
			{
				//Smooth!
			}
		}

		aiAdjPolys.Kill();
	}

	asNormals.Kill();
}
void CMeshSelectionConverter::AddSelectedFaces(void)
{
	int					iFaceNum;
	CMeshFace*			psFace;	
	SSelectionColour*	psSelectionColour;
	int					iIndex;
	int					iCornerOffset;
	CMeshCorner*		psCorner;
	int					iNumFaces;
	int					iStartVertex;
	CArrayInt			aiSkinIndices;
	int					iColour;
	BOOL				bSelected;

	iStartVertex = mpcObject->GetNumberOfVerticesOfType(D3DFVF_CVERTEX);
	iNumFaces = 0;

	aiSkinIndices.Init();
	for (iFaceNum = 0; iFaceNum < mpcMeshEditor->mcSelections.mcFaces.NumElements(); iFaceNum++)
	{
		psFace = mpcMeshEditor->mpcMesh->GetFace(iFaceNum);
		bSelected = FixBool(mpcMeshEditor->mcSelections.mcFaces.Get(iFaceNum));
		iIndex = mpcSelectionColours->FindWithIntKey(bSelected, 0);
		iNumFaces++;

		if (iIndex != -1)
		{
			psSelectionColour = mpcSelectionColours->Get(iIndex);
			iColour = psSelectionColour->iColour;
		}
		else
		{
			iColour = 0xff808080;
		}

		for (iCornerOffset = 0; iCornerOffset < NUM_FACE_CORNERS; iCornerOffset++)
		{
			psCorner = mpcMeshEditor->mpcMesh->GetCorner(psFace->asCorner[iCornerOffset]);
			AssignCorner(psFace->asCorner[iCornerOffset], iColour, mfZOffset, &aiSkinIndices);
		}
	}
	aiSkinIndices.Kill();

	mpcObject->GrowPrimitive(iNumFaces, D3DPT_TRIANGLELIST, iNumFaces * 3, 0, miMaterialIndex, 0, 0);
}
void CConvexHull::GetVertices(CArrayBlock* pasPositions, SFloat3* psPoints, int iStride)
{
	CArrayInt	aiIndices;
	int			i;
	int			iIndex;
	SFloat3*	psPosition;

	aiIndices.Init(mcPolygons.NumElements()+1);
	GetIndices(&aiIndices, psPoints, iStride);

	for (i = 0; i < aiIndices.NumElements(); i++)
	{
		iIndex = aiIndices.GetValue(i);
		psPosition = GetPosition(psPoints, iStride, iIndex);
		pasPositions->Add(psPosition);
	}

	aiIndices.Kill();
}
int CInputDeviceDesc::GetUnusedID(void)
{
	int				i;
	CInputDevice*	pcDevice;
	CArrayInt		aiIDs;
	int				iID;

	if (mapcDevices.NumElements() == 0)
	{
		return 0;
	}
	else if (mapcDevices.NumElements() == 1)
	{
		pcDevice = *mapcDevices.Get(0);
		if (pcDevice->GetDescriptionID() == 0)
		{
			return 1;
		}
		return 0;
	}

	aiIDs.Init();
	for (i = 0; i < mapcDevices.NumElements(); i++)
	{
		pcDevice = *mapcDevices.Get(i);
		aiIDs.Add(pcDevice->GetDescriptionID());
	}
	aiIDs.QuickSort();
	iID = aiIDs.FindUnusedInSorted();
	aiIDs.Kill();
	return iID;
}
示例#7
0
void TestArrayIntAddFind(void)
{
	CArrayInt	cArray;

	cArray.Init(1);
	cArray.AddList(-1, 1, 2, 3, 4, -1);

	cArray.AddIfUnique(5);

	AssertInt(5, cArray.NumElements());
	AssertInt(1, cArray[0]);
	AssertInt(2, cArray[1]);
	AssertInt(3, cArray[2]);
	AssertInt(4, cArray[3]);
	AssertInt(5, cArray[4]);

	cArray.AddIfUnique(5);

	AssertInt(5, cArray.NumElements());
	AssertInt(1, cArray[0]);
	AssertInt(2, cArray[1]);
	AssertInt(3, cArray[2]);
	AssertInt(4, cArray[3]);
	AssertInt(5, cArray[4]);

	cArray.InsertIntoSorted(2, FALSE);

	AssertInt(6, cArray.NumElements());
	AssertInt(1, cArray[0]);
	AssertInt(2, cArray[1]);
	AssertInt(2, cArray[2]);
	AssertInt(3, cArray[3]);
	AssertInt(4, cArray[4]);
	AssertInt(5, cArray[5]);

	cArray.Kill();
}
void CMeshSelectionConverter::AddSelectedEdges(void)
{
	int					iEdgeNum;
	CMeshEdge*			psEdge;	
	SSelectionColour*	psSelectionColour;
	int					iIndex;
	int					iCornerOffset;
	CMeshCorner*		psCorner;
	int					iNumEdges;
	int					iStartVertex;
	CArrayInt			aiSkinIndices;
	BOOL				bSelected;

	iStartVertex = mpcObject->GetNumberOfVerticesOfType(D3DFVF_CVERTEX);
	iNumEdges = 0;

	aiSkinIndices.Init();
	for (iEdgeNum = 0; iEdgeNum < mpcMeshEditor->mcSelections.mcEdges.NumElements(); iEdgeNum++)
	{
		bSelected = FixBool(mpcMeshEditor->mcSelections.mcEdges.Get(iEdgeNum));
		iIndex = mpcSelectionColours->FindWithIntKey(bSelected, 0);
		if (iIndex != -1)
		{
			psEdge = mpcMeshEditor->mpcMesh->GetEdge(iEdgeNum);
			iNumEdges++;
			psSelectionColour = mpcSelectionColours->Get(iIndex);
			for (iCornerOffset = 0; iCornerOffset < NUM_EDGE_CORNERS; iCornerOffset++)
			{
				psCorner = mpcMeshEditor->mpcMesh->GetCorner(psEdge->aiCorner[iCornerOffset]);
				AssignCorner(psEdge->aiCorner[iCornerOffset], psSelectionColour->iColour, mfZOffset*2, &aiSkinIndices);
			}
		}
	}
	aiSkinIndices.Kill();

	mpcObject->GrowPrimitive(iNumEdges, D3DPT_LINELIST, iNumEdges * 2, 0, miMaterialIndex, 0, 0);
}
示例#9
0
void TestArrayIntSorting(void)
{
	CArrayInt	cArray;

	cArray.Init(1);
	cArray.AddList(-1, 4, 3, 7, 8, 1, 9, 0, 2, 4, 2, -1);

	cArray.QuickSort();

	AssertInt(10, cArray.NumElements());
	AssertInt(0, cArray[0]);
	AssertInt(1, cArray[1]);
	AssertInt(2, cArray[2]);
	AssertInt(2, cArray[3]);
	AssertInt(3, cArray[4]);
	AssertInt(4, cArray[5]);
	AssertInt(4, cArray[6]);
	AssertInt(7, cArray[7]);
	AssertInt(8, cArray[8]);
	AssertInt(9, cArray[9]);

	cArray.InsertIntoSorted(7, FALSE);
	cArray.InsertIntoSorted(1, TRUE);

	AssertInt(11, cArray.NumElements());
	AssertInt(0, cArray[0]);
	AssertInt(1, cArray[1]);
	AssertInt(2, cArray[2]);
	AssertInt(2, cArray[3]);
	AssertInt(3, cArray[4]);
	AssertInt(4, cArray[5]);
	AssertInt(4, cArray[6]);
	AssertInt(7, cArray[7]);
	AssertInt(7, cArray[8]);
	AssertInt(8, cArray[9]);
	AssertInt(9, cArray[10]);

	cArray.Kill();
}
示例#10
0
BOOL CPolygon::UnionPosition(SFloat3* psPosition)
{
	CArrayInt	cIndices;
	int			iInsertionIndex;
	int			i;
	int			iIndex;
	
	if (mbConvex)
	{
		if (On(psPosition))
		{
			if (!Contains(psPosition))
			{
				if (HasPositionPtr(psPosition))
				{
					return TRUE;
				}

				cIndices.Init(4);
				FindIndicesOfVisibleHalfSpaces(psPosition, &cIndices);
				if (cIndices.NumElements() == 0)
				{
					//Something went wrong.
					return FALSE;
				}

				iInsertionIndex = cIndices.GetValue(1);  //End index of the first visible line.

				for (i = 2; i < cIndices.NumElements(); i+= 2)
				{
					iIndex = cIndices.GetValue(i);
					mapsPositions.RemoveAt(iIndex);
					if (iIndex < iInsertionIndex)
					{
						iInsertionIndex--;
					}
				}

				mapsPositions.InsertAt(&psPosition, iInsertionIndex);
				cIndices.Kill();
			}
			return TRUE;
		}
		return FALSE;
	}
	return FALSE;
}
示例#11
0
void TestArrayIntRemoveDuplicates(void)
{
	CArrayInt	cArray;

	cArray.Init(1);
	cArray.AddList(-1, 1, 1, 2, 3, 3, 3, 4, 5, 5, -1);
	cArray.RemoveDuplicatesFromSorted();
	AssertInt(5, cArray.NumElements());
	AssertInt(1, cArray[0]);
	AssertInt(2, cArray[1]);
	AssertInt(3, cArray[2]);
	AssertInt(4, cArray[3]);
	AssertInt(5, cArray[4]);

	cArray.Kill();
}
示例#12
0
void TestArrayIntRemoveAt(void)
{
	CArrayInt	cArray;
	CArrayInt	cKiller;

	////////////////////////////////////////////////
	cArray.Init(1);

	//                 0  1  2  3  4  5  6  7  8  9  Stop
	cArray.AddList(-1, 4, 3, 7, 8, 1, 9, 0, 2, 4, 2, -1);

	AssertInt(10, cArray.NumElements());

	cKiller.Init(1);
	cKiller.AddList(-1, 8, 5, 0, 5, -1);
	cKiller.MakeUnique();

	cArray.RemoveAt(cKiller.GetData(), cKiller.NumElements());

	AssertInt(7, cArray.NumElements());

	AssertInt(3, cArray[0]);
	AssertInt(7, cArray[1]);
	AssertInt(8, cArray[2]);
	AssertInt(1, cArray[3]);
	AssertInt(0, cArray[4]);
	AssertInt(2, cArray[5]);
	AssertInt(2, cArray[6]);

	cKiller.Kill();
	cArray.Kill();

	////////////////////////////////////////////////
	cArray.Init(1);

	//                 0  1  2  3  4  5  6  7  8  9  Stop
	cArray.AddList(-1, 4, 3, 7, 8, 1, 9, 0, 2, 4, 2, -1);

	AssertInt(10, cArray.NumElements());

	cKiller.Init(1);
	cKiller.AddList(-1, 8, 5, 2, -1);
	cKiller.MakeUnique();

	cArray.RemoveAt(cKiller.GetData(), cKiller.NumElements());

	AssertInt(7, cArray.NumElements());

	AssertInt(4, cArray[0]);
	AssertInt(3, cArray[1]);
	AssertInt(8, cArray[2]);
	AssertInt(1, cArray[3]);
	AssertInt(0, cArray[4]);
	AssertInt(2, cArray[5]);
	AssertInt(2, cArray[6]);

	cKiller.Kill();
	cArray.Kill();

	////////////////////////////////////////////////
	cArray.Init(1);

	//                 0  1  2  3  4  5  6  7  8  9  Stop
	cArray.AddList(-1, 4, 3, 7, 8, 1, 9, 0, 2, 4, 2, -1);

	AssertInt(10, cArray.NumElements());

	cKiller.Init(1);
	cKiller.AddList(-1, 0, 1, 2, 7, 8, 9, -1);
	cKiller.MakeUnique();

	cArray.RemoveAt(cKiller.GetData(), cKiller.NumElements());

	AssertInt(4, cArray.NumElements());

	AssertInt(8, cArray[0]);
	AssertInt(1, cArray[1]);
	AssertInt(9, cArray[2]);
	AssertInt(0, cArray[3]);

	cKiller.Kill();
	cArray.Kill();

	////////////////////////////////////////////////
	cArray.Init(1);

	//                 0  1  2  3  4  5  6  7  8  9  Stop
	cArray.AddList(-1, 4, 3, 7, 8, 1, 9, 0, 2, 4, 2, -1);

	AssertInt(10, cArray.NumElements());

	cKiller.Init(1);
	cKiller.AddList(-1, 3, 4, 5, 6, -1);
	cKiller.MakeUnique();

	cArray.RemoveAt(cKiller.GetData(), cKiller.NumElements());

	AssertInt(6, cArray.NumElements());

	AssertInt(4, cArray[0]);
	AssertInt(3, cArray[1]);
	AssertInt(7, cArray[2]);
	AssertInt(2, cArray[3]);
	AssertInt(4, cArray[4]);
	AssertInt(2, cArray[5]);

	cKiller.Kill();
	cArray.Kill();

	////////////////////////////////////////////////
	cArray.Init(1);

	//                 0  1  2  3  4  5  6  7  8  9  Stop
	cArray.AddList(-1, 4, 3, 7, 8, 1, 9, 0, 2, 4, 2, -1);

	cKiller.Init(1);
	cKiller.AddList(-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1);
	cKiller.MakeUnique();

	cArray.RemoveAt(cKiller.GetData(), cKiller.NumElements());

	AssertInt(0, cArray.NumElements());

	cKiller.Kill();
	cArray.Kill();


	////////////////////////////////////////////////
	cArray.Init(1);

	//                 0  1  2  3  4  5  6  7  8  9  Stop
	cArray.AddList(-1, 4, 3, 7, 8, 1, 9, 0, 2, 4, 2, -1);

	cKiller.Init(1);
	cKiller.AddList(-1, -1);
	cKiller.MakeUnique();

	cArray.RemoveAt(cKiller.GetData(), cKiller.NumElements());

	AssertInt(10, cArray.NumElements());

	AssertInt(4, cArray[0]);
	AssertInt(3, cArray[1]);
	AssertInt(7, cArray[2]);
	AssertInt(8, cArray[3]);
	AssertInt(1, cArray[4]);
	AssertInt(9, cArray[5]);
	AssertInt(0, cArray[6]);
	AssertInt(2, cArray[7]);
	AssertInt(4, cArray[8]);
	AssertInt(2, cArray[9]);

	cKiller.Kill();
	cArray.Kill();

	////////////////////////////////////////////////
	cArray.Init(1);

	//                 0  1  2  3  4  5  6  7  8  9  Stop
	cArray.AddList(-1, 4, 3, 7, 8, 1, 9, 0, 2, 4, 2, -1);

	cKiller.Init(1);
	cKiller.AddList(-1, 0, 2, 4, 6, 8, -1);
	cKiller.MakeUnique();

	cArray.RemoveAt(cKiller.GetData(), cKiller.NumElements());

	AssertInt(5, cArray.NumElements());

	AssertInt(3, cArray[0]);
	AssertInt(8, cArray[1]);
	AssertInt(9, cArray[2]);
	AssertInt(2, cArray[3]);
	AssertInt(2, cArray[4]);

	cKiller.Kill();
	cArray.Kill();

	////////////////////////////////////////////////
	cArray.Init(1);

	//                 0  1  2  3  4  5  6  7  8  9  Stop
	cArray.AddList(-1, 4, 3, 7, 8, 1, 9, 0, 2, 4, 2, -1);

	cKiller.Init(1);
	cKiller.AddList(-1, 1, 3, 5, 7, 9, -1);
	cKiller.MakeUnique();

	cArray.RemoveAt(cKiller.GetData(), cKiller.NumElements());

	AssertInt(5, cArray.NumElements());

	AssertInt(4, cArray[0]);
	AssertInt(7, cArray[1]);
	AssertInt(1, cArray[2]);
	AssertInt(0, cArray[3]);
	AssertInt(4, cArray[4]);

	cKiller.Kill();
	cArray.Kill();
}
示例#13
0
void TestArraySorting2(void)
{
	CArrayInt	cInts;

	cInts.Init();
	cInts.Add(4);
	cInts.Add(3);
	cInts.Add(2);
	cInts.Add(1);

	cInts.QuickSort();

	AssertInt(1, cInts.GetValue(0));
	AssertInt(2, cInts.GetValue(1));
	AssertInt(3, cInts.GetValue(2));
	AssertInt(4, cInts.GetValue(3));

	cInts.Kill();

	cInts.Init();
	cInts.Add(4);
	cInts.Add(3);
	cInts.Add(2);
	cInts.Add(1);

	cInts.BubbleSort();

	AssertInt(1, cInts.GetValue(0));
	AssertInt(2, cInts.GetValue(1));
	AssertInt(3, cInts.GetValue(2));
	AssertInt(4, cInts.GetValue(3));

	cInts.Kill();
}