Discussion:
Using a negative scale value to mirror an image
(too old to reply)
Lostkiwi
2007-02-23 17:49:05 UTC
Permalink
Hi all

I'm new to DirectX and have hit a problem that has me stumped. I am using C#
in VS2005.

I have created a textured quad (ie: a texture overlaid on 4 vertices) and
have it successfully displayed on the screen.

The trouble comes when I try to negatively scale the quad in either the x OR
y axis to produce a reverse image - the image doesn't appear on the screen.
Scaling the quad using positive values works as expected. Interestingly if I
negatively scale the quad in both the x AND y axis the image is displayed
correctly (ie: reversed in both the x and y axes).

A similar effect happens when I try to rotate the quad. Rotating in the Z
axis works fine however if I rotate the quad around either the x or y axes
the image disappears as soon as it is any angle other than 0 radians.

I suspect it is a fairly easy problem to solve but I'm not sure where to
start looking. Any help would be greatly appreciated.

Ben
legalize+ (Richard [Microsoft Direct3D MVP])
2007-02-23 18:09:52 UTC
Permalink
[Please do not mail me a copy of your followup]

Do you have backface culling enabled? Try setting CullMode to None
and see if your geometry reappears.

Negative scaling is generally not the best way to achieve mirroring.
It is better to draw the same geometry with different texture
coordinates, or use the texture coordinate transformation matrices to
mirror the texture while leaving the geometry alone.
--
"The Direct3D Graphics Pipeline" -- DirectX 9 draft available for download
<http://www.xmission.com/~legalize/book/download/index.html>

Legalize Adulthood! <http://blogs.xmission.com/legalize/>
Lostkiwi
2007-02-23 18:40:12 UTC
Permalink
Thank you very much for your response - that indeed was the problem. Next
time I'll come straight here rather than spend 5 hours on a problem.

Thank you also for the suggestions on the more efficient ways of mirroring
the image. I had thought about updating the vertex buffer with different
texture co-ordinates but thought this was quite expensive - is it less
expensive than scaling the quad (given the buffer only contains the four
vertices)?

I believe I will end up using a matix to reverse the texture in the end
however I would be interested to know the answer to my question above.

Thank you once again.

Ben
Post by legalize+ (Richard [Microsoft Direct3D MVP])
[Please do not mail me a copy of your followup]
Do you have backface culling enabled? Try setting CullMode to None
and see if your geometry reappears.
Negative scaling is generally not the best way to achieve mirroring.
It is better to draw the same geometry with different texture
coordinates, or use the texture coordinate transformation matrices to
mirror the texture while leaving the geometry alone.
--
"The Direct3D Graphics Pipeline" -- DirectX 9 draft available for download
<http://www.xmission.com/~legalize/book/download/index.html>
Legalize Adulthood! <http://blogs.xmission.com/legalize/>
legalize+ (Richard [Microsoft Direct3D MVP])
2007-02-23 18:59:15 UTC
Permalink
[Please do not mail me a copy of your followup]
Post by Lostkiwi
Thank you also for the suggestions on the more efficient ways of mirroring
the image. I had thought about updating the vertex buffer with different
texture co-ordinates but thought this was quite expensive - is it less
expensive than scaling the quad (given the buffer only contains the four
vertices)?
You wouldn't typically update the vertex buffer, but use vertex
processing to transform the coordinates. This leaves the vertex data
alone, but changes the texture coordinates as vertices are processed.
In a vertex shader, this amounts to pumping the texture coordinates
through a 3x3 matrix (for 2D coordinates, a 4x4 matrix for 3D
coordinates). In the FFP this is done using SetTransform.
--
"The Direct3D Graphics Pipeline" -- DirectX 9 draft available for download
<http://www.xmission.com/~legalize/book/download/index.html>

Legalize Adulthood! <http://blogs.xmission.com/legalize/>
Loading...