Jump to content
  • Advertisement
Sign in to follow this  
yewbie

Texture Rotation in DX9

This topic is 2605 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am supplying the U and V coordinates for my texture like below, what I would like to do is have the texture rotate from left to right but stay on my quad.
I haven't really been able to find much information about this, A lot of people suggest using a translation matrix, but I am defining my vertices directly and nothing goes through translation.

How was this done in YE OLDE times such as the texture "scrolling" done in games like doom, duke3d, etc?




TLVERTEX* vertices; //my vertices

vertices[0].colour = D3DCOLOR_ARGB (Alpha,Light,Light,Light);
vertices[0].x = (float)x;
vertices[0].y = (float)y;
vertices[0].z = 0.0f;
vertices[0].rhw = 1.0f;
vertices[0].u = 0.0f ;//1 - 0
vertices[0].v = 0.0f ;//1 - 0

vertices[1].colour = D3DCOLOR_ARGB (Alpha,Light,Light,Light);
vertices[1].x = (float)x + 64;
vertices[1].y = (float)y;
vertices[1].z = 0.0f;
vertices[1].rhw = 1.0f;
vertices[1].u = 1.0f ;//0 - 1
vertices[1].v = 0.0f ;//0 - 0

vertices[2].colour = D3DCOLOR_ARGB (Alpha,Light,Light,Light);
vertices[2].x = (float)x + 64;
vertices[2].y = (float)y + 64;
vertices[2].z = 0.0f;
vertices[2].rhw = 1.0f;
vertices[2].u = 1.0f ;//0 - 1
vertices[2].v = 1.0f ;//0 - 0

vertices[3].colour = D3DCOLOR_ARGB (Alpha,Light,Light,Light);
vertices[3].x = (float)x;
vertices[3].y = (float)y + 64;
vertices[3].z = 0.0f;
vertices[3].rhw = 1.0f;
vertices[3].u = 0.0f ;//0 - 1
vertices[3].v = 1.0f ;//0 - 0

Share this post


Link to post
Share on other sites
Advertisement
The translation (or any other transformation matrix) is meant to be used on the (2D) texcoord. For a simple left to right scroll, just add an offset between [0..1] for u and set the texture addressing mode to wrap. E.g. (pseudo-code):

float elapsedTime = ...; // total elapsed time for current frame
float offset = frac(elapsedTime); // scale the argument to adjust speed, frac then "mods" it to [0..1]
//...
vertices[0].u = 0.0f + offset;
//...
vertices[1].u = 1.0f + offset;
// etc.


With shaders, of course, no need to recreate the vertex buffer: You could do this in a vertex shader providing the offset as a uniform.

Share this post


Link to post
Share on other sites
Oh, thanks I tried this but didn't even think about the texture wrapping mode!
I will give it a shot and report back, thanks!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!