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


C++ Transform::GetMVP方法代码示例

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


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

示例1: Update

void Shader::Update(const Transform& transform, const Camera& camera)
{
	glm::mat4 MVP = transform.GetMVP(camera);
	glm::mat4 Normal = transform.GetModel();

	glUniformMatrix4fv(m_uniforms[0], 1, GL_FALSE, &MVP[0][0]);
	glUniformMatrix4fv(m_uniforms[1], 1, GL_FALSE, &Normal[0][0]);
	glUniform3f(m_uniforms[2], 0.0f, 0.0f, 1.0f); //light Direction
}
开发者ID:zenopax,项目名称:Platformer,代码行数:9,代码来源:shader.cpp

示例2: Draw

	void Sprite::Draw(int frame, Transform & transform, int anchor, vec4 color)
	{
		// calculate st.uv texture offsets
		assert(frame >= 0 && frame < frameCount);

		int cols = size.z;
		int rows = size.w;

		vec4 offset;
    
		//  0   1   2   3   4
		//  5   6   7   8   9
		// 10  11  12  13  14
		// 15  16  17  18  19
		// 20  21  22  23  24
	
		int frameCol = frame % cols;
		int frameRow = frame / cols;	

		// 0 -  row 0, col 0
		// 12 - row 2, col 2
		// 24 - row 4, col 4

		float tX = 1.f / cols;
		float tY = 1.f / rows;

		offset.x = tX * frameCol;
		offset.y = tY * frameRow;

		MatrixStack * mv = transform.GetModelViewStack();
		mv->PushMatrix();

		vec2 renderPos = GetAnchorCoords(anchor, vec2(0, 0), vec2(size.x, size.y));
		renderPos += (size.xy() / 2);
		mv->Translate(renderPos.x, renderPos.y, 0);
		g_Sprite.SetupShader(transform.GetMVP(), offset, texture, color);
		buffer.render(GL_TRIANGLE_STRIP);

		mv->PopMatrix();
	}
开发者ID:jcramb,项目名称:triage,代码行数:40,代码来源:sprite.cpp

