A new built-in mesh has been added to GeeXLab 0.17.2.0: 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):