Solved

OpenGL Toughie

Posted on 2001-06-06
8
407 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

813 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

17 Experts available now in Live!

Get 1:1 Help Now