Solved

OpenGL Toughie

Posted on 2001-06-06
8
410 Views
Last Modified: 2010-04-06
Ok this question might be better posted in the 3D Games section but as my internet gateway stops me going anywhere near anything with games in the title, this'll do (besides which it's also a Delphi question)

I'm developing an editor for creating 3D objects to use in a piece of OpenGL code. Although I can do this no problem, I'm also trying to get a texture mapping system implemented. Again I've managed it but only when projecting the texture from one direction. What I need to do is apply textures that realistically wrap around the mesh (my efforts always come unstuck when they hit the faces on the 'back' of the object). I'm storing my data as a series of triangular faces, storing the position of each corner (from this I'm calculating the normal to the face and basing my texture mapping calculations etc.)

Anybody got an algorithm (or better still a piece of working code) that would allow me to wrap a texture in this way (preferably being able to decide if the texture is wrapped horizontally, vertically, or in the z-axis)? (ie Give it a 3D point and it returns the 2D point used by OpenGL)
0
Comment
Question by:TheNeil
8 Comments
 
LVL 4

Expert Comment

by:fva
ID: 6162746
Hi.

I tried to give you a hand. Now there's a 0 pts link in 3D games section (http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=3dgames&qid=20131154) pointing to this one. I asked them to come and post here.

HTH,
F.
0
 
LVL 5

Author Comment

by:TheNeil
ID: 6163668
Thanks fva (I'm barred from visiting any address with the text 'game' in it)

The Neil =:)
0
 
LVL 2

Expert Comment

by:cybermike3d
ID: 6179683
There are various ways of tackling the problem ... but, I have had no experience in Delphi.  For starters ... In my opinion ogl is a bit of a nightmare. I have a list of queries as long as my arm still awaiting an answer from microsoft. Are you committed to delphi ... or is visual B or C an option ?  If you download the DX8 SDK (Highly reccomended - chuck ogl away if u can) There are a number of samples ... but they only relate to VB / VC ... maybe there is a delphi SDK for DX8 ...  DX8 is a vast improvement.  The other way is to create a primitive object in something like max. Then, map your texture and export the primitive with the mapping co ordinates. Then, using the converter included with the SDK, convert the primitive shape ie sphere.3ds to a .x file (sphere.x) Open that file and look at the mapping co ords. Then, when u create a sphere, write it out to a .x file, specify the mapping co cords, and read it straight back in again with the co cords and your object will be mapped perfectly. You can then use the meshtool function to start modifying the mesh ... I appreciate that this is a roundabout way of doing things but it will get you going. Get someone with something like 3d studio max to make you a simple library sphere, cylinder, cube, etc... with diferent mapping modes, pre mapped. I don't know if I am being of any help here ... I wonder why you are making a mesh editor in delphi ? As apposed to getting a free dowload of a package like strata 3D or does your sw have to dynamicaly make and modify meshes ?  You can find in depth doccumentation of 3d file formats at www.wotsit.org ... and lots of code samples ... But really, I would not write code to do this functionality when DX8 does it automaticaly. Loading a pre mapped primitive and then modifying it with the mesh tool and letting dx8 do all the hard stuff is the way I would go.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Author Comment

by:TheNeil
ID: 6180238
Well I'm locked with Delphi at the moment so no chance of switching to either VB or C. At the moment I'm creating my mesh data in 3DS and then importing it into my code where I need to do some processing before outputting it in a format used in some 3D stuff (be written by someone else). As there's manipulation going on I needed to generate the texture map data internally so getting 3DS to do the job just won't work. Thanks for the comment and if nothing better comes along then you'll get the points

The Neil =:)
0
 
LVL 2

Expert Comment

by:smitty1276
ID: 6192374
I haven't done it, and to be honest don't want to do it right now, because I would imagine that coding it would be tedious and time consuming, but not necessarily hard.

You will want to temporarily flatten the mesh onto a 2d plane, which means eliminating the z-axis.  To do this you will have to take the z component of each point and use a pythagorian theorum type approach to determine the length of each "line" in your mesh that extends in the z direction.  Then you will have to replot those points to lie only on the x/y axes.  You can then use those to generate texture coordinates.

I don't know how clear that was.  Sorry, I don't have any code... just an idea.  You will be using a lot of geometry, though, to determine angles and lengths of lines.
0
 
LVL 5

Author Comment

by:TheNeil
ID: 6192457
Smitty1276,

Thanks for the suggestion but it's the 'flattening' that's the problem. Although I've written a piece of code that 'unwraps' a cylinder, it can't handle the situations where the object isn't orientated perfectly along the axis. There are also major problems detecting when the texture wraps around the 'back' of the object (the arccos, arctan routines only return 0-180 degrees) and getting a rule that detects this is a real nightmare - hence the question

The Neil =:)
0
 
LVL 2

Accepted Solution

by:
cybermike3d earned 200 total points
ID: 6203376
you can maybe chat to the peeps at   http://www.yks.ne.jp/~hori/DelphiX-e.html
and http://delphi.about.com
0
 
LVL 5

Author Comment

by:TheNeil
ID: 6251904
Looks like no-one is going to be able to give me a hard and fast answer but CyberMike3D's links proved to be the most helpful (although it didn't give me a hard and fast answer either - hence the C grade. Sorry)

The Neil =:)
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

680 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