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


C++ LPD3DXSPRITE::DrawTransform方法代码示例

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


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

示例1: DrawSprite

void Renderer::DrawSprite(Vector2 position, float width, float height, TexCoord textureCoordinates, float angle,Vector2 rotationPoint)
{
#if IS_XBOX

	// Convert Param Information into proper structures

	XGVECTOR2 scale;
	scale.x = (IMAGE_TO_SCREEN_X / SCREEN_WIDTH) / textureCoordinates.width  * width;
	scale.y = (IMAGE_TO_SCREEN_Y / SCREEN_HEIGHT) / textureCoordinates.height * height;

	RECT tex;
	tex.top = (LONG)((textureCoordinates.y)*IMAGE_HEIGHT);
	tex.bottom = (LONG)((textureCoordinates.y + textureCoordinates.height)*IMAGE_HEIGHT);
	tex.left = (LONG)((textureCoordinates.x)*IMAGE_WIDTH);
	tex.right = (LONG)((textureCoordinates.x + textureCoordinates.width)*IMAGE_WIDTH);
	
	XGVECTOR2 rot;
	rot.x = rotationPoint.x - position.x;
	rot.y = rotationPoint.y - position.y;

	XGVECTOR2 pos;
	pos.x = position.x;
	pos.y = position.y;

	m_sprite->Begin();

	// Transform and Draw the Sprite
#	if FALSE 
	// Apply Transform Matrix
	D3DXMATRIX matWorld;
	D3DXMatrixIdentity(&matWorld);
	D3DXMATRIX matTransform;
	D3DXMatrixScaling(&matTransform, scale.x, scale.y, 1);
	D3DXMatrixMultiply(&matWorld, &matWorld, &matTransform);

	if(angle != 0){
		D3DXMatrixTranslation(&matTransform, - rotationPoint.x, - rotationPoint.y , 0.0f);
		D3DXMatrixMultiply(&matWorld, &matWorld, &matTransform);
		D3DXMatrixRotationZ(&matTransform, angle);
		D3DXMatrixMultiply(&matWorld, &matWorld, &matTransform);
		D3DXMatrixTranslation(&matTransform, rotationPoint.x, rotationPoint.y , 0.0f);
		D3DXMatrixMultiply(&matWorld, &matWorld, &matTransform);
	}

	D3DXMatrixTranslation(&matTransform, position.x, position.y, 0.0f);
	D3DXMatrixMultiply(&matWorld, &matWorld, &matTransform);

	m_sprite->DrawTransform(g_pTextureMap[currentID], &tex, &matWorld,  0xffffffff);
#	else
	// Trust Draw Method
	m_sprite->Draw(g_pTextureMap[currentID], &tex, &scale, &rot, angle, &pos, 0xffffffff);
#	endif

	m_sprite->End();
#else
	// Simple inversion of the texture for DirectX
	textureCoordinates.y = 1 - textureCoordinates.y;

	GLdouble matrix[16];
	glGetDoublev(GL_MODELVIEW_MATRIX, matrix);

	Vector2 topLeft, topRight, bottomLeft, bottomRight;
	topLeft = position;
	topRight = position;
	bottomLeft = position;
	bottomRight = position;

	topRight.x += width;

	bottomLeft.y += height;

	bottomRight.x += width;
	bottomRight.y += height;

	if (angle != 0) {
		topLeft.rotateOnPivot(angle, &rotationPoint);
		topRight.rotateOnPivot(angle, &rotationPoint);
		bottomLeft.rotateOnPivot(angle, &rotationPoint);
		bottomRight.rotateOnPivot(angle, &rotationPoint);
	}

	glGetDoublev(GL_MODELVIEW_MATRIX, matrix);

	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, mTextureID[currentID]);
	glBegin(GL_QUADS);
	glTexCoord2f(textureCoordinates.x, textureCoordinates.y);

	glVertex2f(topLeft.x, topLeft.y);
	glTexCoord2f(textureCoordinates.x, textureCoordinates.y - textureCoordinates.height);

	glVertex2f(bottomLeft.x, bottomLeft.y );

	glTexCoord2f(textureCoordinates.x + textureCoordinates.width, textureCoordinates.y - textureCoordinates.height);
	glVertex2f(bottomRight.x  , bottomRight.y );

	glTexCoord2f(textureCoordinates.x + textureCoordinates.width, textureCoordinates.y);

	glVertex2f(topRight.x, topRight.y);

//.........这里部分代码省略.........
开发者ID:ash9991win,项目名称:Xbox-Game,代码行数:101,代码来源:Renderer.cpp


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