Link to home
Start Free TrialLog in
Avatar of orbyone
orbyone

asked on

Perspective transformation using Managed DirectX?

Hi there,

I'm fairly irrelevant to game graphics, but I do have a question that perfectly fits here. I want a function that given an Image and a trapezoid defined by a four points array (or similar), will transform the original image to fit the destination quadrilateral. Actually, gdiplus has something close to what I want, DrawImage, but the destination there is a parallelogram defined by three points (the fourth is computed from the other three). Btw, I'm a VB.NET developer (...), but C# code should be fine too.

Any help?
Thanks in advance
Themos
Avatar of davebytes
davebytes
Flag of United States of America image

DirectX would make you jump through a LOT of hoops to get the result.  You're trying to do a standard quad-based image warp I assume?  There are samples (and likely even examples here on EE) out on the net that I've seen before.

If you REALLY want to go through DirectX, the ROUGH steps you'd need to do are:

- set up a direct3D context (there are some good sample with the DX SDK that start you off with basic rendering)
- load the Image into a D3D Texture object (the D3DX helper functions may help here)
- set up the viewport/camera transformation (in this case, it'll be a display-space camera)
- start rendering
- set the texture as active, and other rendering state
- render a triangle strip or fan with the four vertices in question
- finish rendering
- read pixels out of the backbuffer.

Fun, eh? ;)  As I said, lots of samples with DX SDK that should even start you off with a textured quad and all the proper setup, you just load your image, and need to read from the backbuffer the result.

-d
Avatar of orbyone
orbyone

ASKER

hmm...

thanks. I was a bit afraid it was going to be that complex. could someone help me find the right sample in the net for "standard quad-based image warp"? points will be rewarded for that.

themos
open source lib:
http://xmorph.sourceforge.net/

image displacement fns:
http://www.codeproject.com/cs/media/DisplacementFilters.asp

this guy's master thesis was on quad image warping, has sample code later on page:
http://www-2.cs.cmu.edu/~ph/

this is different type of approach & effect, but might have useful tidbits:
http://astronomy.swin.edu.au/~pbourke/projection/imagewarp/

-d
Avatar of orbyone

ASKER

hi d,

I really appreciate your effort, it's still though not 100% what I'm looking for. I'm really looking for VB/C# source code, C/C++ is just chinese for me... If you do find a sample in VB/VB.NET or C#, it would be greatly appreciated

thanks
themos
the codeproject.com link WAS C#...

and from http://portal.vbcodesource.com/portal/modules/news/ :
"Finally, Visual Basic 2005 BETA1 is available for download for Non-MSDN subscribers!! I have been playing around with it for alittle while today and I really think I will like it. The .Net Framework 2.0 looks to have even more powerful features available. I was looking through the GDI+ classes and looks like there are some pretty nice change/additions. Looks like warping will be easy to do."

Sounds like from the C# example, and the above note, GDI+ stuff has the capabilities you want.  The codeproject C# sample should get you started for sure.

-d

Avatar of orbyone

ASKER

hi,

the C# project was indeed very interesting, but had no sample related to perspective transformation. The new .NET framework sounds promising, but after browsing the docs I could not find the appropriate function (e.g. new overloaded DrawImage function) that performs warping. If you can find this for me, I'll be more than happy to give you the points.

Thanks
Themos
ASKER CERTIFIED SOLUTION
Avatar of davebytes
davebytes
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial