Original Post
Hey, I'm having a problem translating texture coordinates, and maybe someone can help me figure out what the problem is. For the record, I'm using C# with managed DX, though I'm not sure how much that matters. The following is my texture transformation code that does *NOT* translate texture coordinates. The code works perfectly. The point of transforming texture coordinates is to allow the user to specify coordinates where the unit length is a single pixel, instead of the unit length being the entire texture. "DX.Matrix" is the standard DirectX matrix struct. "image" is an instance of my Image class, which is simply a wrapper around a D3D Texture object. Image.OriginalSize is the original size of the file from which the texture was loaded. "curTexTransform" is simply my engine's cache of the current texture transform. "dev" is a Direct3D Device object. Again, the above code works fine and properly scales texture coordinates. However, my problem lies in trying to introduce coordinate translation in addition to scaling. Here's the code I'm trying to get working: In terms of the graphical output to the screen, this code behaves identically to the code that only scales coordinates. My goal here is to translate texture coordinates 32 pixels to the right before scaling them (for testing purposes). Note that I tried both "m = translation * scaling" and "m = scaling * translation", as well as commenting out the if statement, such that the two statements in the body of the if are always called. In all cases, the output to the screen is identical to the code that only scales. The texture I'm using to test this was created such that translating the x coordinate by 32 pixels should produce wildly different output. [edit: texture coordinate rotation, while pretty pointless in my case, appears to work fine] I should probably also say that I enable texture coordinate translation like so: "dev.TextureState[0].TextureTransform = TextureTransform.Count2;" [edit: none of the other TextureTransform values work either; Count3 and Count4 have no effect, and Projected screws everything up.] Anyone know why my code isn't properly translating texture coordinates? Thanks! - Fuzz [Edited by - Holy Fuzz on August 1, 2005 10:58:49 AM]
DX.Matrix scaling = (image != null)?(DX.Matrix.Scaling(1f/image.OriginalSize.Width, 1f/image.OriginalSize.Height, 1f)):(DX.Matrix.Identity);
DX.Matrix m = translation;
if(m != curTexTransform)
{
dev.Transform.Texture0 = m;
curTexTransform = m;
}
DX.Matrix scaling = (image != null)?(DX.Matrix.Scaling(1f/image.OriginalSize.Width, 1f/image.OriginalSize.Height, 1f)):(DX.Matrix.Identity);
DX.Matrix translation = DX.Matrix.Translation(32, 0, 0);
DX.Matrix m = translation * scaling;
if(m != curTexTransform)
{
dev.Transform.Texture0 = m;
curTexTransform = m;
}