Пример #1
0
// --------------------------------------------------------------------
Landscape::Landscape(int ClipmapRimWidth, float VerticesInterval):
RestartIndex(0xFFFFFFFF), Offset(VerticesInterval), VBOSize(0), IBOSize(0), TBOSize(0), HeightData(0), HeightDataSize(0), StartIndexX(0), StartIndexY(0)
{
	ClipmapIBOsData = new unsigned int*[IBO_MODES_AMOUNT];

	IBOSize = new unsigned int[IBO_MODES_AMOUNT];

	ClipmapVBOWidth = ClipmapRimWidth * 4 + 4;
	TBOSize = ClipmapRimWidth * 4 + 5;

	CreateVBO();

	for (int i = 0; i < IBO_MODES_AMOUNT; ++i)
		CreateIBO((ClipmapIBOMode)i);


	HeightDataSize = 424;
	StartIndexX = StartIndexY = 210;

	HeightData = new float[HeightDataSize * HeightDataSize];

	LOG("Generating terrain data...");

	for (unsigned int i = 0; i < HeightDataSize; ++i)
	{
		for (unsigned int j = 0; j < HeightDataSize; ++j)
		{
			//HeightData[i + HeightDataSize * j] = 10.0f + i / 10.0f;
			//HeightData[i + HeightDataSize * j] = (i % 32) / 8.0f + 430.0f;
			//HeightData[i + HeightDataSize * j] = (j % 512 == 113 || i % 512 == 113) ? (20.0f) : (0.0f);
			//HeightData[i + HeightDataSize * j] = 93.8f;
			//HeightData[i + HeightDataSize * j] = 50.0f + sin(float(i) / 3.0f) * 1.0f + sin(float(j) / 5.6f) * 1.6f;
			//HeightData[i + HeightDataSize * j] = 20.0f + j / 11.0f + i / 4.36f;
			//HeightData[i + HeightDataSize * j] = sin(float(j) / 400.f) * 80.0f + 300.0f;
			HeightData[i + HeightDataSize * j] = 70.0f + sin(float(i) / 10.0f) * 2.0f + sin(float(j) / 25.6f) * 10.6f;

			//float a = sin(float(i) / (1.0 * 704.0f)) * 30.0f;
			//float b = sin(float(i) / (1.0 * 352.0f)) * 25.0f;
			//float c = (sin(float(j) / (1.0 * 469.4f)) - (cos(float(j) / (1.0 * 234.7f)) + 1.0f) / 4.5f) * 30.0f;
			//float d = sin(float(j) / (2.0 * 58.f)) * 3.0f + sin(float(i) / (2.0 * 122.f)) * 5.0f;
			//float e = sin(float(i) / (3.0 * 2.0f)) * 0.8f * cos(float(j) / (3.0 * 6.2f)) * 0.6f + sin(float(j) / (3.0 * 2.3f)) * 0.8f * cos(float(i) / (3.0 * 6.4f)) * 0.5f;
			//HeightData[i + HeightDataSize * j] = (a + b + c + d + e) * 5.0f;
		}

		if (HeightDataSize > 10 && i % (HeightDataSize / 10) == 0)
			LOG("Progress: " << i / (HeightDataSize / 10) * 10 << "%");
	}

	StartIndexX += TBOSize / 2;
	StartIndexY += TBOSize / 2;

	LOG("Terrain Ready!\n");
}
Пример #2
0
GModelSphere::GModelSphere(const int rows, const int cols, const float rad)
{
	VertexAttribute.clear();
	Index.clear();

	for (int i = 0; i < rows + 1; i++){
		float r = (float)M_PI / (float)rows * i;
		float ry = cos(r);
		float rr = sin(r);

		for (int j = 0; j < cols + 1; j++){
			float tr = (float)M_PI * 2 / (float)cols * j;
			float tx = rr * rad * cos(tr);
			float ty = ry * rad;
			float tz = rr * rad * sin(tr);
			float rx = rr * cos(tr);
			float rz = rr * sin(tr);

			GVertexAttribute vertexAttr;
			vertexAttr.position = vec3(tx, ty, tz);
			vertexAttr.normal = vec3(rx, ry, rz);
//			vertexAttr.color = vec4(1.0, 0.0, 1.0, 1.0);
			vec3 hsv(360.0f / (float)rows * i, 1.0, 1.0);
			vertexAttr.color = vec4(hsv2rgb(hsv), 1.0);

			VertexAttribute.push_back(vertexAttr);
		}

		for (int i = 0; i < rows; i++){
			for (int j = 0; j < cols; j++){
				int r = (cols + 1) * i + j;
				Index.push_back(u16vec3(r, r + 1, r + cols + 2));
				Index.push_back(u16vec3(r, r + cols + 2, r + cols + 1));
			}
		}

	}

	CreateVBO();
	CreateIBO();
	BindVBO();
	BindIBO();


}
Пример #3
0
///------------------------------------------------------
///
///------------------------------------------------------
void GLMesh::CreateBufferFromC23File(const std::string& filePath, const std::string& fourChars)
{
	BinaryFileParser modelParser(filePath);
	std::string nextFourChars = modelParser.ReadNextString(4);

	if (!Utility::TestFourChars((unsigned char*)nextFourChars.data(), fourChars))
	{
		return ;
	}
	unsigned char subType;
	subType = modelParser.ReadNextUnsignedChar();
	unsigned char version = modelParser.ReadNextChar();
	std::string comments = modelParser.ReadNextString();
	version;
	//////////////////////////////////////////////////////////////////////////
	if (subType == 1 || subType == 2)
	{	
	unsigned int vertsNum = modelParser.ReadNextUnsignedInt();
	//qNTBVertex3D_PCT* vertexArray = new NTBVertex3D_PCT[vertsNum];
	NTBVertex3D_PCT* vertexArray = new NTBVertex3D_PCT[vertsNum];
	for (unsigned int i = 0; i < vertsNum; i++)
	{
		NTBVertex3D_PCT newVert;
		newVert = modelParser.ReadNextNTB_Vert3D();
		vertexArray[i] = newVert;
	}
	CreateVBO(vertexArray, vertsNum*sizeof(NTBVertex3D_PCT));
	unsigned int intIndexNum = modelParser.ReadNextUnsignedInt();
	unsigned int* intIndex = new unsigned int[intIndexNum];
	for (unsigned int i = 0; i < intIndexNum;i++)
	{
		intIndex[i] = modelParser.ReadNextUnsignedInt();
	}

	CreateIBO(intIndex, intIndexNum*4);
	return;
	}
	//////////////////////////////////////////////////////////////////////////
	if (subType == 4)
	{
		unsigned int vertsNum = modelParser.ReadNextUnsignedInt();
		//qNTBVertex3D_PCT* vertexArray = new NTBVertex3D_PCT[vertsNum];
		Vertex3D_Skeletal* vertexArray = new Vertex3D_Skeletal[vertsNum];
		vertexArray = new Vertex3D_Skeletal[vertsNum];
		for (unsigned int i = 0; i < vertsNum; i++)
		{
			Vertex3D_Skeletal newVert;
			newVert = modelParser.ReadNextSkeletonVert();
			vertexArray[i] = newVert;
		}
		CreateVBO(vertexArray, vertsNum*sizeof(Vertex3D_Skeletal));
		unsigned int intIndexNum = modelParser.ReadNextUnsignedInt();
		unsigned int* intIndex = new unsigned int[intIndexNum];
		for (unsigned int i = 0; i < intIndexNum; i++)
		{
			intIndex[i] = modelParser.ReadNextUnsignedInt();
		}

		CreateIBO(intIndex, intIndexNum * 4);
		return;
	}
	//////////////////////////////////////////////////////////////////////////
	//newVert.
}
Пример #4
0
GModelCube::GModelCube(const float side){
	const float hs = side*0.5f;
	VertexAttribute.resize(4 * 6);
	int i = 0;
	VertexAttribute[i++].position = vec3(-hs, -hs, hs);
	VertexAttribute[i++].position = vec3(hs, -hs, hs);
	VertexAttribute[i++].position = vec3(hs, hs, hs);
	VertexAttribute[i++].position = vec3(-hs, hs, hs);

	VertexAttribute[i++].position = vec3(-hs, -hs, -hs);
	VertexAttribute[i++].position = vec3(-hs, hs, -hs);
	VertexAttribute[i++].position = vec3(hs, hs, -hs);
	VertexAttribute[i++].position = vec3(hs, -hs, -hs);

	VertexAttribute[i++].position = vec3(-hs, hs, -hs);
	VertexAttribute[i++].position = vec3(-hs, hs, hs);
	VertexAttribute[i++].position = vec3(hs, hs, hs);
	VertexAttribute[i++].position = vec3(hs, hs, -hs);

	VertexAttribute[i++].position = vec3(-hs, -hs, -hs);
	VertexAttribute[i++].position = vec3(hs, -hs, -hs);
	VertexAttribute[i++].position = vec3(hs, -hs, hs);
	VertexAttribute[i++].position = vec3(-hs, -hs, hs);

	VertexAttribute[i++].position = vec3(hs, -hs, -hs);
	VertexAttribute[i++].position = vec3(hs, hs, -hs);
	VertexAttribute[i++].position = vec3(hs, hs, hs);
	VertexAttribute[i++].position = vec3(hs, -hs, hs);

	VertexAttribute[i++].position = vec3(-hs, -hs, -hs);
	VertexAttribute[i++].position = vec3(-hs, -hs, hs);
	VertexAttribute[i++].position = vec3(-hs, hs, hs);
	VertexAttribute[i++].position = vec3(-hs, hs, -hs);

	i = 0;
	VertexAttribute[i++].normal = vec3(-1.0, -1.0, 1.0);
	VertexAttribute[i++].normal = vec3(1.0, -1.0, 1.0);
	VertexAttribute[i++].normal = vec3(1.0, 1.0, 1.0);
	VertexAttribute[i++].normal = vec3(-1.0, 1.0, 1.0);

	VertexAttribute[i++].normal = vec3(-1.0, -1.0, -1.0);
	VertexAttribute[i++].normal = vec3(-1.0, 1.0, -1.0);
	VertexAttribute[i++].normal = vec3(1.0, 1.0, -1.0);
	VertexAttribute[i++].normal = vec3(1.0, -1.0, -1.0);

	VertexAttribute[i++].normal = vec3(-1.0, 1.0, -1.0);
	VertexAttribute[i++].normal = vec3(-1.0, 1.0, 1.0);
	VertexAttribute[i++].normal = vec3(1.0, 1.0, 1.0);
	VertexAttribute[i++].normal = vec3(1.0, 1.0, -1.0);

	VertexAttribute[i++].normal = vec3(-1.0, -1.0, -1.0);
	VertexAttribute[i++].normal = vec3(1.0, -1.0, -1.0);
	VertexAttribute[i++].normal = vec3(1.0, -1.0, 1.0);
	VertexAttribute[i++].normal = vec3(-1.0, -1.0, 1.0);

	VertexAttribute[i++].normal = vec3(1.0, -1.0, -1.0);
	VertexAttribute[i++].normal = vec3(1.0, 1.0, -1.0);
	VertexAttribute[i++].normal = vec3(1.0, 1.0, 1.0);
	VertexAttribute[i++].normal = vec3(1.0, -1.0, 1.0);

	VertexAttribute[i++].normal = vec3(-1.0, -1.0, -1.0);
	VertexAttribute[i++].normal = vec3(-1.0, -1.0, 1.0);
	VertexAttribute[i++].normal = vec3(-1.0, 1.0, 1.0);
	VertexAttribute[i++].normal = vec3(-1.0, 1.0, -1.0);


	for (int i = 0; i < VertexAttribute.size(); i++){
		vec3 hsv(360.0f / (float)i, 1.0, 1.0);
		VertexAttribute[i].color = vec4(hsv2rgb(hsv), 1.0);
	}


	Index.resize(2 * 6);
	i = 0;
	Index[i++] = u16vec3(0, 1, 2);
	Index[i++] = u16vec3(0, 2, 3);

	Index[i++] = u16vec3(4, 5, 6);
	Index[i++] = u16vec3(4, 6, 7);

	Index[i++] = u16vec3(8, 9, 10);
	Index[i++] = u16vec3(8, 10, 11);

	Index[i++] = u16vec3(12, 13, 14);
	Index[i++] = u16vec3(12, 14, 15);

	Index[i++] = u16vec3(16, 17, 18);
	Index[i++] = u16vec3(16, 18, 19);

	Index[i++] = u16vec3(20, 21, 22);
	Index[i++] = u16vec3(20, 22, 23);

	CreateVBO();
	CreateIBO();
	BindVBO();
	BindIBO();

}