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
LVL 1
orbyoneAsked:
Who is Participating?
 
davebytesConnect With a Mentor Commented:
Yeah, I agree... After my more intense digging, it is only basic rotate/translate/scale.

I haven't found anything specifically C#/VB, unfortunately.  However, if you want to do a little bit of stretching (a lot of this is C, but I'd think you're likely able to handle the basic read-through...), I tried to find some old articles on projective texture mapping.  Some of them were way too complex, but gamedev.net has a lot (http://www.gamedev.net/reference/list.asp?categoryid=40#112) of potential articles.  Much of these are OLD (at least five years, some more, some less), since these are 'by hand' rendering approaches -- outdated in most cases by hardware rendering.

The ones I picked out for you were:

http://www.gamedev.net/reference/articles/article1083.asp (and the follow up article listed at the end)
http://www.gamedev.net/reference/articles/article810.asp
http://www.gamedev.net/reference/articles/article852.asp
http://www.gamedev.net/reference/articles/article335.asp (starts going into x86 ASM, but gave some good intro and pseudo-code)
http://www.gamedev.net/reference/articles/article331.asp

Hope that helps.  If I find a decent primer to Direct X in VB/C#, will let you know.  You might want to go pick up a book if you want to go that route, as there's likely some good ones out there...

-d
0
 
davebytesCommented:
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
0
 
orbyoneAuthor Commented:
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
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
davebytesCommented:
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
0
 
orbyoneAuthor Commented:
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
0
 
davebytesCommented:
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

0
 
orbyoneAuthor Commented:
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
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.