Texture animation (panning)

Started by
3 comments, last by Etnu 23 years, 5 months ago
Ok Im trying to make all the tiles in my game that have a moving water texture on them animate by adjusting the texture coords accordingly. I basically just have been guessing and playing around with the numbers, and I just can''t seem to get it to look right (its gets distorted as the coords are moved. Here is the code as it currently stands:
    
void CMap::Draw(LPDIRECT3DDEVICE7 pD3DDevice,float fTimeKey)
{

	for(int i3 = 0; i3 < TEXTURES; i3++)
	{
		pD3DDevice->SetTexture(0,m_ppTex[i3]);
		for(int i = 0; i < m_XCount; i++)
		{
			for(int i2 = 0; i2 < m_ZCount; i2++)
			{
				int t = m_MapTiles<i>[i2]->Tex;
				if( t == i3)
				{

					D3DXMATRIX mat = m_MapTiles[i][i2]->matPos;
					pD3DDevice->SetTransform( D3DTRANSFORMSTATE_WORLD,(D3DMATRIX *)mat);
					if(i3 == WATER)
					{
						for(int v = 0; v < 4;  v++)
						{
							m_MapTiles[i][i2]->Verts[v].tv += fTimeKey;
							if(m_MapTiles[i][i2]->Verts[v].tv > 1.0f)
								m_MapTiles[i][i2]->Verts[v].tv = 0.0;
						
						}		
					}
					pD3DDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP,D3DFVF_VERTEX,m_MapTiles[i][i2]->Verts,4,0);
				}
			}
		}
	}
}
    
Is this right( not the other stuff, just the panning part, I know I should optimize the tile drawing as well, but thats beside the point). -Etnu.

---------------------------Hello, and Welcome to some arbitrary temporal location in the space-time continuum.

Advertisement
Looking at this, and thinking about it, I know why it doesn''t work.

But I still can''t for the life of me think of how to make it do what I want (which is to make the texture animate vertically in a scrolling manner)

BTW- im using a simple texture with a blue dot in the middle currently to figure this out. Im planning on doing something more detailed later, but right now Im using the dot until im sure ive got the panning down pat.

Any help is appreciated.

Also, anyone know of some nice, free, 3ds models I could use for a FinalFantasyTactics-esque game?

Thanks
-Etnu

---------------------------Hello, and Welcome to some arbitrary temporal location in the space-time continuum.

I don''t know Direct3D, but the way I''ve solved this in GL is to create your water texture holding two identical textures

I----------I
I I
I I
I----------I
I I
I I
I----------I

(Again - this is one texture in memory)
Draw the same water texture in the top half as in the bottom half
In your game loop , shift a variable from 0 to 0.5 and back to 0 again when it reaches 0.5

and the clamp the texture onto the polygon using this coordinate as the "top" v-coord and size 0.5.
So you will have a block that starts in the top block of the texture that moves down each frame by a specified amount (that will change the speed) until it is aligned with the bottom block.
Then because the bottom block is the same as the top , you will have a seamless animation.

( I know its a crappy description, sorry ) If you still don''t understand, tell me and I''ll try again.
Chris


You could do that in GL, but I''d just translate the texture matrix
Paul Grovespauls opengl page
Ah duh!

Should have thought of that one myself =)

thanks

-Etnu

---------------------------Hello, and Welcome to some arbitrary temporal location in the space-time continuum.

This topic is closed to new replies.

Advertisement