Gear Mesh Demo

GeeXLab - Mesh Gear demo

A new built-in mesh has been added to GeeXLab the gear.

To create a gear mesh, just call the function gh_mesh.create_gear():

inner_radius = 1.0
outer_radius = 4.0
tooth_depth = 1.0
num_teeth = 10
width = 1.0
mesh_gear = gh_mesh.create_gear(inner_radius, outer_radius, tooth_depth, num_teeth, width)

To show to use of the gear mesh, I coded a demo that is available in the code sample pack in the learn/02-intermediate/08-gear/ folder (the demo is available in the full code sample pack and in the learn code sample pack).

This demo shows two gears in rotation and follows the basic math relation between two gears: the teeth ratio is inversely proportional to the angular speed:

Ta * Sa = Tb * Sb

– Ta = number of teeth of gear A
– Tb = number of teeth of gear B
– Sa = angular speed of gear A
– Sb = angular speed of gear B

Or in terms of ratio:

Ta/Tb = Sb/Sa

The radius of the gears is proportional to the teeth ratio. For example, if Ta/Tb = 2.0, the radius of gear A is twice the radius of gear B:

Ta/Tb = Ra/Rb

– Ra = radius of gear A
– Rb = radius of gear B

With that in mind, you will be able to easily understand source code of the demo (in Lua).

I added a simple ImGui control window to set the angular speed of the gear A (the red gear). This control window allows to display the framerate and to change the diffuse color of each gear. Since the mouse controls the camera rotation, we have to know when the mouse is on the ImGui window in order to disable the camera movement. This is possible thanks to the gh_imgui.is_window_hovered() function (look at the frame.lua file).

This demo is available for all platforms: Windows, Linux, macOS and Raspberry Pi (OpenGL 2.1 and OpenGL ES 2.0):


GeeXLab - Mesh Gear demo - Windows



GeeXLab - Mesh Gear demo - macOS



GeeXLab - Mesh Gear demo - Linux


Raspberry Pi

GeeXLab - Mesh Gear demo - Raspberry Pi

2 thoughts on “Gear Mesh Demo”

  1. Omar

    Suggestion: you can use ImGui::ColorEdit4() instead of DragFloat4() or SliderFloat4() to use widgets designed for colors, w/ color pickers, HSV edition and various other options.

    1. JeGX Post Author

      Thanks for the tip! There are so many things in ImGui and it takes time to discover them all. I will add the ColorEdit4() in the next version. Merci pour cette super lib!!!

Leave a Comment

Your email address will not be published. Required fields are marked *