View Full Version : How to create such a text file?...
07-20-2005, 07:37 AM
I read lesson 25 of NeHe. This lesson uses from the text files that contain the vertices of objects. I know that creating such data is so difficult manually.Can we create a shape with a software and then create the vertex data in this manner?:
-0.106 1.593 2.272
-0.106 2.036 2.228
-0.193 2.028 2.228
-0.276 2.002 2.228
-0.353 1.961 2.228
Well, what would you use in your program to hold the vertices? e.g. for C++ I'd use a std::vector or something similar. Then you could use this to draw your objects. For example:
// then in your display function:
glBegin(GL_LINES); // or GL_TRIANGLES, etc.
for (int i = 0; i < vertices.size(); i++)
glEnd();Now the above vector could easilly be saved into a text file like the one you mentioned, don't you think?
07-20-2005, 10:10 PM
Yes DVM, I know that. but my question is another thing!
I need a text file that contains the data of the vertices.I can read the text file and draw the object based on its data. In this program , i only need to read the data from a text file. But if you have seen lesson 25 of NeHe, each of the text files contain of more than 400 vertices. I guess that NeHe has used from a software to generate such values. If it's correct, how can i do this? Unfortunately, i haven't the Email address of Jeff Molofee--If it is his real name. Anyone knows his mail?
07-20-2005, 11:53 PM
it has been a really long time since I've done that lesson, but I want to say yes - yes it is a lot of data points. whether the author manually [or mathematically/automatically] generated those numbers, that's beyond me. but it shouldn't be too hard.
hope that helps
07-20-2005, 11:58 PM
Well.Do you-Or someone else- Know the email address of Jeff Molofee?
In a recent post on those forum, one asked for help for the obj format. I wasn't knewing it, but I discovered it was pretty easy to understand and use. It comes usually with Java but there's no real need for it to be only used within this language...
Here's the link:
Also on windows there are several 3d format exporters so that you can easily transform a model from one format to another (ie obj). So anyone can make a pretty complex model (like a human) with a somewhat complex modeler (as 3ds Max or Maya) and then convert it into another format (like obj). Of course, some information will be lost between conversions just because not all formats support the same things. As for an example, obj seems to support only one texture coordinate per object, and 3ds Max can use more.
However this is a good start and not all people need all the complexity of some expensive modelers.
Hope that helps.
07-21-2005, 01:56 PM
Yes you can create the data for the points of SOME objects programatically. It just depends on what objects you wish to create. Otherwise, if you want the data for a complex object's points then you have to create the object in a 3d modeling application, like TrueSpace or 3ds Max. Then you save off the file, then come up with a parser to read in the file and fill your data structure for the object.
But for basic primitive shapes, like cubes and spheres, you can use mathmatical formulas to create the objects. The easiest one I would guess is the cube since it only has 8 vertices.
When creating a cube you first have to decide how your data structure will look. The basic cube will need to have an array of 8 vertices. If you use just that, then the cube will also need to have an array of indices so that opengl will know how to contect what to what. But since you just want raw data we can say that all you need are the 8 vertices to be saved in the file.
What you can do is first, your cube creating function will need a center position for where the cube is going to be drawn. Here is a prototype of the function:
void vDrawCube( float xpos, float ypos, float zpos );
Well this wont help much unless all of your cubes are going to be the same size, so you should put in a variable for the "radius" of the cube. Radius being how far from the center each face is located. So now our function looks like this:
void vDrawCube( float xpos, float ypos, float zpos, float rad );
Ok, now your function has a position to start from and a distance to go out to. Since each face is a cube, then each vertice of each face is going to be the same distance from the center of the face, which will be the same distance from the center of the cube. So, pick 2 faces in opposite directions to draw, lets pick the top and bottom. Ok, now lets start with the top face and pick the vertex in the positive x and z plane.
Your y value will be ypos + rad.
Your x value will be xpos + rad.
Your z value will be zpos + rad.
So the top, right, closest point on your cube is:
(xpos+rad, ypos+rad, zpos+rad)
Now all you have to do is adjust the x and z values to get the other 3 points on the top face of your cube like so: (this is the 4 points on the top of the cube starting with the right front point and moving to the left and assuming that the positive z axis comes out towards the viewer)
Now, to get the other 4 points of the cube for the bottom face you just flip the y value. So you have all the same x and z values but your y value is now -(ypos+rad).
I will leave it up to you to write the function and to create the ordering of drawing the vertices. Also, on whether to save just the 8 vertices, which is what I would recomend, or to save 24 vertices for the cube. I hope this helps give you some ideas on how you can progrmatically create vertices to save off into a file. To do a sphere, you use the math formula for a circle and can just increment the y value and radius starting at the bottom and going up to the top of the sphere.
Powered by vBulletin® Version 4.2.3 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.