Exemplo n.º 1
0
void Rasterizer::DrawPolygon(NPolygon poly)
{
	int sides;
	vector<Vertex> vertices = poly.GetVertices();
	NPolygon polex;
	if ( _texMap )
	{
		ProjectVerts(vertices);
		polex = ClipCheck(vertices);
		vector<Edge> edges = polex.GetEdges();
		sides = polex.GetSides();
		if ( sides == 0)
			return;
		CheckEdges(edges , sides);
		DrawSpanBetweenBuffers();
		ResetBounds();
	}
	else
	{
		ProjectVerts(vertices);
		polex = ClipCheck(vertices);
		sides = polex.GetSides();
		vertices = polex.GetVertices();
		if ( sides == 0)
			return;
		for(int i = 0; i < sides; i++)
		{
			DrawLine(vertices[i], vertices[(i+1)%sides]);
		}
	}

}
void ConstructTable(NodeEdge **nodeEdges, Node** nodes, int numNodes, Edge** edges, int* tableLength, int* check, int* next)
{
	/*TODO: Check if we can get out of the array bounds.*/
	for (int i = 0; i < (*tableLength); i++)
	{
		check[i] = 0;
	}
	//int freeIndex = 0;

	/*root node is at index 1.*/
	for (int i = 1; i <= numNodes; i++)
	{
		if(nodes[i]->numberofEdges == 0)
			continue;

		//NodeEdge* ne = nodeEdges[nodes[i]->edgeStartIndex];
		while(nodes[i]->baseAddress == -1)
		{
			for (int j = 0; j < (*tableLength); j++)
			{
				if(check[j] != 0 || (CheckEdges(nodes[i], nodeEdges, check, j, *tableLength) == 0))
					continue;
			
				nodes[i]->baseAddress = j;
				break;
			}

			/*We haven't found spot for the node. That means we need to increase the arrays*/
			if(nodes[i]->baseAddress == -1)
			{
				(*tableLength) *= 2;
				check = (int*) realloc(check, (*tableLength)*sizeof(int));

				next = (int*) realloc(next, (*tableLength)*sizeof(int));

				for (int k = (*tableLength); k < (*tableLength); k++)
				{
					check[k] = 0;
				}
			
				//nodes[i]->baseAddress = *tableLength;
			}
		}
		SetEdges(nodeEdges, check, next, nodes[i]->baseAddress, nodes[i]);
	}

	if((lastIndex + 1) < (*tableLength))
	{		
		lastIndex++;
		check= (int*) realloc(check, (lastIndex)*sizeof(int));
		next = (int*) realloc(next, (lastIndex)*sizeof(int));
		(*tableLength) = lastIndex;
	}

	return;
}
Exemplo n.º 3
0
Matrix4 Particles::BuildTransform()
{
	copyArrayFromDevice(buoyancy, buoyancyGpu, 0, sizeof(float)* 4 * numParticles);
	copyArrayFromDevice(buoyancyAng, buoyancyAngGpu, 0, sizeof(float)* 4 * numParticles);

	float* force = new float[4];
	
	for (int i = 0; i < numParticles; i++)
	{
		force[0] += buoyancy[i * 4];
		force[1] += buoyancy[i * 4 + 1];
		force[2] += buoyancy[i * 4 + 2];
		force[3] = 0;

		Vector3 ang = Vector3(buoyancyAng[i * 4], buoyancyAng[i * 4 + 1], buoyancyAng[i * 4 + 2]);
		if (ang.x != 0 || ang.y != 0 || ang.z != 0)
		{
			orientation = orientation + orientation * (ang / 20000000.0f);
			orientation.Normalise();
		}
	}
	force[1] -= 9.81f * 2000.0f;
	for (int i = 0; i < 4; i++)
	{
		solidVel[i] = solidVel[i] + force[i] * mparams.timeStep;
	}
	CheckEdges(solidPos, solidVel);
	copyArrayToDevice(solidPosGpu, solidPos, 0, 4 * sizeof(float));
	copyArrayToDevice(solidVelGpu, solidVel, 0, 4 * sizeof(float));

	//orientation.Normalise();
	Matrix4 m = orientation.ToMatrix();
	Vector3 p = Vector3(solidPos[0], solidPos[1], solidPos[2]);
	m.SetPositionVector(p);
	return m;
}