#79508 - NEiM0D - Fri Apr 14, 2006 1:48 am
Hello all,
I'm trying to figure out how to fix a problem which occurs when trying to draw a sprite (textured polygon) using the DS's 3D engine .
First I start with setting up the orthogonal projection matrix.
This orthogonal projection matrix sets up the camera and 3D system so that the X/Y coordinates of the 3D space (regardless of Z) are the same as the screen X/Y coordinates, which makes it very easy for 2D sprites to be drawn on the DS.
However, there is a slight problem with the texture mapping used by the 3D engine with DS:
When rotating the polygon, the polygon can be one texel off!
Consider drawing a sprite which is 32x32 in size.
For the polygon's vertex coordinates you give it these 4 points:
And for texture coordinates the same.
For example, see these two pictures:
Polygon which is not rotated (note the 4 differently coloured pixels) :
[Images not permitted - Click here to view it]
Now when you rotate this 90 degrees (see [1]) using the DS's 3D engine, you get:
[Images not permitted - Click here to view it]
(zoom in to see the problem clearly)
In the last image, the result you get which the 3D engine displays, is obviously not correct. It looks like the texture went up by 1 pixel!
I should mention that this texture was drawn with the "texture repeat" flags enabled. If this would not be the case, then the "1-pixel incorrect left side" of the polygon would simply not be drawn.
A possible correction would be to move the texture one pixel down when you know you are going to rotate 90 degrees, which would then display a correct image.
But consider a rotation of any degree, how does one fix it?
This is where I am stuck at the moment, maybe someone can enlighten me?
[1]: The matrix used to perform the rotation on the polygon is:
I'm trying to figure out how to fix a problem which occurs when trying to draw a sprite (textured polygon) using the DS's 3D engine .
First I start with setting up the orthogonal projection matrix.
This orthogonal projection matrix sets up the camera and 3D system so that the X/Y coordinates of the 3D space (regardless of Z) are the same as the screen X/Y coordinates, which makes it very easy for 2D sprites to be drawn on the DS.
However, there is a slight problem with the texture mapping used by the 3D engine with DS:
When rotating the polygon, the polygon can be one texel off!
Consider drawing a sprite which is 32x32 in size.
For the polygon's vertex coordinates you give it these 4 points:
Code: |
(0.0, 0.0) (32.0, 0.0) (0.0, 32.0) (32.0, 32.0) |
And for texture coordinates the same.
For example, see these two pictures:
Polygon which is not rotated (note the 4 differently coloured pixels) :
[Images not permitted - Click here to view it]
Now when you rotate this 90 degrees (see [1]) using the DS's 3D engine, you get:
[Images not permitted - Click here to view it]
(zoom in to see the problem clearly)
In the last image, the result you get which the 3D engine displays, is obviously not correct. It looks like the texture went up by 1 pixel!
I should mention that this texture was drawn with the "texture repeat" flags enabled. If this would not be the case, then the "1-pixel incorrect left side" of the polygon would simply not be drawn.
A possible correction would be to move the texture one pixel down when you know you are going to rotate 90 degrees, which would then display a correct image.
But consider a rotation of any degree, how does one fix it?
This is where I am stuck at the moment, maybe someone can enlighten me?
[1]: The matrix used to perform the rotation on the polygon is:
Code: |
P = [cos(a) sin(a)] [-sin(a) cos(a)] |