Can't get sprite to rotate

Started by
9 comments, last by cheese4432 10 years, 9 months ago

So I want the sprite to rotate around its origin, at the moment it's rotating around the bottom left hand corner. right now I am modifying vpMatrix_ and the world matrix to move the sprite around. vpMatrix_ is created in my loadContent function which sets up the shaders and buffers for directx, and vpMatrix_ is created by the following:


XMMATRIX view = XMMatrixIdentity();
XMMATRIX projection = XMMatrixOrthographicOffCenterLH(0.0f, 800.0f, 0.0f, 600.0f, 0.1f, 100.0f);

vpMatrix_ = XMMatrixMultiply(view, projection);

Now as far as I know I want to modifying a matrix that the sprite is part of, but I don't have a matrix for the sprite. Should I make one? Right now the vertices of the sprite are stored in an array. And if I should make one what do I put in it, and how do I initialize it?

The array of vertices for the sprite goes as follows:


struct VertexPos
{
    XMFLOAT3 pos;
    XMFLOAT2 tex0;
};

VertexPos vertices[6]; //a rectangle

	ID3D11Resource* colorTex;
	colorMap_->GetResource( &colorTex);

	//ID3D11Texture2D
	 D3D11_TEXTURE2D_DESC colorTexDesc;
    ( ( ID3D11Texture2D* )colorTex )->GetDesc( &colorTexDesc );
	 float halfWidth = ( float )colorTexDesc.Width / 2.0f;
    float halfHeight = ( float )colorTexDesc.Height / 2.0f;
	colorTex->Release();

	/*VertexPos*/
	 vertices[0].pos = XMFLOAT3( halfWidth, halfHeight, 1.0f); vertices[0].tex0 =  XMFLOAT2(1.0f, 0.0f);		
	 vertices[1].pos =	XMFLOAT3(halfWidth, -halfHeight, 1.0f); vertices[1].tex0 = XMFLOAT2( 1.0f, 1.0f);
	 vertices[2].pos =	XMFLOAT3(-halfWidth, -halfHeight, 1.0f); vertices[2].tex0 = XMFLOAT2(0.0f, 1.0f);
	 vertices[3].pos =	XMFLOAT3(-halfWidth, -halfHeight, 1.0f); vertices[3].tex0 = XMFLOAT2(0.0f, 1.0f);
	 vertices[4].pos =	XMFLOAT3(-halfWidth, halfHeight, 1.0f); vertices[4].tex0 = XMFLOAT2(0.0f, 0.0f);
	 vertices[5].pos =	XMFLOAT3(halfWidth, halfHeight, 1.0f); vertices[5].tex0 = XMFLOAT2(1.0f, 0.0f);

This topic is closed to new replies.

Advertisement