ゲームグラフィックス特論
読み取り中…
検索中…
一致する文字列を見つけられません
GgApp.h
[詳解]
1#pragma once
2
3/*
4
5ゲームグラフィックス特論用補助プログラム GLFW3 版
6
7Copyright (c) 2011-2025 Kohe Tokoi. All Rights Reserved.
8
9Permission is hereby granted, free of charge, to any person obtaining a copy
10of this software and associated documentation files (the "Software"), to deal
11in the Software without restriction, including without limitation the rights
12to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13copies or substantial portions of the Software.
14
15The above copyright notice and this permission notice shall be included in
16all copies or substantial portions of the Software.
17
18THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21KOHE TOKOI BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
25*/
26
34
35// Dear ImGui を使うなら
36#if !defined(GG_USE_IMGUI) && !defined(GG_NO_IMGUI)
37# if defined(__has_include)
38# if __has_include(<imgui.h>) || __has_include("imgui.h")
39# define GG_USE_IMGUI
40# endif
41# endif
42#endif
43
44// OpenXR を使うなら
45//#define GG_USE_OPENXR
46
47// 使用するマウスのボタン数
48#if !defined(GG_BUTTON_COUNT)
49# define GG_BUTTON_COUNT 3
50#endif
51
52// 使用するユーザインタフェースの数
53#if !defined(GG_INTERFACE_COUNT)
54# define GG_INTERFACE_COUNT 5
55#endif
56
57// 補助プログラム
58#include "gg.h"
59using namespace gg;
60
61// 標準ライブラリ
62#include <stdexcept>
63#include <iostream>
64
65// ImGui の組み込み
66#if defined(GG_USE_IMGUI)
67# include "imgui.h"
68# include "imgui_impl_glfw.h"
69# include "imgui_impl_opengl3.h"
70#endif
71
72// OpenXR ライブラリの組み込み
73#if defined(GG_USE_OPENXR)
74# if defined(_WIN32)
75# define XR_USE_PLATFORM_WIN32
76# define XR_USE_GRAPHICS_API_OPENGL
77# define GLFW_EXPOSE_NATIVE_WIN32
78# define GLFW_EXPOSE_NATIVE_WGL
79# include <GLFW/glfw3native.h>
80# include <windows.h>
81# include <unknwn.h>
82# if defined(_MSC_VER)
83# pragma comment(lib, "openxr_loader.lib")
84# endif
85# else
86# if !defined(__gl_h_)
87# define __gl_h_
88# endif
89# define XR_USE_PLATFORM_XLIB
90# define XR_USE_GRAPHICS_API_OPENGL
91# define GLFW_EXPOSE_NATIVE_X11
92# define GLFW_EXPOSE_NATIVE_GLX
93# include <GLFW/glfw3native.h>
94# endif
95# include <openxr/openxr.h>
96# include <openxr/openxr_platform.h>
97# include <algorithm>
98# include <cstdio>
99# include <cstring>
100# include <string>
101# include <utility>
102# include <vector>
103#endif
104
108class GgApp
109{
110public:
111
118 GgApp(int major = 0, int minor = 1);
119
125 GgApp(const GgApp& w) = delete;
126
132 GgApp(GgApp&& w) = default;
133
137 virtual ~GgApp();
138
145 GgApp& operator=(const GgApp& w) = delete;
146
153 GgApp& operator=(GgApp&& w) = default;
154
162 int main(int argc, const char* const* argv);
163
170 class Window
171 {
172 // ウィンドウの識別子
173 GLFWwindow* window{ nullptr };
174
175 // ビューポートの横幅と高さ
176 std::array<GLsizei, 2> size;
177
178 // フレームバッファの横幅と高さ
179 std::array<GLsizei, 2> fboSize;
180
181#if defined(IMGUI_VERSION)
182 // メニューバーの高さ
183 GLsizei menubarHeight{ 0 };
184#endif
185
186 // ビューポートの縦横比
187 GLfloat aspect{ 1.0f };
188
189 // マウスの移動速度[X/Y/Z]
190 std::array<GLfloat, 3> velocity{ 1.0f, 1.0f, 0.1f };
191
192 // マウスボタンの状態
193 std::array<bool, GG_BUTTON_COUNT> status{};
194
195 // ユーザインタフェースのデータ構造
196 struct HumanInterface
197 {
198 // 最後にタイプしたキー
199 int lastKey{ 0 };
200
201 // 矢印キー
202 std::array<std::array<int, 2>, 4> arrow{};
203
204 // マウスの現在位置
205 std::array<GLfloat, 2> mouse{};
206
207 // マウスホイールの回転量
208 std::array<GLfloat, 2> wheel{};
209
210 // 平行移動量[ボタン][直前/更新][X/Y/Z]
211 std::array<std::array<gg::GgVector, 2>, GG_BUTTON_COUNT> translation{};
212
213 // トラックボール
214 std::array<gg::GgTrackball, GG_BUTTON_COUNT> rotation;
215
216 // コンストラクタ
217 HumanInterface()
218 {
220 }
221
222 //
223 // マウスや矢印キーによる平行移動量を初期化する
224 //
225 void resetTranslation();
226
227 //
228 // 平行移動量と回転量を更新する (X, Y のみ, Z は wheel() で計算する)
229 //
230 void calcTranslation(int button, const std::array<GLfloat, 3>& velocity);
231 };
232
233 // ヒューマンインタフェースデバイスのデータ
234 std::array<HumanInterface, GG_INTERFACE_COUNT> interfaceData;
235
236 // ヒューマンインタフェースデバイスの番号
237 int interfaceNo{ 0 };
238
239 //
240 // ユーザー定義のコールバック関数へのポインタ
241 //
242 void* userPointer{ nullptr };
243 void (*resizeFunc)(const Window* window, int width, int height){ nullptr };
244 void (*keyboardFunc)(const Window* window, int key, int scancode, int action, int mods){ nullptr };
245 void (*mouseFunc)(const Window* window, int button, int action, int mods){ nullptr };
246 void (*wheelFunc)(const Window* window, double x, double y){ nullptr };
247
248 //
249 // ウィンドウのサイズ変更時の処理
250 //
251 static void resize(GLFWwindow* window, int width, int height);
252
253 //
254 // キーボードをタイプした時の処理
255 //
256 static void keyboard(GLFWwindow* window, int key, int scancode, int action, int mods);
257
258 //
259 // マウスボタンを操作したときの処理
260 //
261 static void mouse(GLFWwindow* window, int button, int action, int mods);
262
263 //
264 // マウスホイールを操作した時の処理
265 //
266 static void wheel(GLFWwindow* window, double x, double y);
267
268 public:
269
279 Window(const std::string& title = "GLFW Window", int width = 640, int height = 480,
280 int fullscreen = 0, GLFWwindow* share = nullptr);
281
287 Window(const Window& w) = delete;
288
294 Window(Window&& w) noexcept;
295
299 virtual ~Window()
300 {
301 // ウィンドウが作成されていなければ戻る
302 if (!window) return;
303
304 // ウィンドウを破棄する
305 glfwDestroyWindow(window);
306 }
307
314 Window& operator=(const Window& w) = delete;
315
322 Window& operator=(Window&& w) noexcept;
323
329 auto* get() const
330 {
331 return window;
332 }
333
339 void setClose(int flag = GLFW_TRUE) const
340 {
341 glfwSetWindowShouldClose(window, flag);
342 }
343
349 bool shouldClose() const
350 {
351 // ウィンドウを閉じるべきなら true を返す
352 return glfwWindowShouldClose(window) != GLFW_FALSE;
353 }
354
360 explicit operator bool();
361
365 void swapBuffers() const;
366
370 void restoreViewport() const
371 {
372 if (!glfwGetWindowAttrib(window, GLFW_ICONIFIED)) glViewport(0, 0, fboSize[0], fboSize[1]);
373 }
374
378 void updateViewport();
379
380#if defined(IMGUI_VERSION)
386 void setMenubarHeight(GLsizei height)
387 {
388 // メニューバーの高さを保存する
389 menubarHeight = height;
390
391 // ビューポートを復帰する
393 }
394#endif
395
401 auto getWidth() const
402 {
403 return size[0];
404 }
405
411 auto getHeight() const
412 {
413 return size[1];
414 }
415
421 auto getFboWidth() const
422 {
423 return fboSize[0];
424 }
425
431 auto getFboHeight() const
432 {
433 return fboSize[1];
434 }
435
441 const auto& getSize() const
442 {
443 return size;
444 }
445
451 void getSize(GLsizei* size) const
452 {
453 size[0] = getWidth();
454 size[1] = getHeight();
455 }
456
462 const auto& getFboSize() const
463 {
464 return fboSize;
465 }
466
472 void getFboSize(GLsizei* fboSize) const
473 {
474 fboSize[0] = getFboWidth();
475 fboSize[1] = getFboHeight();
476 }
477
483 auto getAspect() const
484 {
485 return aspect;
486 }
487
493 bool getKey(int key) const
494 {
495#if defined(IMGUI_VERSION)
496 // ImGui がキーボードを使うときはキーボードの処理を行わない
497 if (ImGui::GetIO().WantCaptureKeyboard) return false;
498#endif
499
500 return glfwGetKey(window, key) != GLFW_RELEASE;
501 }
502
508 void selectInterface(int no)
509 {
510 assert(static_cast<size_t>(no) < interfaceData.size());
511 interfaceNo = no;
512 }
513
521 void setVelocity(GLfloat vx, GLfloat vy, GLfloat vz = 0.1f)
522 {
523 velocity = std::array<GLfloat, 3>{ vx, vy, vz };
524 }
525
532 {
533 auto& current_if{ interfaceData[interfaceNo] };
534 const int key{ current_if.lastKey };
535 current_if.lastKey = 0;
536 return key;
537 }
538
546 auto getArrow(int direction = 0, int mods = 0) const
547 {
548 const auto& current_if{ interfaceData[interfaceNo] };
549 return static_cast<GLfloat>(current_if.arrow[mods & 3][direction & 1]);
550 }
551
558 auto getArrowX(int mods = 0) const
559 {
560 return getArrow(0, mods);
561 }
562
569 auto getArrowY(int mods = 0) const
570 {
571 return getArrow(1, mods);
572 }
573
580 void getArrow(GLfloat* arrow, int mods = 0) const
581 {
582 arrow[0] = getArrowX(mods);
583 arrow[1] = getArrowY(mods);
584 }
585
591 auto getShiftArrowX() const
592 {
593 return getArrow(0, 1);
594 }
595
601 auto getShiftArrowY() const
602 {
603 return getArrow(1, 1);
604 }
605
611 void getShiftArrow(GLfloat* shift_arrow) const
612 {
613 shift_arrow[0] = getShiftArrowX();
614 shift_arrow[1] = getShiftArrowY();
615 }
616
622 auto getControlArrowX() const
623 {
624 return getArrow(0, 2);
625 }
626
632 auto getControlArrowY() const
633 {
634 return getArrow(1, 2);
635 }
636
642 void getControlArrow(GLfloat* control_arrow) const
643 {
644 control_arrow[0] = getControlArrowX();
645 control_arrow[1] = getControlArrowY();
646 }
647
653 auto getAltArrowX() const
654 {
655 return getArrow(0, 3);
656 }
657
663 auto getAltArrowY() const
664 {
665 return getArrow(1, 3);
666 }
667
673 void getAltArrow(GLfloat* alt_arrow) const
674 {
675 alt_arrow[0] = getAltArrowX();
676 alt_arrow[1] = getAltArrowY();
677 }
678
684 const auto* getMouse() const
685 {
686 const auto& current_if{ interfaceData[interfaceNo] };
687 return current_if.mouse.data();
688 }
689
695 void getMouse(GLfloat* position) const
696 {
697 const auto& current_if{ interfaceData[interfaceNo] };
698 position[0] = current_if.mouse[0];
699 position[1] = current_if.mouse[1];
700 }
701
708 auto getMouse(int direction) const
709 {
710 const auto& current_if{ interfaceData[interfaceNo] };
711 return current_if.mouse[direction & 1];
712 }
713
719 auto getMouseX() const
720 {
721 const auto& current_if{ interfaceData[interfaceNo] };
722 return current_if.mouse[0];
723 }
724
730 auto getMouseY() const
731 {
732 const auto& current_if{ interfaceData[interfaceNo] };
733 return current_if.mouse[1];
734 }
735
741 const auto* getWheel() const
742 {
743 const auto& current_if{ interfaceData[interfaceNo] };
744 return current_if.wheel.data();
745 }
746
752 void getWheel(GLfloat* rotation) const
753 {
754 const auto& current_if{ interfaceData[interfaceNo] };
755 rotation[0] = current_if.wheel[0];
756 rotation[1] = current_if.wheel[1];
757 }
758
765 auto getWheel(int direction) const
766 {
767 const auto& current_if{ interfaceData[interfaceNo] };
768 return current_if.wheel[direction & 1];
769 }
770
776 auto getWheelX() const
777 {
778 const auto& current_if{ interfaceData[interfaceNo] };
779 return current_if.wheel[0];
780 }
781
787 auto getWheelY() const
788 {
789 const auto& current_if{ interfaceData[interfaceNo] };
790 return current_if.wheel[1];
791 }
792
799 const auto& getTranslation(int button = GLFW_MOUSE_BUTTON_1) const
800 {
801 const auto& current_if{ interfaceData[interfaceNo] };
802 assert(button >= GLFW_MOUSE_BUTTON_1 && button < GLFW_MOUSE_BUTTON_1 + GG_BUTTON_COUNT);
803 return current_if.translation[button][1];
804 }
805
812 auto getTranslationMatrix(int button = GLFW_MOUSE_BUTTON_1) const
813 {
814 const auto& current_if{ interfaceData[interfaceNo] };
815 assert(button >= GLFW_MOUSE_BUTTON_1 && button < GLFW_MOUSE_BUTTON_1 + GG_BUTTON_COUNT);
816 const auto& t{ current_if.translation[button][1] };
817
819 {
820 1.0f, 0.0f, 0.0f, 0.0f,
821 0.0f, 1.0f, 0.0f, 0.0f,
822 0.0f, 0.0f, 1.0f, 0.0f,
823 t[0], t[1], t[2], 1.0f
824 };
825
826 return m;
827 }
828
835 auto getScrollMatrix(int button = GLFW_MOUSE_BUTTON_1) const
836 {
837 const auto& current_if{ interfaceData[interfaceNo] };
838 assert(button >= GLFW_MOUSE_BUTTON_1 && button < GLFW_MOUSE_BUTTON_1 + GG_BUTTON_COUNT);
839 const auto& t{ current_if.translation[button][1] };
840
842 {
843 t[2] + 1.0f, 0.0f, 0.0f, 0.0f,
844 0.0f, t[2] + 1.0f, 0.0f, 0.0f,
845 0.0f, 0.0f, 1.0f, 0.0f,
846 t[0], t[1], 0.0f, 1.0f
847 };
848
849 return m;
850 }
851
858 auto getRotation(int button = GLFW_MOUSE_BUTTON_1) const
859 {
860 const auto& current_if{ interfaceData[interfaceNo] };
861 assert(button >= GLFW_MOUSE_BUTTON_1 && button < GLFW_MOUSE_BUTTON_1 + GG_BUTTON_COUNT);
862 return current_if.rotation[button].getQuaternion();
863 }
864
871 auto getRotationMatrix(int button = GLFW_MOUSE_BUTTON_1) const
872 {
873 const auto& current_if{ interfaceData[interfaceNo] };
874 assert(button >= GLFW_MOUSE_BUTTON_1 && button < GLFW_MOUSE_BUTTON_1 + GG_BUTTON_COUNT);
875 return current_if.rotation[button].getMatrix();
876 }
877
882 {
883 // トラックボールを初期化する
884 for (auto& tb : interfaceData[interfaceNo].rotation) tb.reset();
885 }
886
891 {
892 // 現在のインターフェースの平行移動量を初期化する
893 interfaceData[interfaceNo].resetTranslation();
894 }
895
899 void reset()
900 {
901 // トラックボール処理を初期化する
903
904 // 平行移動量を初期化する
906 }
907
913 void* getUserPointer() const
914 {
915 return userPointer;
916 }
917
923 void setUserPointer(void* pointer)
924 {
925 userPointer = pointer;
926 }
927
933 void setResizeFunc(void (*func)(const Window* window, int width, int height))
934 {
935 resizeFunc = func;
936 }
937
943 void setKeyboardFunc(void (*func)(const Window* window, int key, int scancode, int action, int mods))
944 {
945 keyboardFunc = func;
946 }
947
953 void setMouseFunc(void (*func)(const Window* window, int button, int action, int mods))
954 {
955 mouseFunc = func;
956 }
957
963 void setWheelFunc(void (*func)(const Window* window, double x, double y))
964 {
965 wheelFunc = func;
966 }
967 };
968
969#if defined(GG_USE_OPENXR)
978 class OpenXR
979 {
980 public:
981
985 enum Hand
986 {
987 Left = 0,
988 Right = 1,
989 Count = 2
990 };
991
992 private:
993
994 // OpenXR のインスタンスとシステム
995 XrInstance instance{ XR_NULL_HANDLE };
996 XrSystemId systemId{ XR_NULL_SYSTEM_ID };
997
998 // OpenXR のシステムの名前
999 std::string systemName;
1000
1001 // OpenXR のセッション
1002 XrSession session{ XR_NULL_HANDLE };
1003 XrSessionState sessionState{ XR_SESSION_STATE_UNKNOWN };
1004
1005 // OpenXR の参照空間
1006 XrSpace appSpace{ XR_NULL_HANDLE };
1007 XrReferenceSpaceType referenceSpaceType{ XR_REFERENCE_SPACE_TYPE_STAGE };
1008
1009 // ビュー設定とステート
1010 std::vector<XrViewConfigurationView> views;
1011 std::vector<XrView> viewStates;
1012
1013 // OpenXR のスワップチェーン
1014 std::vector<XrSwapchain> swapchains;
1015 std::vector<std::vector<XrSwapchainImageOpenGLKHR>> swapchainImages;
1016
1017 // OpenXR へのレンダリングに使う FBO とデプスバッファ (ビューの数だけ確保する)
1018 std::vector<GLuint> openxrFbo;
1019 std::vector<GLuint> openxrDepth;
1020
1021 // スワップチェーンのカラーフォーマットが sRGB なら true
1022 bool swapchainIsSrgb{ true };
1023
1024 // 環境の合成方法
1025 XrEnvironmentBlendMode blendMode{ XR_ENVIRONMENT_BLEND_MODE_OPAQUE };
1026
1027 // フレームの同期状態
1028 XrFrameState frameState{ XR_TYPE_FRAME_STATE };
1029 bool isSessionRunning{ false };
1030
1031 // xrBeginFrame() を呼んで xrEndFrame() を呼んでいない状態なら true
1032 bool frameBegun{ false };
1033
1034 // 視点の姿勢が取得できていれば true
1035 bool viewPoseValid{ false };
1036
1037 // 初期化が完了していれば true
1038 bool initialized{ false };
1039
1040 // 各フレームで取得したスワップチェーンイメージのインデックス
1041 std::vector<uint32_t> currentImageIndex;
1042
1043 // スワップチェーンイメージを取得中のビューなら true
1044 std::vector<bool> imageAcquired;
1045
1046 // ミラー表示を行うビューの番号, ミラー表示を行わないなら -1
1047 int mirrorView{ 0 };
1048
1049 // OpenXR のミラー表示を行うウィンドウ
1050 const Window* window{ nullptr };
1051
1052 // アクションセット
1053 XrActionSet actionSet{ XR_NULL_HANDLE };
1054
1055 // アクション定義
1056 XrAction aimPoseAction{ XR_NULL_HANDLE };
1057 XrAction gripPoseAction{ XR_NULL_HANDLE };
1058 XrAction triggerAction{ XR_NULL_HANDLE };
1059 XrAction gripAction{ XR_NULL_HANDLE };
1060 XrAction thumbstickAction{ XR_NULL_HANDLE };
1061 XrAction thumbstickClickAction{ XR_NULL_HANDLE };
1062 XrAction primaryButtonAction{ XR_NULL_HANDLE };
1063 XrAction secondaryButtonAction{ XR_NULL_HANDLE };
1064 XrAction menuButtonAction{ XR_NULL_HANDLE };
1065 XrAction hapticAction{ XR_NULL_HANDLE };
1066
1067 // コントローラーのスペース
1068 XrSpace aimSpace[Hand::Count]{ XR_NULL_HANDLE, XR_NULL_HANDLE };
1069 XrSpace gripSpace[Hand::Count]{ XR_NULL_HANDLE, XR_NULL_HANDLE };
1070
1071 // コントローラーの状態キャッシュ
1072 struct ControllerState
1073 {
1074 bool isTracked{ false };
1075 XrPosef gripPose{ { 0.0f, 0.0f, 0.0f, 1.0f }, { 0.0f, 0.0f, 0.0f } };
1076 XrPosef aimPose{ { 0.0f, 0.0f, 0.0f, 1.0f }, { 0.0f, 0.0f, 0.0f } };
1077 float trigger{ 0.0f };
1078 float grip{ 0.0f };
1079 std::array<float, 2> thumbstick{ 0.0f, 0.0f };
1080 bool thumbstickClick{ false };
1081 bool primaryButton{ false };
1082 bool secondaryButton{ false };
1083 bool menuButton{ false };
1084 };
1085 ControllerState controllerStates[Hand::Count];
1086
1087 // サポートするパスの文字列
1088 XrPath handSubactionPath[Hand::Count]{ XR_NULL_PATH, XR_NULL_PATH };
1089
1090 //
1091 // アクションシステムを初期化する
1092 //
1093 void initActions();
1094
1095 //
1096 // アクション状態を更新する
1097 //
1098 void pollActions();
1099
1100 //
1101 // OpenXR のイベントを処理する
1102 //
1103 void pollEvents();
1104
1105 //
1106 // スワップチェーンを作成する
1107 //
1108 void createSwapchains();
1109
1110 //
1111 // 描画中のフレームを合成器に転送する
1112 //
1113 void endFrame();
1114
1115 //
1116 // OpenXR のハンドルを破棄する (OpenGL の資源には触れない)
1117 //
1118 void destroyXr();
1119
1120 //
1121 // ミラー表示を行う
1122 //
1123 void blitMirror() const;
1124
1125 //
1126 // コンストラクタ
1127 //
1128 OpenXR();
1129
1130 //
1131 // デストラクタ
1132 //
1133 virtual ~OpenXR();
1134
1135 public:
1136
1137 // シングルトンなのでコピー・ムーブ禁止
1138 OpenXR(const OpenXR&) = delete;
1139 OpenXR& operator=(const OpenXR&) = delete;
1140 OpenXR(OpenXR&&) = delete;
1141 OpenXR& operator=(OpenXR&&) = delete;
1142
1156 static OpenXR& initialize(const Window& window,
1157 XrReferenceSpaceType spaceType = XR_REFERENCE_SPACE_TYPE_STAGE,
1158 const char* appName = "GgApp");
1159
1167 void terminate();
1168
1181 bool begin();
1182
1188 void select(int eye);
1189
1198 void select(int eye, GLfloat* screen, GLfloat* position, GLfloat* orientation);
1199
1209 void commit(int eye);
1210
1222 bool submit(bool mirror = true);
1223
1229 void setMirror(int eye);
1230
1236 int getMirror() const;
1237
1243 bool isRunning() const;
1244
1250 bool isFocused() const;
1251
1257 const std::string& getSystemName() const;
1258
1267 gg::GgMatrix getProjectionMatrix(int eye, GLfloat zNear = 0.1f, GLfloat zFar = 100.0f) const;
1268
1275 gg::GgMatrix getViewMatrix(int eye) const;
1276
1283 gg::GgMatrix getPoseMatrix(int eye) const;
1284
1291 gg::GgVector getPosition(int eye) const;
1292
1299 gg::GgQuaternion getOrientation(int eye) const;
1300
1307 const XrFovf& getFov(int eye) const;
1308
1315 const XrPosef& getPose(int eye) const;
1316
1322 bool isPoseValid() const;
1323
1330 GLsizei getWidth(int eye = 0) const;
1331
1338 GLsizei getHeight(int eye = 0) const;
1339
1346 GLfloat getAspect(int eye = 0) const;
1347
1353 uint32_t getViewCount() const;
1354
1360 XrReferenceSpaceType getReferenceSpaceType() const;
1361
1368 bool isTracked(int hand) const;
1369
1376 gg::GgMatrix getGripMatrix(int hand) const;
1377
1384 gg::GgMatrix getAimMatrix(int hand) const;
1385
1392 gg::GgVector getGripPosition(int hand) const;
1393
1400 gg::GgQuaternion getGripOrientation(int hand) const;
1401
1408 gg::GgVector getAimPosition(int hand) const;
1409
1416 gg::GgQuaternion getAimOrientation(int hand) const;
1417
1424 float getTrigger(int hand) const;
1425
1432 float getGrip(int hand) const;
1433
1440 std::array<float, 2> getThumbstick(int hand) const;
1441
1448 bool getThumbstickClick(int hand) const;
1449
1456 bool getPrimaryButton(int hand) const;
1457
1464 bool getSecondaryButton(int hand) const;
1465
1477 bool getMenuButton(int hand = Hand::Left) const;
1478
1487 void applyHapticVibration(int hand, float durationSeconds = 0.1f, float frequency = XR_FREQUENCY_UNSPECIFIED, float amplitude = 0.5f);
1488 };
1489#endif
1490
1496 static std::string getUsername();
1497};
#define GG_BUTTON_COUNT
Definition GgApp.h:49
auto getControlArrowX() const
Definition GgApp.h:622
auto getControlArrowY() const
Definition GgApp.h:632
auto getTranslationMatrix(int button=GLFW_MOUSE_BUTTON_1) const
Definition GgApp.h:812
auto getShiftArrowX() const
Definition GgApp.h:591
Window(const std::string &title="GLFW Window", int width=640, int height=480, int fullscreen=0, GLFWwindow *share=nullptr)
Definition GgApp.cpp:344
void swapBuffers() const
Definition GgApp.cpp:528
void getShiftArrow(GLfloat *shift_arrow) const
Definition GgApp.h:611
const auto * getMouse() const
Definition GgApp.h:684
void setClose(int flag=GLFW_TRUE) const
Definition GgApp.h:339
auto getWheel(int direction) const
Definition GgApp.h:765
void setMouseFunc(void(*func)(const Window *window, int button, int action, int mods))
Definition GgApp.h:953
void setUserPointer(void *pointer)
Definition GgApp.h:923
void setKeyboardFunc(void(*func)(const Window *window, int key, int scancode, int action, int mods))
Definition GgApp.h:943
auto getMouse(int direction) const
Definition GgApp.h:708
const auto & getSize() const
Definition GgApp.h:441
auto getArrowY(int mods=0) const
Definition GgApp.h:569
void setVelocity(GLfloat vx, GLfloat vy, GLfloat vz=0.1f)
Definition GgApp.h:521
void restoreViewport() const
Definition GgApp.h:370
auto getMouseX() const
Definition GgApp.h:719
void getFboSize(GLsizei *fboSize) const
Definition GgApp.h:472
auto getWidth() const
Definition GgApp.h:401
void * getUserPointer() const
Definition GgApp.h:913
auto getScrollMatrix(int button=GLFW_MOUSE_BUTTON_1) const
Definition GgApp.h:835
void getSize(GLsizei *size) const
Definition GgApp.h:451
const auto & getTranslation(int button=GLFW_MOUSE_BUTTON_1) const
Definition GgApp.h:799
void setWheelFunc(void(*func)(const Window *window, double x, double y))
Definition GgApp.h:963
auto getFboHeight() const
Definition GgApp.h:431
void updateViewport()
Definition GgApp.cpp:547
auto getHeight() const
Definition GgApp.h:411
void getMouse(GLfloat *position) const
Definition GgApp.h:695
auto getArrowX(int mods=0) const
Definition GgApp.h:558
void reset()
Definition GgApp.h:899
void selectInterface(int no)
Definition GgApp.h:508
auto getMouseY() const
Definition GgApp.h:730
void resetTranslation()
Definition GgApp.h:890
void getAltArrow(GLfloat *alt_arrow) const
Definition GgApp.h:673
virtual ~Window()
Definition GgApp.h:299
void getControlArrow(GLfloat *control_arrow) const
Definition GgApp.h:642
void resetRotation()
Definition GgApp.h:881
bool shouldClose() const
Definition GgApp.h:349
auto getFboWidth() const
Definition GgApp.h:421
auto getRotation(int button=GLFW_MOUSE_BUTTON_1) const
Definition GgApp.h:858
auto getAltArrowY() const
Definition GgApp.h:663
auto getAspect() const
Definition GgApp.h:483
auto getAltArrowX() const
Definition GgApp.h:653
void getWheel(GLfloat *rotation) const
Definition GgApp.h:752
void setResizeFunc(void(*func)(const Window *window, int width, int height))
Definition GgApp.h:933
auto getWheelX() const
Definition GgApp.h:776
auto getShiftArrowY() const
Definition GgApp.h:601
auto getRotationMatrix(int button=GLFW_MOUSE_BUTTON_1) const
Definition GgApp.h:871
bool getKey(int key) const
Definition GgApp.h:493
auto * get() const
Definition GgApp.h:329
Window(const Window &w)=delete
const auto & getFboSize() const
Definition GgApp.h:462
void getArrow(GLfloat *arrow, int mods=0) const
Definition GgApp.h:580
Window & operator=(const Window &w)=delete
auto getWheelY() const
Definition GgApp.h:787
const auto * getWheel() const
Definition GgApp.h:741
int getLastKey()
Definition GgApp.h:531
auto getArrow(int direction=0, int mods=0) const
Definition GgApp.h:546
GgApp & operator=(const GgApp &w)=delete
GgApp(GgApp &&w)=default
GgApp(int major=0, int minor=1)
Definition GgApp.cpp:49
GgApp & operator=(GgApp &&w)=default
virtual ~GgApp()
Definition GgApp.cpp:91
static std::string getUsername()
Definition GgApp.cpp:1997
int main(int argc, const char *const *argv)
GgApp(const GgApp &w)=delete
Definition gg.h:1351