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


C++ Vector4::ToVector3方法代码示例

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


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

示例1:

void	MD5Node::DebugDrawJointTransforms(float size, bool worldSpace) {
	//Temporary VAO and VBO
	unsigned int skeletonArray;
	unsigned int skeletonBuffer;
	unsigned int skeletonColourBuffer;

	glGenVertexArrays(1, &skeletonArray);
	glGenBuffers(1, &skeletonBuffer);
	glGenBuffers(1, &skeletonColourBuffer);
	//Temporary chunk of memory to keep our joint positions in

	int numVerts = currentSkeleton.numJoints * 6;

	Vector3*	 skeletonVertices = new Vector3[numVerts];
	Vector4*	 skeletonColours  = new Vector4[numVerts];


	for (int i = 0; i < currentSkeleton.numJoints; ++i) {
		Matrix4 transform = (worldSpace ? currentSkeleton.joints[i].transform : currentSkeleton.joints[i].localTransform);

		Vector3 start = transform.GetPositionVector();
		transform.SetPositionVector(Vector3(0, 0, 0));

		Vector4 endX = transform * Vector4(1, 0, 0, 1);
		Vector4 endY = transform * Vector4(0, 1, 0, 1);
		Vector4 endZ = transform * Vector4(0, 0, 1, 1);

		skeletonVertices[(i * 6) + 0] = currentSkeleton.joints[i].transform.GetPositionVector();
		skeletonVertices[(i * 6) + 1] = currentSkeleton.joints[i].transform.GetPositionVector() + (endX.ToVector3() * size);

		skeletonVertices[(i * 6) + 2] = currentSkeleton.joints[i].transform.GetPositionVector();
		skeletonVertices[(i * 6) + 3] = currentSkeleton.joints[i].transform.GetPositionVector() + (endY.ToVector3() * size);
					
		skeletonVertices[(i * 6) + 4] = currentSkeleton.joints[i].transform.GetPositionVector();
		skeletonVertices[(i * 6) + 5] = currentSkeleton.joints[i].transform.GetPositionVector() + (endZ.ToVector3() * size);


		skeletonColours[(i * 6) + 0] = Vector4(1, 0, 0, 1);
		skeletonColours[(i * 6) + 1] = Vector4(1, 0, 0, 1);

		skeletonColours[(i * 6) + 2] = Vector4(0, 1, 0, 1);
		skeletonColours[(i * 6) + 3] = Vector4(0, 1, 0, 1);

		skeletonColours[(i * 6) + 4] = Vector4(0, 0, 1, 1);
		skeletonColours[(i * 6) + 5] = Vector4(0, 0, 1, 1);
	}

	//You should know what this all does by now, except we combine it with the draw operations in a single function
	glBindVertexArray(skeletonArray);
	glBindBuffer(GL_ARRAY_BUFFER, skeletonBuffer);
	glBufferData(GL_ARRAY_BUFFER, currentSkeleton.numJoints*sizeof(Vector3) * 6, skeletonVertices, GL_STREAM_DRAW);
	glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
	glEnableVertexAttribArray(0);

	glBindBuffer(GL_ARRAY_BUFFER, skeletonColourBuffer);
	glBufferData(GL_ARRAY_BUFFER, currentSkeleton.numJoints*sizeof(Vector4) * 6, skeletonColours, GL_STREAM_DRAW);
	glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 0, 0);
	glEnableVertexAttribArray(1);

	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D, 0);

	glLineWidth(2.0f);
	glDrawArrays(GL_LINES, 0, currentSkeleton.numJoints * 6);	// draw Bones
	glLineWidth(1.0f);

	glBindVertexArray(0);

	//Delete the VBO and VAO, and the heap memory we allocated earlier
	glDeleteVertexArrays(1, &skeletonArray);
	glDeleteBuffers(1, &skeletonBuffer);
	glDeleteBuffers(1, &skeletonColourBuffer);

	delete[]skeletonVertices;
	delete[]skeletonColours;
}
开发者ID:littlehachiko,项目名称:CSC8502-Advanced-Graphics-for-Games,代码行数:76,代码来源:MD5Node.cpp


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