コード例 #1
0
void MyPrimitive::GeneratePlane(float a_fSize, vector3 a_v3Color)
{
	if (a_fSize < 0.01f)
		a_fSize = 0.01f;

	Release();
	Init();

	float fValue = 0.5f * a_fSize;

	vector3 pointA(-fValue, -fValue, 0.0f); //0
	vector3 pointB(fValue, -fValue, 0.0f); //1
	vector3 pointC(fValue, fValue, 0.0f); //2
	vector3 pointD(-fValue, fValue, 0.0f); //3

	vector3 pointE(fValue, -fValue, -0.001f); //1
	vector3 pointF(-fValue, -fValue, -0.001f); //0
	vector3 pointG(fValue, fValue, -0.001f); //2
	vector3 pointH(-fValue, fValue, -0.001f); //3

											  //F
	AddQuad(pointA, pointB, pointD, pointC);
	//Double sided
	AddQuad(pointE, pointF, pointG, pointH);

	CompileObject(a_v3Color);
}
コード例 #2
0
void MyPrimitive::GenerateTube(float a_fOuterRadius, float a_fInnerRadius, float a_fHeight, int a_nSubdivisions, vector3 a_v3Color)
{
	if (a_nSubdivisions < 3)
		a_nSubdivisions = 3;
	if (a_nSubdivisions > 360)
		a_nSubdivisions = 360;

	Release();
	Init();

	for (int i = 0; i < a_nSubdivisions; i++)
	{
		float ang = (2 * PI) / a_nSubdivisions;

		vector3 point0(a_fOuterRadius*cos((i + 1)*ang), a_fHeight, a_fOuterRadius*sin((i + 1)*ang)); //1
		vector3 point1(a_fOuterRadius*cos(i*ang), 0, a_fOuterRadius*sin(i*ang)); //2
		vector3 point2(a_fOuterRadius*cos(i*ang), a_fHeight, a_fOuterRadius*sin(i*ang)); //0
		vector3 point3(a_fOuterRadius*cos((i + 1)*ang), 0, a_fOuterRadius*sin((i + 1)*ang)); //3

		vector3 point4(a_fInnerRadius*cos((i + 1)*ang), a_fHeight, a_fInnerRadius*sin((i + 1)*ang)); //1
		vector3 point5(a_fInnerRadius*cos(i*ang), 0, a_fInnerRadius*sin(i*ang)); //2
		vector3 point6(a_fInnerRadius*cos(i*ang), a_fHeight, a_fInnerRadius*sin(i*ang)); //0
		vector3 point7(a_fInnerRadius*cos((i + 1)*ang), 0, a_fInnerRadius*sin((i + 1)*ang)); //3

		AddQuad(point4, point0, point6, point2); //Top
		AddQuad(point0, point3, point2, point1); //Outer
		AddQuad(point7, point5, point3, point1); //Bottom
		AddQuad(point5, point7, point6,point4 ); // Inner
		
	}

	//Your code ends here
	CompileObject(a_v3Color);
}
コード例 #3
0
void MyPrimitive::GenerateCone(float a_fRadius, float a_fHeight, int a_nSubdivisions, vector3 a_v3Color)
{
	if (a_nSubdivisions < 3)
		a_nSubdivisions = 3;
	if (a_nSubdivisions > 360)
		a_nSubdivisions = 360;

	Release();
	Init();
	
	vector3 baseCenter(0, 0, 0); //topCenter
	vector3 topCenter(0, a_fHeight, 0); //2
	//AddQuad(baseCenter, pointtopCenter, point3, point2);
	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

		AddQuad(topCenter, point3, point2, baseCenter);
	}

	CompileObject(a_v3Color);
}
コード例 #4
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);
}
コード例 #5
0
void MyPrimitive::GenerateTorus(float a_fOuterRadius, float a_fInnerRadius, int a_nSubdivisionsA, int a_nSubdivisionsB, vector3 a_v3Color)
{
	if (a_fOuterRadius <= a_fInnerRadius + 0.1f)
		return;

	if (a_nSubdivisionsA < 3)
		a_nSubdivisionsA = 3;
	if (a_nSubdivisionsA > 25)
		a_nSubdivisionsA = 25;

	if (a_nSubdivisionsB < 3)
		a_nSubdivisionsB = 3;
	if (a_nSubdivisionsB > 25)
		a_nSubdivisionsB = 25;

	Release();
	Init();

	//Your code starts here
	float fValue = 0.5f;
	//3--2
	//|  |
	//0--1
	vector3 point0(-fValue, -fValue, fValue); //0
	vector3 point1(fValue, -fValue, fValue); //1
	vector3 point2(fValue, fValue, fValue); //2
	vector3 point3(-fValue, fValue, fValue); //3

	AddQuad(point0, point1, point3, point2);

	//Your code ends here
	CompileObject(a_v3Color);
}
コード例 #6
0
void MyPrimitive::GenerateTube(float a_fOuterRadius, float a_fInnerRadius, float a_fHeight, int a_nSubdivisions, vector3 a_v3Color)
{
	if (a_nSubdivisions < 3)
		a_nSubdivisions = 3;
	if (a_nSubdivisions > 360)
		a_nSubdivisions = 360;

	Release();
	Init();

	//Your code starts here
	vector3 base1Center = vector3(0, 0, -a_fHeight / 2);
	vector<vector3> base1InnerPoints = GenerateNGon(a_fInnerRadius, a_nSubdivisions, base1Center);
	vector<vector3> base1OuterPoints = GenerateNGon(a_fOuterRadius, a_nSubdivisions, base1Center);

	vector3 base2Center = vector3(0, 0, a_fHeight / 2);
	vector<vector3> base2InnerPoints = GenerateNGon(a_fInnerRadius, a_nSubdivisions, base2Center);
	vector<vector3> base2OuterPoints = GenerateNGon(a_fOuterRadius, a_nSubdivisions, base2Center);

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

		AddQuad(base2InnerPoints[rightIndex], base2InnerPoints[leftIndex], base1InnerPoints[rightIndex], base1InnerPoints[leftIndex]);
		AddQuad(base2OuterPoints[leftIndex], base2OuterPoints[rightIndex], base1OuterPoints[leftIndex], base1OuterPoints[rightIndex]);

		AddQuad(base2OuterPoints[rightIndex], base2OuterPoints[leftIndex], base2InnerPoints[rightIndex], base2InnerPoints[leftIndex]);
		AddQuad(base1OuterPoints[leftIndex], base1OuterPoints[rightIndex], base1InnerPoints[leftIndex], base1InnerPoints[rightIndex]);
	}

	//Your code ends here
	CompileObject(a_v3Color);
}
コード例 #7
0
void MyPrimitive::GenerateCone(float a_fRadius, float a_fHeight, int a_nSubdivisions, vector3 a_v3Color)
{
	if (a_nSubdivisions < 3)
		a_nSubdivisions = 3;
	if (a_nSubdivisions > 360)
		a_nSubdivisions = 360;

	Release();
	Init();

	//Your code starts here
	vector<vector3> basePoints = GenerateNGon(a_fRadius, a_nSubdivisions, vector3(0, 0, -a_fHeight / 2));
	vector3 vertexPoint = vector3(0, 0, a_fHeight / 2);
	vector3 baseCenter = vector3(0, 0, -a_fHeight / 2);

	for (size_t i = 0; i < a_nSubdivisions; i++)
	{
		AddVertexPosition(basePoints[i]);
		AddVertexPosition(basePoints[(i + 1) % a_nSubdivisions]);
		AddVertexPosition(vertexPoint);

		AddVertexPosition(baseCenter);
		AddVertexPosition(basePoints[(i + 1) % a_nSubdivisions]);
		AddVertexPosition(basePoints[i]);
	}
	

	//Your code ends here
	CompileObject(a_v3Color);
}
コード例 #8
0
void MyPrimitive::GenerateCone
(float a_fRadius, float a_fHeight, int a_nSubdivisions, vector3 a_vColor)
{
	if (a_nSubdivisions < 3)
		a_nSubdivisions = 3;
	if (a_nSubdivisions > 360)
		a_nSubdivisions = 360;

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

	//Your Code Goes Here instead of the next three lines
	//Calculating the bottom vertices
	std::vector<vector3 > vertex;
	vertex.push_back(vector3(0.0f, -a_fHeight / 2.0f, 0.0f));

	GLfloat theta = 0;
	for (int i = 0; i < a_nSubdivisions; i++)
	{
		theta += static_cast<GLfloat>(2 * PI / a_nSubdivisions);
		vector3 temp = vector3(static_cast<GLfloat>(cos(theta)) * a_fRadius,
			-a_fHeight / 2.0f,
			-static_cast<GLfloat>(sin(theta)) * a_fRadius);
		vertex.push_back(temp);
	}

	vertex.push_back(vector3(0.0f, a_fHeight / 2.0f, 0.0f));

	//Bottom Faces
	for (int i = 1; i < a_nSubdivisions; i++)
	{
		AddVertexPosition(vertex[0]);
		AddVertexPosition(vertex[i + 1]);
		AddVertexPosition(vertex[i]);
	}
	AddVertexPosition(vertex[0]);
	AddVertexPosition(vertex[1]);
	AddVertexPosition(vertex[a_nSubdivisions]);

	//Side Faces
	for (int i = 1; i < a_nSubdivisions; i++)
	{
		AddVertexPosition(vertex[i]);
		AddVertexPosition(vertex[i + 1]);
		AddVertexPosition(vertex[a_nSubdivisions + 1]);
	}

	AddVertexPosition(vertex[a_nSubdivisions]);
	AddVertexPosition(vertex[1]);
	AddVertexPosition(vertex[a_nSubdivisions + 1]);

	//Compile the object in this color and assign it this name
	CompileObject(a_vColor);
}
コード例 #9
0
void MyPrimitive::GenerateTorus(float a_fOuterRadius, float a_fInnerRadius, int a_nSubdivisionsA, int a_nSubdivisionsB, vector3 a_v3Color)
{
	if (a_fOuterRadius <= a_fInnerRadius + 0.1f)
		return;

	if (a_nSubdivisionsA < 3)
		a_nSubdivisionsA = 3;
	if (a_nSubdivisionsA > 25)
		a_nSubdivisionsA = 25;

	if (a_nSubdivisionsB < 3)
		a_nSubdivisionsB = 3;
	if (a_nSubdivisionsB > 25)
		a_nSubdivisionsB = 25;

	Release();
	Init();

	//Your code starts here
	//Your code starts here
	
	

	float ringRadius = (a_fOuterRadius - a_fInnerRadius) / 2;
	float radIncrement = (3.1459 * 2) / (a_nSubdivisionsB);

	float z = ringRadius * cos(a_nSubdivisionsB * radIncrement);
	float xRadius = ringRadius * sin(a_nSubdivisionsB * radIncrement);
	vector3 base1Center = vector3(0, 0, z);
	vector<vector3> lastRingPoints = GenerateNGon(a_fInnerRadius + ringRadius + xRadius, a_nSubdivisionsA, base1Center);

	for (int i = a_nSubdivisionsB - 1; i > -1; i--)
	{
		float z = ringRadius * cos(i * radIncrement);
		float xRadius = ringRadius * sin(i * radIncrement);

		vector<vector3> ringPoints = GenerateNGon(a_fInnerRadius + ringRadius + xRadius, a_nSubdivisionsA, vector3(0, 0, z));

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

			AddQuad(lastRingPoints[rightIndex], lastRingPoints[leftIndex], ringPoints[rightIndex], ringPoints[leftIndex]);
		}

		lastRingPoints = ringPoints;
	}

	//Your code ends here
	CompileObject(a_v3Color);
}
コード例 #10
0
void MyPrimitive::GenerateCube(float a_mSize, vector3 a_vColor)
{
	//If the size is less than this make it this large
	if (a_mSize < 0.01f)
		a_mSize = 0.01f;

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

	float fValue = 0.5f * a_mSize;
	//3--2
	//|  |
	//0--1
	vector3 point0(-fValue, -fValue, fValue); //0
	vector3 point1(fValue, -fValue, fValue); //1
	vector3 point2(fValue, fValue, fValue); //2
	vector3 point3(-fValue, fValue, fValue); //3

	//7--6
	//|  |
	//4--5
	vector3 point4(-fValue, -fValue, -fValue); //4
	vector3 point5(fValue, -fValue, -fValue); //5
	vector3 point6(fValue, fValue, -fValue); //6
	vector3 point7(-fValue, fValue, -fValue); //7

	//F
	AddQuad(point0, point1, point3, point2);

	//B
	AddQuad(point5, point4, point6, point7);

	//L
	AddQuad(point4, point0, point7, point3);

	//R
	AddQuad(point1, point5, point2, point6);

	//U
	AddQuad(point3, point2, point7, point6);

	//D
	AddQuad(point4, point5, point0, point1);

	//Compile the object in this color and assign it this name
	CompileObject(a_vColor);
}
コード例 #11
0
void MyPrimitive::GenerateCube(float a_fSize, vector3 a_v3Color)
{
	if (a_fSize < 0.01f)
		a_fSize = 0.01f;

	Release();
	Init();

	float fValue = 0.5f * a_fSize;
	//3--2
	//|  |
	//0--1
	vector3 point0(-fValue, -fValue, fValue); //0
	vector3 point1(fValue, -fValue, fValue); //1
	vector3 point2(fValue, fValue, fValue); //2
	vector3 point3(-fValue, fValue, fValue); //3

	vector3 point4(-fValue, -fValue, -fValue); //4
	vector3 point5(fValue, -fValue, -fValue); //5
	vector3 point6(fValue, fValue, -fValue); //6
	vector3 point7(-fValue, fValue, -fValue); //7

											  //F
	AddQuad(point0, point1, point3, point2);

	//B
	AddQuad(point5, point4, point6, point7);

	//L
	AddQuad(point4, point0, point7, point3);

	//R
	AddQuad(point1, point5, point2, point6);

	//U
	AddQuad(point3, point2, point7, point6);

	//D
	AddQuad(point4, point5, point0, point1);

	CompileObject(a_v3Color);
}
コード例 #12
0
void MyPrimitive::GenerateCylinder(float a_fRadius, float a_fHeight, int a_nSubdivisions, vector3 a_v3Color)
{
	if (a_nSubdivisions < 3)
		a_nSubdivisions = 3;
	if (a_nSubdivisions > 360)
		a_nSubdivisions = 360;

	Release();
	Init();

	//Your code starts here
	float fValue = 0.5f;
	//3--2
	//|  |
	//0--1
	//vector3 point0(-fValue, -fValue, fValue); //0
	//vector3 point1(fValue, -fValue, fValue); //1
	//vector3 point2(fValue, fValue, fValue); //2
	//vector3 point3(-fValue, fValue, fValue); //3
	//
	//AddQuad(point0, point1, point3, point2);
		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);
}
コード例 #13
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);
}
コード例 #14
0
void MyPrimitive::GenerateTube(float a_fOuterRadius, float a_fInnerRadius, float a_fHeight, int a_nSubdivisions, vector3 a_v3Color)
{
	if (a_nSubdivisions < 3)
		a_nSubdivisions = 3;
	if (a_nSubdivisions > 360)
		a_nSubdivisions = 360;

	Release();
	Init();

	//Your code starts here
	std::vector<vector3> outerTopPoints; //outer-top vertices
	std::vector<vector3> outerBasePoints; //outer-base vertices
	for (int x = 0; x < a_nSubdivisions; x++)
	{
		//calculate vertex positions
		float angle = ((2 * PI) / a_nSubdivisions) * x;
		float x_Value = a_fOuterRadius * sin(angle);
		float z_Value = a_fOuterRadius * cos(angle);

		outerBasePoints.push_back(vector3(x_Value, -(a_fHeight / 2), z_Value));
	}
	for (int x = 0; x < a_nSubdivisions; x++)
	{
		//calculate vertex positions
		float angle = ((2 * PI) / a_nSubdivisions) * x;
		float x_Value = a_fOuterRadius * sin(angle);
		float z_Value = a_fOuterRadius * cos(angle);

		outerTopPoints.push_back(vector3(x_Value, a_fHeight / 2, z_Value));
	}
	std::vector<vector3> innerTopPoints; //inner-top vertices
	std::vector<vector3> innerBasePoints; //inner-base vertices
	for (int x = 0; x < a_nSubdivisions; x++)
	{
		//calculate vertex positions
		float angle = ((2 * PI) / a_nSubdivisions) * x;
		float x_Value = a_fInnerRadius * sin(angle);
		float z_Value = a_fInnerRadius * cos(angle);

		innerBasePoints.push_back(vector3(x_Value, -(a_fHeight / 2), z_Value));
	}
	for (int x = 0; x < a_nSubdivisions; x++)
	{
		//calculate vertex positions
		float angle = ((2 * PI) / a_nSubdivisions) * x;
		float x_Value = a_fInnerRadius * sin(angle);
		float z_Value = a_fInnerRadius * cos(angle);

		innerTopPoints.push_back(vector3(x_Value, a_fHeight / 2, z_Value));
	}
	//create outer sides
	for (int x = 0; x < outerBasePoints.size(); x++)
	{
		if (x != outerBasePoints.size() - 1)
		{
			AddQuad(outerBasePoints[x], outerBasePoints[x + 1], outerTopPoints[x], outerTopPoints[x + 1]);
		}
		else
		{
			AddQuad(outerBasePoints[x], outerBasePoints[0], outerTopPoints[x], outerTopPoints[0]);
		}
	}
	//create inner sides
	for (int x = 0; x < innerBasePoints.size(); x++)
	{
		if (x != innerBasePoints.size() - 1)
		{
			AddQuad(innerTopPoints[x], innerTopPoints[x + 1], innerBasePoints[x], innerBasePoints[x + 1]);
		}
		else
		{
			AddQuad(innerTopPoints[x], innerTopPoints[0], innerBasePoints[x], innerBasePoints[0]);
		}
	}
	//create base ring
	for (int x = 0; x < outerBasePoints.size(); x++)
	{
		if (x != outerBasePoints.size() - 1)
		{
			AddQuad(innerBasePoints[x], innerBasePoints[x + 1], outerBasePoints[x], outerBasePoints[x + 1]);
		}
		else
		{
			AddQuad(innerBasePoints[x], innerBasePoints[0], outerBasePoints[x], outerBasePoints[0]);
		}
	}
	//create top ring
	for (int x = 0; x < outerTopPoints.size(); x++)
	{
		if (x != outerTopPoints.size() - 1)
		{
			AddQuad(outerTopPoints[x], outerTopPoints[x + 1], innerTopPoints[x], innerTopPoints[x + 1]);
		}
		else
		{
			AddQuad(outerTopPoints[x], outerTopPoints[0], innerTopPoints[x], innerTopPoints[0]);
		}
	}

	//float fValue = 0.5f;
	////3--2
	////|  |
	////0--1
	//vector3 point0(-fValue, -fValue, fValue); //0
	//vector3 point1(fValue, -fValue, fValue); //1
	//vector3 point2(fValue, fValue, fValue); //2
	//vector3 point3(-fValue, fValue, fValue); //3

	//AddQuad(point0, point1, point3, point2);

	//Your code ends here
	CompileObject(a_v3Color);
}
コード例 #15
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);
}
コード例 #16
0
void MyPrimitive::GenerateTube(float a_fOuterRadius, float a_fInnerRadius, float a_fHeight, int a_nSubdivisions, vector3 a_vColor)
{
	if (a_nSubdivisions < 3)
		a_nSubdivisions = 3;
	if (a_nSubdivisions > 360)
		a_nSubdivisions = 360;

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

	//Your Code Goes Here instead of the next three lines
	//Calculating the top vertices
	std::vector<vector3 > vertexTopOuter;
	GLfloat theta = 0;
	for (int i = 0; i < a_nSubdivisions; i++)
	{
		theta += static_cast<GLfloat>(2 * PI / a_nSubdivisions);
		vector3 temp = vector3(static_cast<GLfloat>(cos(theta)) * a_fOuterRadius,
			a_fHeight / 2.0f,
			-static_cast<GLfloat>(sin(theta)) * a_fOuterRadius);
		vertexTopOuter.push_back(temp);
	}

	std::vector<vector3 > vertexTopInner;
	theta = 0;
	for (int i = 0; i < a_nSubdivisions; i++)
	{
		theta += static_cast<GLfloat>(2 * PI / a_nSubdivisions);
		vector3 temp = vector3(static_cast<GLfloat>(cos(theta)) * a_fInnerRadius,
			a_fHeight / 2.0f,
			-static_cast<GLfloat>(sin(theta)) * a_fInnerRadius);
		vertexTopInner.push_back(temp);
	}

	//Bottom Outer
	for (int i = 0; i < a_nSubdivisions - 1; i++)
	{
		AddVertexPosition(vertexTopInner[i]);
		AddVertexPosition(vertexTopOuter[i]);
		AddVertexPosition(vertexTopOuter[i + 1]);
	}
	AddVertexPosition(vertexTopInner[a_nSubdivisions - 1]);
	AddVertexPosition(vertexTopOuter[a_nSubdivisions - 1]);
	AddVertexPosition(vertexTopOuter[0]);

	//Bottom Inner
	for (int i = 0; i < a_nSubdivisions - 1; i++)
	{
		AddVertexPosition(vertexTopOuter[i + 1]);
		AddVertexPosition(vertexTopInner[i + 1]);
		AddVertexPosition(vertexTopInner[i]);
	}
	AddVertexPosition(vertexTopOuter[0]);
	AddVertexPosition(vertexTopInner[0]);
	AddVertexPosition(vertexTopInner[a_nSubdivisions - 1]);

	//Calculating the bottom vertices
	std::vector<vector3 > vertexBottomOuter;
	theta = 0;
	for (int i = 0; i < a_nSubdivisions; i++)
	{
		theta += static_cast<GLfloat>(2 * PI / a_nSubdivisions);
		vector3 temp = vector3(static_cast<GLfloat>(cos(theta)) * a_fOuterRadius,
			-a_fHeight / 2.0f,
			-static_cast<GLfloat>(sin(theta)) * a_fOuterRadius);
		vertexBottomOuter.push_back(temp);
	}

	std::vector<vector3 > vertexBottomInner;
	theta = 0;
	for (int i = 0; i < a_nSubdivisions; i++)
	{
		theta += static_cast<GLfloat>(2 * PI / a_nSubdivisions);
		vector3 temp = vector3(static_cast<GLfloat>(cos(theta)) * a_fInnerRadius,
			-a_fHeight / 2.0f,
			-static_cast<GLfloat>(sin(theta)) * a_fInnerRadius);
		vertexBottomInner.push_back(temp);
	}

	//Bottom Outer
	for (int i = 0; i < a_nSubdivisions - 1; i++)
	{
		AddVertexPosition(vertexBottomOuter[i + 1]);
		AddVertexPosition(vertexBottomOuter[i]);
		AddVertexPosition(vertexBottomInner[i]);
	}
	AddVertexPosition(vertexBottomOuter[0]);
	AddVertexPosition(vertexBottomOuter[a_nSubdivisions - 1]);
	AddVertexPosition(vertexBottomInner[a_nSubdivisions - 1]);


	//Bottom Inner
	for (int i = 0; i < a_nSubdivisions - 1; i++)
	{
		AddVertexPosition(vertexBottomInner[i]);
		AddVertexPosition(vertexBottomInner[i + 1]);
		AddVertexPosition(vertexBottomOuter[i + 1]);
	}
	AddVertexPosition(vertexBottomInner[a_nSubdivisions - 1]);
	AddVertexPosition(vertexBottomInner[0]);
	AddVertexPosition(vertexBottomOuter[0]);

	//Vertical Inner
	for (int i = 0; i < a_nSubdivisions - 1; i++)
	{
		AddVertexPosition(vertexTopInner[i]);
		AddVertexPosition(vertexBottomInner[i + 1]);
		AddVertexPosition(vertexBottomInner[i]);
	}
	AddVertexPosition(vertexTopInner[a_nSubdivisions - 1]);
	AddVertexPosition(vertexBottomInner[0]);
	AddVertexPosition(vertexBottomInner[a_nSubdivisions - 1]);

	for (int i = 0; i < a_nSubdivisions - 1; i++)
	{
		AddVertexPosition(vertexTopInner[i + 1]);
		AddVertexPosition(vertexBottomInner[i + 1]);
		AddVertexPosition(vertexTopInner[i]);
	}
	AddVertexPosition(vertexTopInner[0]);
	AddVertexPosition(vertexBottomInner[0]);
	AddVertexPosition(vertexTopInner[a_nSubdivisions - 1]);

	//Vertical Outer
	for (int i = 0; i < a_nSubdivisions - 1; i++)
	{
		AddVertexPosition(vertexBottomOuter[i]);
		AddVertexPosition(vertexBottomOuter[i + 1]);
		AddVertexPosition(vertexTopOuter[i]);
	}
	AddVertexPosition(vertexBottomOuter[a_nSubdivisions - 1]);
	AddVertexPosition(vertexBottomOuter[0]);
	AddVertexPosition(vertexTopOuter[a_nSubdivisions - 1]);

	for (int i = 0; i < a_nSubdivisions - 1; i++)
	{
		AddVertexPosition(vertexTopOuter[i + 1]);
		AddVertexPosition(vertexTopOuter[i]);
		AddVertexPosition(vertexBottomOuter[i + 1]);
	}
	AddVertexPosition(vertexTopOuter[0]);
	AddVertexPosition(vertexTopOuter[a_nSubdivisions - 1]);
	AddVertexPosition(vertexBottomOuter[0]);

	//Compile the object in this color and assign it this name
	CompileObject(a_vColor);
}
コード例 #17
0
void MyPrimitive::GenerateCylinder(float a_fRadius, float a_fHeight, int a_nSubdivisions, vector3 a_vColor)
{
	if (a_nSubdivisions < 3)
		a_nSubdivisions = 3;
	if (a_nSubdivisions > 360)
		a_nSubdivisions = 360;

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

	//Calculating the bottom vertices
	std::vector<vector3 > vertexB;
	vertexB.push_back(vector3(0.0f, -a_fHeight / 2.0f, 0.0f));
	GLfloat theta = 0;
	for (int i = 0; i < a_nSubdivisions; i++)
	{
		theta += static_cast<GLfloat>(2 * PI / a_nSubdivisions);
		vector3 temp = vector3(static_cast<GLfloat>(cos(theta)) * a_fRadius,
			-a_fHeight / 2.0f,
			-static_cast<GLfloat>(sin(theta)) * a_fRadius);
		vertexB.push_back(temp);
	}

	//calculating the top vertices
	std::vector<vector3 > vertexU;
	vertexU.push_back(vector3(0.0f, a_fHeight / 2.0f, 0.0f));
	theta = 0;
	vector3 vHeight = vector3(0.0f, a_fHeight, 0.0f);
	for (int i = 0; i < a_nSubdivisions; i++)
	{
		vertexU.push_back(vertexB[i + 1] + vHeight);
	}

	//Bottom Faces
	for (int i = 1; i < a_nSubdivisions; i++)
	{
		AddVertexPosition(vertexB[0]);
		AddVertexPosition(vertexB[i + 1]);
		AddVertexPosition(vertexB[i]);
	}
	AddVertexPosition(vertexB[0]);
	AddVertexPosition(vertexB[1]);
	AddVertexPosition(vertexB[a_nSubdivisions]);

	//Top Faces
	for (int i = 1; i < a_nSubdivisions; i++)
	{
		AddVertexPosition(vertexU[0]);
		AddVertexPosition(vertexU[i]);
		AddVertexPosition(vertexU[i + 1]);
	}
	AddVertexPosition(vertexU[0]);
	AddVertexPosition(vertexU[a_nSubdivisions]);
	AddVertexPosition(vertexU[1]);

	//Side Faces
	for (int i = 1; i < a_nSubdivisions; i++)
	{
		AddVertexPosition(vertexB[i]);
		AddVertexPosition(vertexB[i + 1]);
		AddVertexPosition(vertexU[i]);

		AddVertexPosition(vertexU[i]);
		AddVertexPosition(vertexB[i + 1]);
		AddVertexPosition(vertexU[i + 1]);
	}
	AddVertexPosition(vertexB[a_nSubdivisions]);
	AddVertexPosition(vertexB[1]);
	AddVertexPosition(vertexU[a_nSubdivisions]);

	AddVertexPosition(vertexU[a_nSubdivisions]);
	AddVertexPosition(vertexB[1]);
	AddVertexPosition(vertexU[1]);

	//Compile the object in this color and assign it this name
	CompileObject(a_vColor);
}
コード例 #18
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
	vector3 topPoint(0.00f, a_fRadius, 0.00f);
	vector3 bottomPoint(0.00f, -a_fRadius, 0.00f);
	std::vector<std::vector<vector3>> spherePoints; //holds all other vertices on the sphere

	//add the middle ring of vertices; if the number of subdivisions is even, there are two middle rings
	if (a_nSubdivisions % 2 == 0)
	{
		std::vector<vector3> topMiddleRing;
		for (int x = 0; x < a_nSubdivisions; x++)
		{
			//calculate vertex positions
			float angle = ((2 * PI) / a_nSubdivisions) * x;
			float x_Value = a_fRadius * sin(angle);
			float z_Value = a_fRadius * cos(angle);

			topMiddleRing.push_back(vector3(x_Value, a_fRadius / (2 * a_nSubdivisions), z_Value));
		}
		std::vector<vector3> bottomMiddleRing;
		for (int x = 0; x < a_nSubdivisions; x++)
		{
			//calculate vertex positions
			float angle = ((2 * PI) / a_nSubdivisions) * x;
			float x_Value = a_fRadius * sin(angle);
			float z_Value = a_fRadius * cos(angle);

			bottomMiddleRing.push_back(vector3(x_Value, -a_fRadius / (2 * a_nSubdivisions), z_Value));
		}
		spherePoints.push_back(topMiddleRing);
		spherePoints.push_back(bottomMiddleRing);
	}
	else
	{
		std::vector<vector3> middleRing;
		for (int x = 0; x < a_nSubdivisions; x++)
		{
			//calculate vertex positions
			float angle = ((2 * PI) / a_nSubdivisions) * x;
			float x_Value = a_fRadius * sin(angle);
			float z_Value = a_fRadius * cos(angle);

			middleRing.push_back(vector3(x_Value, 0.00f, z_Value));
		}
		spherePoints.push_back(middleRing);
	}

	//add more rings to the sphere equal to the number of subdivisions minus existing rings
	//rings can be added in pairs moving away from the middle ring/rings in both directions,
	//so the loop will run half the number of times
	int existingRings = spherePoints.size();
	for (int x = 0; x < (a_nSubdivisions -  existingRings)/ 2; x++)
	{
		std::vector<vector3> upperRing;
		std::vector<vector3> lowerRing;
		//get an adjusted radius for this pair of rings
		float adjustedRadius = (a_fRadius / ((a_nSubdivisions / 2) + 1)) * ((a_nSubdivisions / 2) - x);

		for (int y = 0; y < a_nSubdivisions; y++)
		{
			//calculate vertex positions
			float angle = ((2 * PI) / a_nSubdivisions) * y;
			float x_Value = adjustedRadius * sin(angle);
			float z_Value = adjustedRadius * cos(angle);

			upperRing.push_back(vector3(x_Value, a_fRadius - adjustedRadius, z_Value));
			lowerRing.push_back(vector3(x_Value, -a_fRadius + adjustedRadius, z_Value));
		}
		spherePoints.push_back(upperRing);
		spherePoints.push_back(lowerRing);
	}

	//draw quads around the sphere moving away from the middle ring/rings
	if (a_nSubdivisions % 2 == 0)
	{
		//draw middle ring of quads
		for (int x = 0; x < spherePoints[0].size(); x++)
		{
			if (x != spherePoints[0].size() - 1)
			{
				AddQuad(spherePoints[1][x], spherePoints[1][x + 1], spherePoints[0][x], spherePoints[0][x + 1]);
			}
			else
			{
				AddQuad(spherePoints[1][x], spherePoints[1][0], spherePoints[0][x], spherePoints[0][0]);
			}
		}
		//draw more rings of quads
		for (int x = 0; x < spherePoints.size() - 2; x++)
		{
			if (x % 2 == 0)
			{
				for (int y = 0; y < spherePoints[x].size(); y++)
				{
					if (y != spherePoints[x].size() - 1)
					{
						AddQuad(spherePoints[x][y], spherePoints[x][y + 1], spherePoints[x + 2][y], spherePoints[x + 2][y + 1]);
					}
					else
					{
						AddQuad(spherePoints[x][y], spherePoints[x][0], spherePoints[x + 2][y], spherePoints[x + 2][0]);
					}
				}
			}
			else
			{
				for (int y = 0; y < spherePoints[x].size(); y++)
				{
					if (y != spherePoints[x].size() - 1)
					{
						AddQuad(spherePoints[x + 2][y], spherePoints[x + 2][y + 1], spherePoints[x][y], spherePoints[x][y + 1]);
					}
					else
					{
						AddQuad(spherePoints[x + 2][y], spherePoints[x + 2][0], spherePoints[x][y], spherePoints[x][0]);
					}
				}
			}
		}
	}
	else
	{

	}

	//draw the tris for the top and bottom
	for (int x = 0; x < spherePoints[spherePoints.size() - 1].size(); x++)
	{
		AddVertexPosition(bottomPoint);
		if (x == spherePoints[spherePoints.size() - 1].size() - 1)
		{
			AddVertexPosition(spherePoints[spherePoints.size() - 1][0]);
		}
		else
		{
			AddVertexPosition(spherePoints[spherePoints.size() - 1][x + 1]);
		}
		AddVertexPosition(spherePoints[spherePoints.size() - 1][x]);
	}
	for (int x = 0; x < spherePoints[spherePoints.size() - 2].size(); x++)
	{
		AddVertexPosition(spherePoints[spherePoints.size() - 2][x]);
		if (x == spherePoints[spherePoints.size() - 2].size() - 1)
		{
			AddVertexPosition(spherePoints[spherePoints.size() - 2][0]);
		}
		else
		{
			AddVertexPosition(spherePoints[spherePoints.size() - 2][x + 1]);
		}
		AddVertexPosition(topPoint);
	}

	//float fValue = 0.5f;
	////3--2
	////|  |
	////0--1
	//vector3 point0(-fValue, -fValue, fValue); //0
	//vector3 point1(fValue, -fValue, fValue); //1
	//vector3 point2(fValue, fValue, fValue); //2
	//vector3 point3(-fValue, fValue, fValue); //3

	//AddQuad(point0, point1, point3, point2);

	//Your code ends here
	CompileObject(a_v3Color);
}
コード例 #19
0
void MyPrimitive::GenerateCylinder(float a_fRadius, float a_fHeight, int a_nSubdivisions, vector3 a_v3Color)
{
	if (a_nSubdivisions < 3)
		a_nSubdivisions = 3;
	if (a_nSubdivisions > 360)
		a_nSubdivisions = 360;

	Release();
	Init();

	//Your code starts here
	vector3 topMid(0.00f, a_fHeight / 2, 0.00f); //mid-top vertex
	vector3 baseMid(0.00f, -(a_fHeight / 2), 0.00f); //mid-base vertex
	std::vector<vector3> topPoints; //top vertices
	std::vector<vector3> basePoints; //base vertices
	for (int x = 0; x < a_nSubdivisions; x++)
	{
		//calculate vertex positions
		float angle = ((2 * PI) / a_nSubdivisions) * x;
		float x_Value = a_fRadius * sin(angle);
		float z_Value = a_fRadius * cos(angle);

		basePoints.push_back(vector3(x_Value, -(a_fHeight / 2), z_Value));
	}
	for (int x = 0; x < a_nSubdivisions; x++)
	{
		//calculate vertex positions
		float angle = ((2 * PI) / a_nSubdivisions) * x;
		float x_Value = a_fRadius * sin(angle);
		float z_Value = a_fRadius * cos(angle);

		topPoints.push_back(vector3(x_Value, a_fHeight / 2, z_Value));
	}
	//create base
	for (int x = 0; x < basePoints.size(); x++)
	{
		AddVertexPosition(baseMid);
		if (x == basePoints.size() - 1)
		{
			AddVertexPosition(basePoints[0]);
		}
		else
		{
			AddVertexPosition(basePoints[x + 1]);
		}
		AddVertexPosition(basePoints[x]);
	}
	//create top
	for (int x = 0; x <topPoints.size(); x++)
	{
		AddVertexPosition(topMid);
		AddVertexPosition(topPoints[x]);
		if (x == topPoints.size() - 1)
		{
			AddVertexPosition(topPoints[0]);
		}
		else
		{
			AddVertexPosition(topPoints[x + 1]);
		}
	}
	//create sides
	for (int x = 0; x < basePoints.size(); x++)
	{
		if (x != basePoints.size() - 1)
		{
			AddQuad(basePoints[x], basePoints[x + 1], topPoints[x], topPoints[x + 1]);
		}
		else
		{
			AddQuad(basePoints[x], basePoints[0], topPoints[x], topPoints[0]);
		}
	}

	//float fValue = 0.5f;
	////3--2
	////|  |
	////0--1
	//vector3 point0(-fValue, -fValue, fValue); //0
	//vector3 point1(fValue, -fValue, fValue); //1
	//vector3 point2(fValue, fValue, fValue); //2
	//vector3 point3(-fValue, fValue, fValue); //3

	//AddQuad(point0, point1, point3, point2);

	//Your code ends here
	CompileObject(a_v3Color);
}