예제 #1
0
파일: LOD.cpp 프로젝트: cpzhang/zen
void LOD::nmCreateObjFile( std::vector<Vector3>& vertices, std::vector<Vector3Int>& indices)
{
    int base = vertices.size();
    for (int i = 0; i != gIndices.size(); )
    {
        int a = base + gIndices[i];
        int b = base + gIndices[i+1];
        int c = base + gIndices[i+2];
        indices.push_back(Vector3Int(a, b, c));
        i = i + 3;
    }
}
예제 #2
0
//-----------------------------------------------------------------------------------
DebugRenderer::SphereCommand::SphereCommand(const Vector3& position, float radius, const RGBA& color, float duration, DepthTestingMode mode)
	: m_position(position)
	, m_radius(radius)
{
	m_color = color;
	m_duration = duration;
	m_mode = mode;
	//Generate points to use for the sphere algorithm
	//We need to start off with an octahedron to keep the faces even.
	std::vector<Vertex_PCT> verts;
	std::vector<Vector3Int> indices;
	Vector3 initialPoints[6] = { { 0, 0, radius }, { 0, 0, -radius }, { -radius, -radius, 0 }, { radius, -radius, 0 }, { radius, radius, 0 }, { -radius,  radius, 0 } };
	Vertex_PCT vert;
	vert.color = color;

	for (int i = 0; i < 6; i++)
	{
		vert.pos = Vector3::GetNormalized(initialPoints[i]) * radius;
		verts.push_back(vert);
	}

 	indices.push_back(Vector3Int(0, 3, 4));
 	indices.push_back(Vector3Int(0, 4, 5));
 	indices.push_back(Vector3Int(0, 5, 2));
 	indices.push_back(Vector3Int(0, 2, 3));
 	indices.push_back(Vector3Int(1, 4, 3));
 	indices.push_back(Vector3Int(1, 5, 4));
 	indices.push_back(Vector3Int(1, 2, 5));
 	indices.push_back(Vector3Int(1, 3, 2));

	for (int i = 0; i < 3; i++)
	{
		int n = indices.size();
		for (int j = 0; j < n; j++)
		{
			// Calculate the midpoints 
			Vector3 point1 = Vector3::GetMidpoint(verts.at(indices.at(j).x).pos, verts.at(indices.at(j).y).pos);
			Vector3 point2 = Vector3::GetMidpoint(verts.at(indices.at(j).y).pos, verts.at(indices.at(j).z).pos);
			Vector3 point3 = Vector3::GetMidpoint(verts.at(indices.at(j).z).pos, verts.at(indices.at(j).x).pos);

			//Move the points to the outside of our sphere.
			point1.Normalize();
			point2.Normalize();
			point3.Normalize();

			//Add these vertices to the list of verts, and store their array location.
			//Naiive way to check for dupes is here. I'll find a better solution later.
			int point1Location = -1;
			int point2Location = -1;
			int point3Location = -1;
			for (unsigned int q = 0; q < verts.size(); q++)
			{
				Vector3 compare = verts.at(q).pos;
				if (compare == point1)
					point1Location = q;
				if (compare == point2)
					point2Location = q;
				if (compare == point3)
					point3Location = q;
			}
			if (point1Location == -1)
			{
				point1Location = verts.size(); 
				vert.pos = point1 * radius;
				verts.push_back(vert);
			}

			if (point2Location == -1)
			{
				point2Location = verts.size();
				vert.pos = point2 * radius;
				verts.push_back(vert);
			}

			if (point3Location == -1)
			{
				point3Location = verts.size();
				vert.pos = point3 * radius;
				verts.push_back(vert);
			}

			//Create 3 new faces (the outer triangles, the pieces of the triforce)
			indices.push_back(Vector3Int(indices.at(j).x, point1Location, point3Location));
			indices.push_back(Vector3Int(point1Location, indices.at(j).y, point2Location));
			indices.push_back(Vector3Int(point3Location, point2Location, indices.at(j).z));

			//Replace the original face with the inner, upside-down triangle (not the triforce)
			indices.at(j).x = point1Location;
			indices.at(j).y = point2Location;
			indices.at(j).z = point3Location;
		}
	}
	//Send sphere to the graphics card
	m_vboId = Renderer::instance->GenerateBufferID();
	m_numVerts = verts.size();
	Renderer::instance->BindAndBufferVBOData(m_vboId, verts.data(), m_numVerts);
}