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


C++ PVRTVec3::cross方法代码示例

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


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

示例1: ComputeVertexAndNormals

void ParametricSurface::ComputeVertexAndNormals(PFUNCTION function, float dMinU, float dMaxU, float dMinV, float dMaxV)
{
	int nVertex = nSampleU * nSampleV;
	pVertex = new float[nVertex*3];
	pNormal = new float[nVertex*3];
	pUV = new float[nVertex*2];

	fMinU = dMinU;
	fMaxU = dMaxU;
	fMinV = dMinV;
	fMaxV = dMaxV;

	for (int i=0; i<nSampleU; i++)
	{
		for (int j=0; j<nSampleV; j++)
		{
			float u = fMinU + i * (fMaxU-fMinU) / (float)(nSampleU-1);
			float v = fMinV + j * (fMaxV-fMinV) / (float)(nSampleV-1);
			float x,y,z;
            function(u,v, &x,&y,&z);
			pVertex[(j*nSampleU+i)*3 + 0] = x;
			pVertex[(j*nSampleU+i)*3 + 1] = y;
			pVertex[(j*nSampleU+i)*3 + 2] = z;
		}
	}

	for (int i=0; i<nSampleU; i++)
	{
		for (int j=0; j<nSampleV; j++)
		{
			pUV[ (j*nSampleU+i)*2 + 0 ] = (float)i / (float)(nSampleU-1);
			pUV[ (j*nSampleU+i)*2 + 1 ] = (float)j / (float)(nSampleV-1);
		}
	}

	for (int i=0; i<nSampleU-1; i++)
	{
		for (int j=0; j<nSampleV-1; j++)
		{
			PVRTVec3 ptA = PVRTVec3(pVertex[(j*nSampleU+i)*3+0],pVertex[(j*nSampleU+i)*3+1],pVertex[(j*nSampleU+i)*3+2]);
			PVRTVec3 ptB = PVRTVec3(pVertex[(j*nSampleU+i+1)*3+0],pVertex[(j*nSampleU+i+1)*3+1],pVertex[(j*nSampleU+i+1)*3+2]);
			PVRTVec3 ptC = PVRTVec3(pVertex[((j+1)*nSampleU+i)*3+0],pVertex[((j+1)*nSampleU+i)*3+1],pVertex[((j+1)*nSampleU+i)*3+2]);
			PVRTVec3 AB = PVRTVec3(ptB.x-ptA.x, ptB.y-ptA.y, ptB.z-ptA.z);
			PVRTVec3 AC = PVRTVec3(ptC.x-ptA.x, ptC.y-ptA.y, ptC.z-ptA.z);
			PVRTVec3 normal;

			normal = AB.cross(AC);
			normal.normalize();

			pNormal[(j*nSampleU+i)*3 + 0] = -normal.x;
			pNormal[(j*nSampleU+i)*3 + 1] = -normal.y;
			pNormal[(j*nSampleU+i)*3 + 2] = -normal.z;
		}
	}

	for (int i=0; i<nSampleU-1; i++)
	{
		pNormal[((nSampleV-1)*nSampleU+i)*3+0] = pNormal[(i)*3+0];
		pNormal[((nSampleV-1)*nSampleU+i)*3+1] = pNormal[(i)*3+1];
		pNormal[((nSampleV-1)*nSampleU+i)*3+2] = pNormal[(i)*3+2];
	}

	for (int j=0; j<nSampleV-1; j++)
	{
		pNormal[(j*nSampleU+nSampleU-1)*3+0] = pNormal[(j*nSampleU)*3+0];
		pNormal[(j*nSampleU+nSampleU-1)*3+1] = pNormal[(j*nSampleU)*3+1];
		pNormal[(j*nSampleU+nSampleU-1)*3+2] = pNormal[(j*nSampleU)*3+2];
	}

	pNormal[((nSampleV-1)*nSampleU + (nSampleU-1))*3+0]= pNormal[((nSampleV-2)*nSampleU + (nSampleU-2))*3+0];
	pNormal[((nSampleV-1)*nSampleU + (nSampleU-1))*3+1]= pNormal[((nSampleV-2)*nSampleU + (nSampleU-2))*3+1];
	pNormal[((nSampleV-1)*nSampleU + (nSampleU-1))*3+2]= pNormal[((nSampleV-2)*nSampleU + (nSampleU-2))*3+2];

	// Insert generated data into vertex buffer objects.
    glBindBuffer(GL_ARRAY_BUFFER, iVertexVBO);
	glBufferData(GL_ARRAY_BUFFER, nVertex * 3 * sizeof (float), pVertex, GL_STATIC_DRAW);

	glBindBuffer(GL_ARRAY_BUFFER, iUvVBO);
	glBufferData(GL_ARRAY_BUFFER, nVertex * 2 * sizeof (float), pUV, GL_STATIC_DRAW);

	glBindBuffer(GL_ARRAY_BUFFER, iNormalVBO);
	glBufferData(GL_ARRAY_BUFFER, nVertex * 3 * sizeof (float), pNormal, GL_STATIC_DRAW);

	glBindBuffer(GL_ARRAY_BUFFER, 0); // Unbind the last buffer used.

	delete[] pVertex;
	delete[] pNormal;
	delete[] pUV;
}
开发者ID:,项目名称:,代码行数:89,代码来源:


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