-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathglfw_opengl3_imguizmo.rb
More file actions
118 lines (95 loc) · 3.25 KB
/
glfw_opengl3_imguizmo.rb
File metadata and controls
118 lines (95 loc) · 3.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# coding: utf-8
#
require_relative '../utils/appImGui'
require_relative '../libs/imguizmo'
#----------
# gui_main
#----------
def gui_main(window)
window.setBackgroundColor(0.1, 0.1, 0.12)
# Setup fonts
setupFonts()
zmo_op = FFIint.new(ImGuizmo::TRANSLATE)
zmo_mode = FFIint.new(ImGuizmo::LOCAL)
# bounds 6 floats
zmobounds= FFIfloatArray.new([-0.5, -0.5, -0.5, 0.5, 0.5, 0.5], size: 6)
# 16 floats
m_ident = FFIfloatArray.new([1,0,0,0,
0,1,0,0,
0,0,1,0,
0,0,0,1 ], size: 16)
mv_mo = FFIfloatArray.new([1,0,0,0,
0,1,0,0,
0,0,1,0,
0,0,-7,1], size: 16)
mp_mo = FFIfloatArray.new([2.3787,0,0,0,
0,3.1716,0,0,
0,0,-1.0002,-1,
0,0,-0.2,0], size: 16)
mo_mo = FFIfloatArray.new([1,0,0,0,
0,1,0,0,
0,0,1,0,
0.5,0.5,0.5,1], size: 16)
#-----------
# main loop
#-----------
while window.shouldClose()
window.pollEvents()
# Iconify sleep
if window.isIconified()
next
end
window.newFrame()
ImGuizmo.BeginFrame()
#----------------------
# Show ImGuizmo window
#----------------------
begin
ImGui::Begin("ImGuizmo window in Ruby " + ICON_FA_WIFI + " 2025/09", nil)
#
ImGui.igRadioButton_IntPtr("trans", zmo_op.addr, ImGuizmo::TRANSLATE)
ImGui.igSameLine(0.0, -1.0)
ImGui.igRadioButton_IntPtr("rot", zmo_op.addr, ImGuizmo::ROTATE)
ImGui.igSameLine(0.0, -1.0)
ImGui.igRadioButton_IntPtr("scale", zmo_op.addr, ImGuizmo::SCALE)
ImGui.igSameLine(0.0, -1.0)
ImGui.igRadioButton_IntPtr("bounds", zmo_op.addr, ImGuizmo::BOUNDS)
ImGui.igRadioButton_IntPtr("local", zmo_mode.addr, ImGuizmo::LOCAL)
ImGui.igSameLine(0.0, -1.0)
ImGui.igRadioButton_IntPtr("world", zmo_mode.addr, ImGuizmo::WORLD)
ensure
ImGui::End() # Window end proc
end
# --- ImGuizmo drawing & manipulation ---
ImGuizmo.SetRect(0.0, 0.0, window.pio[:DisplaySize][:x], window.pio[:DisplaySize][:y])
ImGuizmo.SetOrthographic(false)
ImGuizmo.DrawGrid( mv_mo.addr, mp_mo.addr, m_ident.addr, 10)
ImGuizmo.DrawCubes(mv_mo.addr, mp_mo.addr, mo_mo.addr , 1)
# read current zmo_op value (int) from memory
current_op = zmo_op.read
current_mode = zmo_mode.read
pmp = (current_op == ImGuizmo::BOUNDS) ? zmobounds.addr : nil
ImGuizmo.Manipulate(mv_mo.addr, mp_mo.addr, current_op, current_mode, mo_mo.addr, nil, nil, pmp, nil)
pos = FFIfloatArray.new([0.0, 0.0], size: 2)
size = FFIfloatArray.new([129.0, 128.0], size: 2)
ImGuizmo.ViewManipulate_Float(mv_mo.addr, 7.0, pos.addr, size.addr, 0x10101010)
#--------
# Render
#--------
window.render()
end # end main loop
end
#------
# main
#------
def main()
begin
window = createImGui(title:"Dear ImGui: Ruby window", titleBarIcon:__dir__ + "/res/r.png")
gui_main(window)
ensure
window.destroyImGui() # Free resources
end
end
if __FILE__ == $PROGRAM_NAME
main()
end