Click here to Skip to main content
15,881,938 members
Please Sign up or sign in to vote.
5.00/5 (4 votes)
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 :) :)

------------------------------------------------------
C#
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
Comments
fjdiewornncalwe 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. :)

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".

If you can clear this up, it would be nice if you leave a comment to my "answer" and also modify your question so other that read your post will immediately understand.

Thanks!
 
Share this answer
 
Comments
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 :)
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
 
Share this answer
 
Comments
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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900