AdityaG
AdityaG

Reputation: 438

Merging a Sphere and Cylinder

I want to render a spring using spheres and cylinders. Each Cylinder has two Spheres at each end and all the cylinders are placed along the spring centre line. I could achieve this .. and rendering is good. I am presently doing it using gluSphere and gluCylinder.

Now when I look at the performance its not good its very slow. So I want to know if the following are possible :

Is it possible that I combine the surfaces of the spheres and cylinders and render only the outer hull but not the inner covered parts of the sphere ... ?

I also read about VBOs .. is it possible to use gluSphere and gluCylinder with VBOs .. ? I cannot use a display list because the properties of the spring keep changing ... !

Can any one suggest a better suggestion?

Upvotes: 1

Views: 1158

Answers (2)

Sir Digby Chicken Caesar
Sir Digby Chicken Caesar

Reputation: 3123

You might want to reconsider the way you are drawing springs. In my opinion there are two valid approaches.

  1. Load a spring model using Assimp or some other model loading software that is easily integrated with OpenGL. Free 3D models can be found at Turbo Squid or through Google's 3D warehouse (while in Google Sketch-Up).

  2. Draw the object purely in OpenGL. The idiomatic way to draw this kind of object using the post fixed function OpenGL pipeline is by drawing volumetric 3D lines. The more lines you draw the more curvature you can give to your spring at the expense of rendering time.

    For drawing springs I would recommend that you define a set of points (with adjacency) that define the shape of your spring and draw these points with a primitive type of GL_LINE_STRIP_ADJACENCY. Then, in the shader program use a geometry shader to expand this pixel-bound line strip into a set of volumetric 3D lines composed of triangle strips.

    This blog post gives an excellent description of the technique.

Upvotes: 3

Zultar
Zultar

Reputation: 181

Your best bet would probably be to take a quick tutorial in any 3D modeling software (Blender comes to mind) and then model your spring in its rest pose using CSG operations.

This approach not only rids you of redundant primitives but also makes it very easy to use your model with VBOs. All you have to do is to parse the output file of Blender (easiest would be .obj), retrieving arrays filled with vertex data (positions, normals, possibly texture coordinates).

Lastly, to "animate" your spring, you can use the vertex shader. You just have to pass it another uniform describing how much the spring is deformed and do the rest of the transformation there.

Upvotes: 1

Related Questions