Link to home
Start Free TrialLog in
Avatar of TheNeil
TheNeil

asked on

OpenGL Toughie

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)
Avatar of fva
fva

Hi.

I tried to give you a hand. Now there's a 0 pts link in 3D games section (https://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.
Avatar of TheNeil

ASKER

Thanks fva (I'm barred from visiting any address with the text 'game' in it)

The Neil =:)
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.
Avatar of TheNeil

ASKER

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 =:)
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.
Avatar of TheNeil

ASKER

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 =:)
ASKER CERTIFIED SOLUTION
Avatar of cybermike3d
cybermike3d

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of TheNeil

ASKER

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 =:)