当前位置: 首页>>代码示例>>C++>>正文


C++ VertexData::size方法代码示例

本文整理汇总了C++中VertexData::size方法的典型用法代码示例。如果您正苦于以下问题:C++ VertexData::size方法的具体用法?C++ VertexData::size怎么用?C++ VertexData::size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在VertexData的用法示例。


在下文中一共展示了VertexData::size方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1:

Sphere::Sphere( bool fullSphere, byte numSubDiv, float dim )
{
	setPrimitiveType( PrimitiveType::Triangles );
	
	VertexData position;
	buildGeometry( fullSphere, numSubDiv, position, dim );
	
	// Build Texture Coordinates.
	BoundingBox box;
	
	for( size_t i = 0; i < position.size(); i++ )
	{
		const Vector3& v = position[i];
		box.add(v);
	}

	Vector3 center = box.getCenter();

	std::vector<Vector3> texCoords;

	for( size_t i = 0; i < position.size(); i++ )
	{
		const Vector3& vert = position[i];
		Vector3 d = vert-center;
		d.normalize();

		// Conveert to spherical coordinates.
		//float t = d.z / sqrt(d.x*d.x+d.y*d.y+d.z*d.z);
		//float delta = acos(t);
		//float phi = atan2(d.y, d.x);

		//float u = delta / Math::PI;
		//float v = phi / 2*Math::PI;
		float u = std::asin(d.x) / PI + 0.5f;
		float v = std::asin(d.y) / PI + 0.5f;

		texCoords.push_back( Vector2(u, v) );
	}

	gb->set( VertexAttribute::Position, position );
	gb->set( VertexAttribute::TexCoord0, texCoords );
}
开发者ID:,项目名称:,代码行数:42,代码来源:

示例2: buildGeometry

void Sphere::buildGeometry( bool fullSphere, byte numSubDiv, 
							VertexData& pos, float dim)
{
	GeometryBufferPtr gb = AllocateThis(GeometryBuffer);
	setGeometryBuffer(gb);

	// Rotate the vertices, else the sphere is not properly aligned.
	Matrix4x3 rot = Matrix4x3::createRotation( EulerAngles(-60, 0, 0) );

	for( size_t i = 0; i < ARRAY_SIZE(IcoDomeIndices); i++ )
	{
		const byte* p = IcoDomeIndices[i];
	
		Vector3 v1( IcoVertices[p[0]][0], IcoVertices[p[0]][2], IcoVertices[p[0]][1] );
		Vector3 v2( IcoVertices[p[1]][0], IcoVertices[p[1]][2], IcoVertices[p[1]][1] );
		Vector3 v3( IcoVertices[p[2]][0], IcoVertices[p[2]][2], IcoVertices[p[2]][1] );

		subdivide( rot*v1, rot*v2, rot*v3, numSubDiv, pos );
	}

	// If we don't want a full sphere, we return here.
	if( fullSphere )
	{
		// These indices are the bottom of the sphere.
		for( size_t i = 0; i < ARRAY_SIZE(IcoSphereIndices); i++ )
		{
			const byte* p = IcoSphereIndices[i];
			Vector3 v1( IcoVertices[p[0]][0], IcoVertices[p[0]][2], IcoVertices[p[0]][1] );
			Vector3 v2( IcoVertices[p[1]][0], IcoVertices[p[1]][2], IcoVertices[p[1]][1] );
			Vector3 v3( IcoVertices[p[2]][0], IcoVertices[p[2]][2], IcoVertices[p[2]][1] );

			subdivide( rot*v1, rot*v2, rot*v3, numSubDiv, pos );
		}
	}

	// Scale all the vertices.
	for( size_t i = 0; i < pos.size(); i++ )
	{
		Vector3& vec = pos[i];	
		vec *= dim;
	}
}
开发者ID:,项目名称:,代码行数:42,代码来源:


注:本文中的VertexData::size方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。