示例3: Render

    void App::Render(const delta_t dt, const delta_t elapsed)
    {	
		// clear buffer and save matrix state
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

		// position camera
		mat4 camera;
		cameraFrame.GetCameraMatrix(camera);
		mv.PushMatrix(camera);

			// create point light
			vec4 vLightPos(sin(elapsed) * 10, 5, -8 + (cos(elapsed) * 15), 1);
			vec4 vLightEyePos;
			vec4 vAmbientColor(0.1f, 0.1f, 0.1f, 1);
			vec4 vDiffuseColor(1, 1, 1, 1);
			vec4 vSpecularColor(1, 1, 1, 1);

			// use smoothstep to animate the cube movement
			static float xPos;
			xPos = ((float)sin(elapsed * 3.1) + 1.0f) / 2.0f;
			xPos = (xPos) * (xPos) * (3.0f - 2.0f * (xPos));
			xPos = (-1.5f * xPos) + (1.5f * (1.0f - xPos));

			// copy uniform information to shader 
			GL_DEBUG(glUseProgram(phongShader));
			vLightEyePos = mv.Transform(vLightPos);
			GL_DEBUG(glUniformMatrix3fv(locNM , 1, GL_FALSE, transform.GetNormalMatrix() ));
			GL_DEBUG(glUniformMatrix4fv(locMV , 1, GL_FALSE, transform.GetModelView() ));
			GL_DEBUG(glUniformMatrix4fv(locMVP, 1, GL_FALSE, transform.GetMVP() ));
			GL_DEBUG(glUniform4fv(locAmbient, 1, &vAmbientColor[0]));
			GL_DEBUG(glUniform4fv(locDiffuse, 1, &vDiffuseColor[0]));
			GL_DEBUG(glUniform4fv(locSpecular, 1, &vSpecularColor[0]));
			GL_DEBUG(glUniform3fv(locLightPos, 1, &vLightEyePos[0]));
			GL_DEBUG(glUniform1i(locTexture, 0));

			// render the floor
			glActiveTexture(GL_TEXTURE0);
			glBindTexture(GL_TEXTURE_2D, baseTexture);
			base.Draw();

			// transform modelview to rotate cube
			mv.PushMatrix();
				mat4 cubePos = translate(mat4(), vec3(xPos, -0.5f, -15.f));
				cubePos = rotate(cubePos, 100.0f * (float)sin(elapsed), vec3(1.0f, 0.0f, 0.0f));
				cubePos = rotate(cubePos, 20.0f * (float)elapsed, vec3(0.0f, 1.0f, 0.0f));
				mv.MultMatrix(cubePos);

				// copy uniform information to shader for cube
				vLightEyePos = mv.Transform(vLightPos);
				GL_DEBUG(glUniform3fv(locLightPos, 1, &vLightEyePos[0]));
				GL_DEBUG(glUniformMatrix3fv(locNM , 1, GL_FALSE, transform.GetNormalMatrix() ));
				GL_DEBUG(glUniformMatrix4fv(locMV , 1, GL_FALSE, transform.GetModelView() ));
				GL_DEBUG(glUniformMatrix4fv(locMVP, 1, GL_FALSE, transform.GetMVP() ));
				glBindTexture(GL_TEXTURE_2D, cubeTexture);

				// render geometry
				cube.Draw();
			mv.PopMatrix();

			// draw cube at light position
			mv.PushMatrix();
				cubePos = translate(mat4(), vLightPos.xyz());
				mv.MultMatrix(cubePos);
				vLightEyePos = mv.Transform(vLightPos);
				GL_DEBUG(glUniform3fv(locLightPos, 1, &vLightEyePos[0]));
				GL_DEBUG(glUniformMatrix3fv(locNM , 1, GL_FALSE, transform.GetNormalMatrix() ));
				GL_DEBUG(glUniformMatrix4fv(locMV , 1, GL_FALSE, transform.GetModelView() ));
				GL_DEBUG(glUniformMatrix4fv(locMVP, 1, GL_FALSE, transform.GetMVP() ));
				glBindTexture(GL_TEXTURE_2D, cubeTexture);
				cube.Draw();
			mv.PopMatrix();

			// draw a stationary cube
			mv.PushMatrix();
				cubePos = translate(mat4(), vec3(-5, 0, 0));
				cubePos = rotate(cubePos, 45.0f, vec3(1, 0, 0));
				mv.MultMatrix(cubePos);
				vLightEyePos = mv.Transform(vLightPos);
				GL_DEBUG(glUniform3fv(locLightPos, 1, &vLightEyePos[0]));
				GL_DEBUG(glUniformMatrix3fv(locNM , 1, GL_FALSE, transform.GetNormalMatrix() ));
				GL_DEBUG(glUniformMatrix4fv(locMV , 1, GL_FALSE, transform.GetModelView() ));
				GL_DEBUG(glUniformMatrix4fv(locMVP, 1, GL_FALSE, transform.GetMVP() ));
				glBindTexture(GL_TEXTURE_2D, cubeTexture);
				cube.Draw();
			mv.PopMatrix();

		mv.PopMatrix();

		// update blur frame textures
		blurTimer += (float)dt;
		if (blurTimer > BLUR_FRAME_DELAY)
		{
			// save frame buffer to pbo
			glBindBuffer(GL_PIXEL_PACK_BUFFER, pbo);
			glReadPixels(0, 0, g_App.GetWidth(), g_App.GetHeight(), GL_RGB, GL_UNSIGNED_BYTE, NULL);
			glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);

			// save pixel buffer to texture and increment frame index
			glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo);
			glActiveTexture(GL_TEXTURE0 + GetBlurFrame0());
//.........这里部分代码省略.........
开发者ID:evgenymartynov,项目名称:firefly,代码行数:101,代码来源:demo.cpp


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