Monday, October 29, 2012

3D simulation of a lathe using solids of revolution, C# and openGL

Last month a teacher from my former college call me telling me that they were going to model all the machines in their mechanical workshop and that they will simulate all ther procesess in a 3D enviroment. They were starting with a lathe, but there was a problem, they had no idea how to make the lowering of the pieces with the lathe's blades.

After doing some research, I found out that most of the pieces made by the lathe were solids of revolution, and... I had a project named Solids of Revolution. After mixing that project with another project that loaded a workshop and had a FPS camera I had a prototype to work on.
The lathe was modeled in 3D max and I exported in 3DS format. The small engine I had (Shadowengine) eased the process of loading models and textures. after that I only had to get the blade position anytime I moved it and lower the radius of the piece in the blade position and generate the revolution on the only part.
I also added some particle to give more realism to the process and used my engine to play sounds.
here is the structure of the project:
It handles all concerning the lathe operations, the movement of the blades,etc.
It handles all concerning the drawing and creation of the piece, also the solid of revolution algorithm for lowering the piece.
It manages the drawing of the workshop and collitions.
It loads and saves all the data of the simulation to an XML file

The other classes are less important. I hope this project will be usefull to anyone who face a similar problem. If you have any questions ask it here in the blog.

Here is the download Link


  1. Hi, What is the best to use for 3D games? openGL, XNA or directX as far I know all are based on openGL but would it be worth it to create it in purely openGL?

  2. Well, first of all DirectX its not OpenGL based they are both 3d renderers. OpenGL is multi-platform and DX only runs on Windows. My advice its to look for a 3D engine that encapsulates both. I recomend Unity 3D.
    Any further questions, let me know.
    It would help that you become a follower of this blog

    1. Hi Vasily! Great content! I just find your blog very useful! Can you please share the source code of your shadow engine? I'd love to have a look at it!

  3. Vasiliy, I have project in mind
    my phone 978-512-9826
    edward rotenberg

    1. Hello I have replied to your mail but I get no answer

  4. Hello, I used your code to load my model. It loads but the parts of my model are not bound. Any idea? Thanks

  5. Can you explain a little further please, try to export the model to OBJ and then te OBJ try to export to 3DS again.
    Also I have a new version where that bug is fixed if you want I can send it to you

  6. Hello Vasily, if I export the model to .obj file and the result to .3ds file then the application gives me an error "System.IndexOutOfRangeException" in method "ContentManager.LoadModels ()". Also what I need is the model hierarchy (parent-child) so I can not export my model to .obj file because I lose the hierarchy. Could you give me your email address to send my model?


  7. Hi Vasily! Great content! I just find your blog very useful! Can you please share the source code of your shadow engine? I'd love to have at look at it!

  8. Hello if you browse the site you will find it
    best regards

  9. I have an exception called TypeInitializationException. How can I handle this. Please help me!!