Solved

Perspective transformation using Managed DirectX?

Posted on 2004-08-07
8
2,073 Views
Last Modified: 2013-12-08
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
0
Comment
Question by:orbyone
  • 4
  • 3
8 Comments
 
LVL 17

Expert Comment

by:davebytes
ID: 11747727
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
 
LVL 1

Author Comment

by:orbyone
ID: 11760368
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
 
LVL 17

Expert Comment

by:davebytes
ID: 11768811
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 1

Author Comment

by:orbyone
ID: 11770012
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
 
LVL 17

Expert Comment

by:davebytes
ID: 11779317
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
 
LVL 1

Author Comment

by:orbyone
ID: 11805235
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
 
LVL 17

Accepted Solution

by:
davebytes earned 500 total points
ID: 11824739
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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Recently, in one of the tech-blogs I usually read, I saw a post about the best-selling video games through history. The first place in the list is for the classic, extremely addictive Tetris. Well, a long time ago, in a galaxy far far away, I was…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now