PDA

View Full Version : Drawing complex objects



mpledge52
01-28-2008, 12:00 PM
I've made a heightmap in openGL, the idea of the heightmap is to use on aeroplanes so passengers can see where they are. What I want to do is include a 3D object that represents an aeroplane, so I can make something that will look like this (http://img141.imageshack.us/img141/5079/rcairshow4200km3.jpg). How would I go about making something like that? Would I have to define all the points manually or is there an easier way?

Thanks for any advice.

Dark Photon
01-29-2008, 05:39 AM
3D object that represents an aeroplane...How would I go about making something like that? Would I have to define all the points manually or is there an easier way?
What you want is termed a 3D modeling program. Here are some examples: <a href="http://www.povray.org/resources/links/3D_Programs/POV-Ray_Modelling_Programs/" target="_blank">
"POV-Ray Modelling Programs"</a>. Some other modeling programs: Maya, 3DS Max, Lightwave 3D, Multigen (Presagis) Creator, Remo3D, OSGEdit, ... They're all over the place, targeting varying markets (media/movies, vis-sim/real-time, games, specific scene graphs, etc.) with varying features and price points. If this is your first foray into modeling, I would recommend focusing on the editors that target real-time graphics, not uber-pretty/uber-slow batch graphics.

Alternatively (simpler), find a free or low-cost pre-built 3D plane model (on 3dcafe (http://www.3dcafe.com/) or elsewhere) and use that. That may work for starters, depending on the poly count and format, but you'll probably find that you want some sort of tools path to adjust the number of polys, optimize the triangle order, split them into batches and material states, and translate them into a format your renderer can deal with more efficiently. If you've got time, doing this yourself will teach you alot.

mpledge52
02-04-2008, 10:36 AM
Thanks for the reply Dark Photon. I've had a read into loading pre built models, .3ds in specific. The trouble is that the models available, and the techniques for loading them are far too complex for my needs. The aeroplane is only a very small feature of the program, it will not be viewed close up so quality is not an issue. I'm simply after the simplest techniques possible.

I think it's probably going to be easier to draw it in openGL defining all the vertices individually, perhaps using some gluPrimitives.

Is there any other easier method than drawing it in this way? Thanks again.

ZbuffeR
02-04-2008, 10:49 AM
With a few ellipsoids (glScale on gluSphere), you can model a plane in a "toon" style.
http://tbn0.google.com/images?q=tbn:GMs3...erns/la1333.jpg (http://tbn0.google.com/images?q=tbn:GMs3ajoF4N70eM:http://www.embroiderydesigns.com/design_thumbs/medium/Pinnacle_Embroidery_Patterns/la1333.jpg)
Or a simple textured quad (with alpha) with an airplane photograph from above.

Dark Photon
02-05-2008, 05:45 AM
Thanks for the reply Dark Photon. I've had a read into loading pre built models, .3ds in specific. The trouble is that the models available, and the techniques for loading them are far too complex for my needs. The aeroplane is only a very small feature of the program, it will not be viewed close up so quality is not an issue. I'm simply after the simplest techniques possible.
Whatever works for you, of course. However, if you find a free plane model you really like (e.g. in 3ds), don't re-invent the wheel and write your own 3ds loader (unless you want to for fun). Just convert it to an easy-to-read format or to your format directly.

One easy way to do that is to convert it to .obj or .osg. Grab OpenSceneGraph (http://www.openscenegraph.org/), build it, and then use its osgconv (http://www.openscenegraph.org/index.php?page=UserGuides.Osgconv) tool to convert from the source format to .obj or .osg (e.g. "osgconv model.3ds model.osg").

Both are really simple formats, and the latter is just a text dump of the scene graph, with vertex attribute arrays and primitives ready to grab and stuff into your own format (note that .osg contains the entire scene graph, so if you want to just snarf the vertex data, or if you want to keep the mode/attribute material state too, go for it). osgconv also optimizes the scene graph by default so you should have reasonably efficient vertex data. Hard to get much simpler than that. You can also use osgviewer (http://www.openscenegraph.org/index.php?page=UserGuides.Osgviewer) (also built-in) to preview the model. You could also write a little OSG plug-in to write any OSG scene graph to your engine's format, and then you can just osgconv directly to your format -- that's not too hard either.

PolyTrans (http://www.okino.com/conv/conv.htm) is a commercial model converter you can consider if needed, but I think you'll get a lot of miles off osgconv.

For the OBJ format spec, go here (http://www.wotsit.org/list.asp?al=O), and select the "OBJ: Wavefront Object files" link.

mpledge52
02-05-2008, 06:14 AM
Thanks again for both of your replies.

I think I'm going to make it out of a mixture of gluCylinders and GL quads. It seems the only way I can do it quickly (time is a big issue!).

I've drawn a mock up model from about 4 cylinders a sphere and several quads. The problem is I've hard coded the position of the vertices into the program, if I wanted to move the plane at all it's all going to screw up because I will have to change all of them which is going to be a pain because it will have to rotate as well as translate.

Is there anyway I can define the vertices of the plane seperately and create a single object from it so to speak, then I can simply call the object and apply the transformations required to the single object (rather than every single vertex)?If that makes any sense?!!


Thanks.

Dark Photon
02-05-2008, 06:46 AM
I've drawn a mock up model from about 4 cylinders a sphere and several quads. The problem is I've hard coded the position of the vertices into the program, if I wanted to move the plane at all it's all going to screw up because I will have to change all of them which is going to be a pain because it will have to rotate as well as translate.

Read the OpenGL Red Book chapter entitled "Viewing". In particular, focus on the part mentioning the "modeling" transform.

PraecorLoth
02-05-2008, 08:58 AM
Is there anyway I can define the vertices of the plane seperately and create a single object from it so to speak, then I can simply call the object and apply the transformations required to the single object (rather than every single vertex)?If that makes any sense?!!

Sure there's a way. You can transform the vertices easily like this per object:

// object #1
glPushMatrix ();
glTranslatef (30.0f, 0.0f, 0.0f); // Move to x direction
glScalef (1.0f, 4.0f, 1.0f); // Scale height
drawVerticesObj1 ();
glPopMatrix ();

// object #2
glPushMatrix ();
glTranslatef (0.0f, 0.0f, -30.0f); // Move to z direction
glRotatef (45.0f, 0, 1, 0); // Rotate around Y axis (yaw)
drawVerticesObj2 ();
glPopMatrix ();

mpledge52
02-05-2008, 01:11 PM
The problem with rotating the plane's part individually is they respond differently. For example, if I draw a simple 2D square and a sphere using the following commands:

glPushMatrix();
glRotatef(90.0,1.0,0.0,0.0);
gluSphere(quadratic,700.0,30,30);
glPopMatrix();

glPushMatrix();
glRotatef(90.0,1.0,0.0,0.0);
glBegin(GL_QUADS);
glTexCoord2f(0.0, 0.0); glVertex3f(50.0, 50.0, -10.0);
glTexCoord2f(0.0, 1.0); glVertex3f(50.0, 55.0, -10.0);
glTexCoord2f(1.0, 1.0); glVertex3f(51.0, 55.0, -10.0);
glTexCoord2f(1.0, 0.0); glVertex3f(51.0, 50.0, -10.0);
glEnd();
glPopMatrix();


The rotations perform differently - the sphere rotates around it's centre, so it doesnt actually move onscreen, whereas the square rotates around something else (0,0,0 I think???) so moves on screen.

What I want to do is draw the all the different elements sepearately (e.g. like the sphere and square above) then group all the individual elements together into one "object" so when I perform a rotation or translation on this new "object" the different elements all perform together as a single unit.

Is this possible or am I going to need to change the way I'm going to draw the plane?

I've had a look throught the redbook again Dark Photon but I couldn't really see anything about how objects can be grouped/drawn etc. It seems more about explaining how the camera system works and how the rotations are performed using matrix multiplication.

Thanks again for any advice.

Nyad
02-05-2008, 02:43 PM
do this:

glTranslate to where you want the object
glRotate for the entire object.
//now for each different part, eg an arm on a robot
glPushMatrix
glTranslate to where you want it
glRotate the part
drawPart
glPopMatrix
//now do the same for the next part.

about getting 3d models. try Blender at blender.org
it's free. also for model loading try the wavefront obj file format. It is very straight forward and I use it for my engine

mpledge52
02-06-2008, 09:37 AM
Thanks Nyad, I gave that ago but it's still not working, now all the objects on screen rotate constantly never staying still! I forgot to mention that I have another object on screen that I want to control seperately. Here's the code I have at the minute, it's probably easier to explain that way:




void camera (void) {

glRotatef(xrot,1.0,0.0,0.0);
glRotatef(yrot,0.0,1.0,0.0);
glRotatef(zrot,0.0,0.0,1.0);
glTranslated(-xpos,-ypos,-zpos);
}

void display (void){

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();

camera();

//****Draw map****
glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);

glColorPointer(3, GL_FLOAT, 0, colors);
glVertexPointer(3, GL_FLOAT, 0, vertices);

glDrawElements(GL_TRIANGLES, indexSize, GL_UNSIGNED_INT, index);

glPopMatrix();




//****Draw Plane****
glRotatef(xrotP,1.0,0.0,0.0); //This is supposed to rotate just the plane

glColor3f(1.0,1.0,1.0);
quadratic=gluNewQuadric();

//Main part of plane
glPushMatrix();
glTranslatef(50000.0,50500.0,-10000.0);
glRotatef(90.0,0.0,1.0,0.0); //Rotate it to be parallel with ground
glRotatef(90.0,1.0,0.0,0.0); //Face North
gluCylinder(quadratic,700.0,700.0,5000.0,30,30);
glPopMatrix();

//Front of plane
glPushMatrix();
glTranslatef(50000.0,45500.0,-10000.0);
glRotatef(90.0,0.0,1.0,0.0);
glRotatef(90.0,1.0,0.0,0.0);
gluSphere(quadratic,700.0,30,30);
glPopMatrix();

//Wing
glPushMatrix();
glBegin(GL_QUADS);
glTexCoord2f(0.0, 0.0); glVertex3f(50700.0, 47000.0, -10000.0);
glTexCoord2f(0.0, 1.0); glVertex3f(50700.0, 49000.0, -10000.0);
glTexCoord2f(1.0, 1.0); glVertex3f(57000.0, 50500.0, -10000.0);
glTexCoord2f(1.0, 0.0); glVertex3f(57000.0, 48500.0, -10000.0);
glEnd();
glPopMatrix();


glutSwapBuffers();

}


The first half of the display function displays the map, the second half displays the plane (well only a few parts of it at the minute!). The map is rotated and translated using the camera function which moves the map based on the keys pressed on the keyboard. This half works fine.

Now the second half is the problem, I basically want to acheive the same thing, use another 'camera' type function which allows me translate/rotate the plane independently - without moving the map. I also want to apply these translations/rotations to the entire plane model, not each part individually.

First off, is this possible? Secondly, if so, what have I done wrong/what do I need to change?

Thanks again for any help, its very much appreciated. :)