Solved

OpenGL Toughie

Posted on 2001-06-06
8
402 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
 
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

743 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

11 Experts available now in Live!

Get 1:1 Help Now