12,954,464 members (46,209 online)
Rate this:
See more:
Hi all,

Background::
I am currently in the process of creating a 3D modelling engine using c#.Net without the use of any 3rd party libraries like DirectX or OpenGl. So far I have built an engine that supports the creation of new objects, lights, movement and physics (which I think is pretty impressive so far considering the restrictions :p). However I have hit a bit of a stumble. I cannot map an Image to a triangle.

Question::
I have 3 screen points generated by my engine from a 3d triangle stored in an array. I can simply draw lines between the points to generate a mesh but I would like to be able to put a given texture warped to the bounds of this triangle. The given texture is made up of an Image and the 3 points of a different triangle it will source of the image. How can I accomplish this?

Thank you to all who help me solve my challenge :) :)

------------------------------------------------------
```Graphics Drawer;  //Graphics Object
Image TextureImage;  //Image to draw source
Point[] PointsOnImageToSource;  //triangle on source image we want drawn
Point[] PointsOnScreenToDraw;   //Triangle in 2D space where texture needs to be drawn

//TODO - Draw triangle to screen```
Posted 18-Jan-11 10:00am
Marcus Kramer 18-Jan-11 16:53pm

+5 for the question. I don't have any kind of an answer for you, but I like the question.
Thomas.D Williams 19-Jan-11 2:59am

Thank you all for the feedback. Once I come up with a solution to this problem I can post source up here for those interested. :)

Rate this:

## Solution 1

Since you've not specified if you want a projection of an image to the trianlge or just a triangular section of your image see here: http://msdn.microsoft.com/en-us/library/aa457087.aspx[^]

You'd have to elaborate a bit on what you mean by "map an image to a triangle".

Thanks!
Thomas.D Williams 19-Jan-11 2:52am

This link is very useful for extracting the part of the image that is being used as a texture. This is accomplishes the first part of what needs to be done. It just now needs to map it to 3d points (I have already calculated there 2d representation of them). It should be a bit like the warp transform tool in Photoshop.

Thank you for your help. Very useful :)
Rate this:

## Solution 2

DirectX or OpenGl are included with Windows, and should not be considered 3rd party.

Mapping an image to a triangle in 3d space for rendering on a 2d device. Not something I can give you a Quick Answer to.

If you don't mind wading trough a lot of code - http://away3d.com/[^] provides one solution to yur problem - look at the pre flash 10 version.

irrlicht http://irrlicht.sourceforge.net/[^] also comes with a "software" based renderer.

The irrlicht software renderer is pretty impressive in terms of speed.

Regards
Espen Harlinn
Thomas.D Williams 19-Jan-11 2:56am

Very useful links. I shall look through them later once I have done my Maths exam :p I only consider it third party in the sense DirectX has dropped c# support in VS 2010. Very annoying as I wanted to learn DirectX (Still learning to program really).

Thank you for the links. I'm sure i'll put them to good use :) :)
Espen Harlinn 19-Jan-11 5:47am

Glad to be of some help, and thanks for voting

Top Experts
Last 24hrsThis month
 ppolymorphe 110 OriginalGriff 110 Kornfeld Eliyahu Peter 80 Dave Kreskowiak 68 Bryian Tan 55
 OriginalGriff 6,539 CHill60 3,490 Maciej Los 3,143 ppolymorphe 2,030 Jochen Arndt 1,975