becafuel's picture

Newcomer request for help


I'm currently developing (C# on Windows) an application for astronomers and wanted to add a 3D realtime view of an equatorial mount while it is moving. It doesn't need to be photographic rendering and needs only 4 or 5 cylinders (may be textured, but not mandatory) and 2 rotation axis. No light, no skydome, really simple display as it is only informative.

My problem is : where to start ? I've been looking for such primitives (like DrawCircle(), cylinder(), rectangle and so on) but without any success.

Does anyone know of such primitives or do I have to modelize them myself ? If this is the case, is there a doc somewhere explaining how to do that ?

If you need more info on the project itself, do not hesitate to ask. I will answer with pleasure.

Note : I have no problem with the library. Everything is working flawlessly. It's "only" about how to do the job.



Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture

OpenGL itself operates at a lower level than shapes: you need to create a buffer which defines the vertices that comprise the shape you wish to draw. We have some documentation on rendering geometry with OpenGL.

The issue then is how to calculate the vertex coordinates for the shape you wish to draw. There are two solutions:

  • Use the procedural geometry, where you describe the shape using mathematical functions. This works best for simple shapes, such as spheres, ellipsoids, cylinders, planes but can be used to create arbitrary shapes.
  • Use 3d modeling software to model the shape. The more complex the shape, the easier it is to model it through dedicated software.

For this specific use case, it will probably be easier to generate geometry procedurally. For example, this code can be used to generate spheres or hemispheres. With a trivial modification, it can also generate cylinders (use Y = height * phi instead of Y = height * Math.Cos(phi)).

Once you have an array of vertices, you can pass them to OpenGL for rendering (check the documentation on rendering geometry).

becafuel's picture

Thanks for your quick answer !

Well, it seems that it will require a lot of work for what was only a cosmetic addition in my program...

I will have to learn too much things that are not especially useful to me for the moment. But I will give it a try, anyway. I will also have to look for some formulas for the rotation along an axis for which I have the equation. My maths are some (many) years behind me :(

I have one other question, though : about the maths, I think I've seen such transformations in the library. Do you think these functions can help me with the maths ? As I've seen matrixes, there must exist some translation/rotation or so ?

Thanks again. I will keep you informed.


the Fiddler's picture

Yes, you can use the Matrix4.CreateTranslation/CreateFromAxisAngle to create translation and rotation matrices. You can then apply those matrices to rotate a model as outlined in this post.

flopoloco's picture

Try my Entity class here

It will help you handling your scene with extreme easiness...

All you have to do is to simply "inject" your geometry drawing code. The Entity class uses a triangle as an example you can try these:

A Sphere:

A Chamfercube:

I hope that helps... :)

becafuel's picture

Thank you !

Your use-case example is clearly what I want to do ! The sphere method is on my disk; now.

I only have one problem, right now : where can I get the Entity class ? ;-)
In the posts you quote, it seems that there's no complete class. Or am I completely wrong ?


flopoloco's picture

The entity class is located on the post topic "as it is". I have not tried to develop it further since then. I know for sure that common code (used on the OpenTK forums) can be glued together in order to make it useful.