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


C++ Mat4x4::CreateRotationY方法代码示例

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


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

示例1: VertexBuffer

GrassPack::GrassPack(	const Vec & center, const AREAL r32HalfWidth, const AREAL r32HalfHeight,
						const AINT32 & num)
{
	const AREAL size_x = 0.5f;
	const AREAL size_y = 0.7f;

	m_worldTransform = Mat4x4::Identity().CreateTranslation(center);
	m_pVertices = new VertexBuffer();
	m_pTexCoords = new VertexBuffer();
	m_pNormals = new VertexBuffer();

	m_pMaterial = new Material();
	m_pShaders = new ShaderBunch();

	//Initialize vertex buffers
	BufferParams params;
	params.FillVertexBufferParams(sizeof(float3), 18 * num, true, false, false, false);

	SubresourceData data;

#pragma region Vertex buffers
	float3* pos = new float3[18 * num];
	float2* texCoords = new float2[18 * num];
	float3* normals = new float3[18 * num];
	
	//calculate grass quad offsets
	Mat4x4 rotCW = Mat4x4::Identity();
	Mat4x4 rotCCW = Mat4x4::Identity();
	rotCW = rotCW.CreateRotationY(Pi / 4.0);
	rotCCW = rotCCW.CreateRotationY(-Pi / 4.0);

	Vec leftTopVec		= Vector(-size_x, size_y, 0.0f, 0.0f);
	Vec rightTopVec		= Vector(size_x, size_y, 0.0f, 0.0f);
	Vec leftBottomVec	= Vector(-size_x, -size_y, 0.0f, 0.0f);
	Vec rightBottomVec	= Vector(size_x, -size_y, 0.0f, 0.0f);
	float3 leftTop1		= float3(leftTopVec);
	float3 rightTop1	= float3(rightTopVec);
	float3 leftBottom1	= float3(leftBottomVec);
	float3 rightBottom1	= float3(rightBottomVec);
	float3 leftTop2		= float3(leftTopVec * rotCW);
	float3 rightTop2	= float3(rightTopVec * rotCW);
	float3 leftBottom2	= float3(leftBottomVec * rotCW);
	float3 rightBottom2 = float3(rightBottomVec * rotCW);
	float3 leftTop3		= float3(leftTopVec * rotCCW);
	float3 rightTop3	= float3(rightTopVec * rotCCW);
	float3 leftBottom3	= float3(leftBottomVec * rotCCW);
	float3 rightBottom3 = float3(rightBottomVec * rotCCW);

	float3 normal = leftTop1 - leftBottom1;

	AINT32 numWidth = num / (AREAL)(r32HalfHeight + r32HalfHeight);
	AREAL stepWidth  =  (r32HalfWidth * 2) / (AREAL)numWidth;

	AINT32 numHeight = num / numWidth;
	AREAL stepHeight = (r32HalfHeight * 2) / (AREAL)numHeight;

	for (AINT32 i = 0; i < num; i++)
	{
		///////////////////////////////////////////////////
		//Calculate block center position
		//AINT32 x = Random(-r32HalfWidth, r32HalfWidth);
		//AINT32 y = Random(-r32HalfHeight, r32HalfHeight);
		AREAL x = (i % numWidth) * stepWidth;
		AREAL z = (i / numWidth) * stepHeight;

		float3 blockCenter = float3(getx(center) + x, gety(center), getz(center) + z);

		///////////////////////////////////////////////////
		//Calculate invidual vertex data for each block

		//first block
		pos[i*18]		= blockCenter + leftTop1;
		pos[i*18+1]		= blockCenter + rightTop1;
		pos[i*18+2]		= blockCenter + leftBottom1;
		pos[i*18+3]		= blockCenter + leftBottom1;
		pos[i*18+4]		= blockCenter + rightTop1;
		pos[i*18+5]		= blockCenter + rightBottom1;

		texCoords[i*18]	  = float2(0.0f, 0.0f);
		texCoords[i*18+1] = float2(1.0f, 0.0f);
		texCoords[i*18+2] = float2(0.0f, 1.0f);
		texCoords[i*18+3] = float2(0.0f, 1.0f);
		texCoords[i*18+4] = float2(1.0f, 0.0f);
		texCoords[i*18+5] = float2(1.0f, 1.0f);

		normals[i*18]	= normal;
		normals[i*18+1] = normal;
		normals[i*18+2] = normal;
		normals[i*18+3] = normal;
		normals[i*18+4] = normal;
		normals[i*18+5] = normal;

		//second block
		pos[i*18+6]		= blockCenter + leftTop2;
		pos[i*18+7]		= blockCenter + rightTop2;
		pos[i*18+8]		= blockCenter + leftBottom2;
		pos[i*18+9]		= blockCenter + leftBottom2;
		pos[i*18+10]	= blockCenter + rightTop2;
		pos[i*18+11]	= blockCenter + rightBottom2;

//.........这里部分代码省略.........
开发者ID:jjiezheng,项目名称:Anubis-Engine,代码行数:101,代码来源:GrassPack.cpp


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