コード例 #1
0
void MyPrimitive::GenerateSphere(float a_fRadius, int a_nSubdivisions, vector3 a_v3Color)
{
	//Sets minimum and maximum of subdivisions
	if (a_nSubdivisions < 1)
	{
		GenerateCube(a_fRadius * 2, a_v3Color);
		return;
	}
	if (a_nSubdivisions > 12)
		a_nSubdivisions = 12;

	Release();
	Init();

	//Your code starts here
	vector3 base1Center = vector3(0, 0, 0);
	vector<vector3> centerRingPoints = GenerateNGon(a_fRadius, a_nSubdivisions, base1Center);
	vector<vector3> prevUpperRingPoints = centerRingPoints;
	vector<vector3> prevLowerRingPoints = centerRingPoints;

	vector3 topCenter = vector3(0, 0, a_fRadius);
	vector3 bottomCenter = vector3(0, 0, -a_fRadius);

	float radIncrement = (3.1459 / 2) / (a_nSubdivisions / 2);
	for (size_t i = a_nSubdivisions / 2; i > 0; i--)
	{
		float z = a_fRadius * cos(i * radIncrement);
		float xRadius = a_fRadius * sin(i * radIncrement);

		vector<vector3> upperRingPoints = GenerateNGon(xRadius, a_nSubdivisions, vector3(0, 0, z));
		vector<vector3> lowerRingPoints = GenerateNGon(xRadius, a_nSubdivisions, vector3(0, 0, -z));

		for (size_t j = 0; j < a_nSubdivisions; j++)
		{
			int rightIndex = j;
			int leftIndex = (j + 1) % a_nSubdivisions;

			AddQuad(prevUpperRingPoints[rightIndex], prevUpperRingPoints[leftIndex], upperRingPoints[rightIndex], upperRingPoints[leftIndex]);
			AddQuad(prevLowerRingPoints[leftIndex], prevLowerRingPoints[rightIndex], lowerRingPoints[leftIndex], lowerRingPoints[rightIndex]);

			if (i == 1) {
				AddVertexPosition(upperRingPoints[rightIndex]);
				AddVertexPosition(upperRingPoints[leftIndex]);
				AddVertexPosition(topCenter);

				AddVertexPosition(bottomCenter);
				AddVertexPosition(lowerRingPoints[leftIndex]);
				AddVertexPosition(lowerRingPoints[rightIndex]);
				
			}
		}

		prevUpperRingPoints = upperRingPoints;
		prevLowerRingPoints = lowerRingPoints;
	}


	//Your code ends here
	CompileObject(a_v3Color);
}
コード例 #2
0
void ASimpleCubeActor::GenerateMesh()
{
	FProceduralMeshData MeshData = FProceduralMeshData();
	GenerateCube(MeshData, Depth, Width, Height);
	ProcMesh->ClearAllMeshSections();
	ProcMesh->CreateMeshSection(0, MeshData.Vertices, MeshData.Triangles, MeshData.Normals, MeshData.UVs, MeshData.VertexColors, MeshData.Tangents, false);
	ProcMesh->SetMaterial(0, Material);
}
コード例 #3
0
ファイル: VoxelChunkMesh.cpp プロジェクト: Overdrivr/Wizlords
void NzVoxelChunkMesh::GenerateMesh(NzVoxelArray& voxelArray)
{
    m_faceCount = 0;
    m_vertexCount = 0;
    m_vertexData.clear();

    for(unsigned int x(0) ; x < NAZARA_VOXELENGINE_CHUNKSIZE_X ; ++x)
        for(unsigned int y(0) ; y < NAZARA_VOXELENGINE_CHUNKSIZE_Y ; ++y)
            for(unsigned int z(0) ; z < NAZARA_VOXELENGINE_CHUNKSIZE_Z ; ++z)
            {
                GenerateCube(voxelArray,x,y,z);
            }
}
コード例 #4
0
ConvexMesh::ConvexMesh(int type, float length)
{
	//Not elegant but it will do for now
	if(type == 0)	//Cube
	{
		GenerateCube(length);		
	}
	else			//Pyramid
	{
		GeneratePyramid(length);		
	}
	generateObjectBuffer();
}
コード例 #5
0
void MyPrimitive::GenerateSphere(float a_fRadius, int a_nSubdivisions, vector3 a_v3Color)
{
	//Sets minimum and maximum of subdivisions
	if (a_nSubdivisions < 1)
	{
		GenerateCube(a_fRadius * 2, a_v3Color);
		return;
	}
	if (a_nSubdivisions > 6)
		a_nSubdivisions = 6;

	Release();
	Init();

	//Your code starts here
	float a_fHeight;
	vector3 point0(0, 0, 0);
	vector3 point1(0, a_fHeight, 0);
	for (int i = 0; i < a_nSubdivisions; i++)
	{
		float ang = (2 * PI) / a_nSubdivisions;


		vector3 point2(a_fRadius*cos(i*ang), 0, a_fRadius*sin(i*ang)); //0
		vector3 point3(a_fRadius*cos((i + 1)*ang), 0, a_fRadius*sin((i + 1)*ang)); //3


		vector3 point4(a_fRadius*cos(i*ang), a_fHeight, a_fRadius*sin(i*ang)); //0
		vector3 point5(a_fRadius*cos((i + 1)*ang), a_fHeight, a_fRadius*sin((i + 1)*ang)); //3

		AddQuad(point1, point3, point2, point4);
		AddQuad(point1, point4, point5, point3);
	}



	//Your code ends here
	CompileObject(a_v3Color);
}
コード例 #6
0
void MyPrimitive::GenerateSphere(float a_fRadius, int a_nSubdivisions, vector3 a_vColor)
{
	//Sets minimum and maximum of subdivisions
	if (a_nSubdivisions < 1)
	{
		GenerateCube(a_fRadius * 2, a_vColor);
		return;
	}
	if (a_nSubdivisions > 6)
		a_nSubdivisions = 6;

	//Clean up Memory
	Release();
	Init();

	//Your Code Goes Here instead of the next three lines
	float fValue = 0.5f;
	vector3 pointA(-fValue, -fValue, fValue); //0
	vector3 pointB(fValue, -fValue, fValue); //1
	vector3 pointC(-fValue, fValue, fValue); //2

	//left to right List of vector3
	std::vector<vector3> vectorAB;
	vectorAB.push_back(pointA);
	for (int i = 0; i < a_nSubdivisions; i++)
	{
		vector3 temp(pointB - pointA);
		temp /= a_nSubdivisions + 1;
		temp *= (i + 1);
		vectorAB.push_back(temp + pointA);
	}
	vectorAB.push_back(pointB);

	//height increments
	float fHeight = pointC.y - pointA.y;
	fHeight /= a_nSubdivisions + 1;

	//List of Lists
	std::vector<std::vector<vector3>> list;
	list.push_back(vectorAB);
	for (int j = 0; j < a_nSubdivisions + 1; j++)
	{
		std::vector<vector3> temp = list[0];
		float increment = fHeight * (j + 1);
		for (int i = 0; i < a_nSubdivisions + 2; i++)
		{
			temp[i].y += increment;
		}
		list.push_back(temp);
	}

	//Creating the patch of quads
	for (int j = 0; j < a_nSubdivisions + 1; j++)
	{
		for (int i = 0; i < a_nSubdivisions + 1; i++)
		{
			AddQuad(list[j][i], list[j][i + 1], list[j + 1][i], list[j + 1][i + 1]);
		}
	}
	
	int nVertices = static_cast<int>(m_lVertexPos.size());

	//normalizing the vectors to make them round
	for (int i = 0; i < nVertices; i++)
	{
		m_lVertexPos[i] = glm::normalize(m_lVertexPos[i]);
		m_lVertexPos[i] *= a_fRadius;
	}

	//RightSideFace
	std::vector<vector3> right;
	for (int i = 0; i < nVertices; i++)
	{
		matrix4 rotation;
		rotation = glm::rotate(matrix4(1.0f), 90.0f, vector3(0.0f, 1.0f, 0.0f));
		right.push_back(static_cast <vector3>(rotation * vector4(m_lVertexPos[i], 1.0f)));
	}


	for (int i = 0; i < nVertices; i++)
	{
		AddVertexPosition(right[i]);
	}

	//LeftSideFace
	std::vector<vector3> left;
	for (int i = 0; i < nVertices; i++)
	{
		matrix4 rotation;
		rotation = glm::rotate(matrix4(1.0f), -90.0f, vector3(0.0f, 1.0f, 0.0f));
		left.push_back(static_cast <vector3>(rotation * vector4(m_lVertexPos[i], 1.0f)));
	}

	for (int i = 0; i < nVertices; i++)
	{
		AddVertexPosition(left[i]);
	}

	//BackSideFace
	std::vector<vector3> back;
	for (int i = 0; i < nVertices; i++)
	{
		matrix4 rotation;
		rotation = glm::rotate(matrix4(1.0f), 180.0f, vector3(0.0f, 1.0f, 0.0f));
		back.push_back(static_cast <vector3>(rotation * vector4(m_lVertexPos[i], 1.0f)));
	}

	for (int i = 0; i < nVertices; i++)
	{
		AddVertexPosition(back[i]);
	}

	//TopSideFace
	std::vector<vector3> top;
	for (int i = 0; i < nVertices; i++)
	{
		matrix4 rotation;
		rotation = glm::rotate(matrix4(1.0f), -90.0f, vector3(1.0f, 0.0f, 0.0f));
		top.push_back(static_cast <vector3>(rotation * vector4(m_lVertexPos[i], 1.0f)));
	}

	for (int i = 0; i < nVertices; i++)
	{
		AddVertexPosition(top[i]);
	}

	//BottomSideFace
	std::vector<vector3> bottom;
	for (int i = 0; i < nVertices; i++)
	{
		matrix4 rotation;
		rotation = glm::rotate(matrix4(1.0f), 90.0f, vector3(1.0f, 0.0f, 0.0f));
		bottom.push_back(static_cast <vector3>(rotation * vector4(m_lVertexPos[i], 1.0f)));
	}

	for (int i = 0; i < nVertices; i++)
	{
		AddVertexPosition(bottom[i]);
	}

	//Compile the object in this color and assign it this name
	CompileObject(a_vColor);
}
コード例 #7
0
// What about texture coordinates?
UniqueMeshPtr GeoPrimitiveGenerator::GenerateCube( I32 unitsAlongX, I32 unitsAlongY, I32 unitsAlongZ ) {
	UniqueMeshPtr ptr( new Mesh() );
	GenerateCube( unitsAlongX, unitsAlongY, unitsAlongZ, *ptr );
	return ptr;
}