Commit | Line | Data |
---|---|---|
830d0ba4 | 1 | diff -pruN --exclude build ./demo_clean/CMakeLists.txt ./demo_dev/CMakeLists.txt |
197cfd38 AIL |
2 | --- ./demo_clean/CMakeLists.txt 2021-01-13 16:58:08.359828681 +0000 |
3 | +++ ./demo_dev/CMakeLists.txt 2021-01-13 17:22:01.166356692 +0000 | |
4 | @@ -1,9 +1,9 @@ | |
5 | -cmake_minimum_required(VERSION 3.16) | |
6 | +cmake_minimum_required(VERSION 3.13) | |
7 | ||
830d0ba4 AIL |
8 | # Set app name. |
9 | set(APP_NAME Demo) | |
10 | # Set directory paths. | |
11 | -set(SDK_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../..) | |
12 | +set(SDK_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../CubismSdkForNative-4-r.1) | |
13 | set(CORE_PATH ${SDK_ROOT_PATH}/Core) | |
14 | set(FRAMEWORK_PATH ${SDK_ROOT_PATH}/Framework) | |
15 | set(THIRD_PARTY_PATH ${SDK_ROOT_PATH}/Samples/OpenGL/thirdParty) | |
16 | @@ -32,7 +32,7 @@ set(GLFW_INSTALL OFF CACHE BOOL "" FORCE | |
17 | set(BUILD_UTILS OFF CACHE BOOL "" FORCE) | |
18 | ||
19 | # Specify version of compiler. | |
20 | -set(CMAKE_CXX_STANDARD 14) | |
21 | +set(CMAKE_CXX_STANDARD 17) | |
22 | set(CMAKE_CXX_STANDARD_REQUIRED ON) | |
23 | set(CMAKE_CXX_EXTENSIONS OFF) | |
24 | ||
4780896a AIL |
25 | @@ -42,7 +42,7 @@ add_library(Live2DCubismCore STATIC IMPO |
26 | # Find library path. | |
27 | set_target_properties(Live2DCubismCore | |
28 | PROPERTIES | |
29 | - IMPORTED_LOCATION ${CORE_PATH}/lib/linux/x86_64/libLive2DCubismCore.a | |
30 | + IMPORTED_LOCATION ${CORE_PATH}/lib/experimental/rpi/libLive2DCubismCore.a | |
31 | INTERFACE_INCLUDE_DIRECTORIES ${CORE_PATH}/include | |
32 | ) | |
33 | ||
33ad240c | 34 | @@ -64,6 +64,11 @@ target_link_libraries(Framework Live2DCu |
830d0ba4 AIL |
35 | # Find opengl libraries. |
36 | find_package(OpenGL REQUIRED) | |
37 | ||
126d8fa4 | 38 | +# Add MouseTrackerForCubism |
33ad240c AIL |
39 | +find_package(PkgConfig) |
40 | +pkg_check_modules(GTKMM gtkmm-3.0) | |
126d8fa4 | 41 | +add_subdirectory(../.. MouseTrackerForCubism_build) |
830d0ba4 AIL |
42 | + |
43 | # Make executable app. | |
44 | add_executable(${APP_NAME}) | |
45 | # Add source files. | |
33ad240c | 46 | @@ -73,9 +78,20 @@ target_link_libraries(${APP_NAME} |
830d0ba4 AIL |
47 | Framework |
48 | glfw | |
49 | ${OPENGL_LIBRARIES} | |
126d8fa4 | 50 | + MouseTrackerForCubism |
830d0ba4 AIL |
51 | + stdc++fs |
52 | ) | |
53 | # Specify include directories. | |
54 | -target_include_directories(${APP_NAME} PRIVATE ${STB_PATH}) | |
33ad240c AIL |
55 | +target_include_directories(${APP_NAME} PRIVATE ${STB_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/../../include ${GTKMM_INCLUDE_DIRS}) |
56 | + | |
57 | +# Copy GUI to build directory | |
58 | +add_custom_command( | |
59 | + TARGET ${APP_NAME} | |
60 | + POST_BUILD | |
61 | + COMMAND | |
62 | + ${CMAKE_COMMAND} -E | |
63 | + copy ${CMAKE_CURRENT_SOURCE_DIR}/../../src/gui.glade $<TARGET_FILE_DIR:${APP_NAME}>/gui.glade | |
64 | +) | |
830d0ba4 AIL |
65 | |
66 | # Copy resource directory to build directory. | |
67 | add_custom_command( | |
830d0ba4 | 68 | diff -pruN --exclude build ./demo_clean/scripts/make_gcc ./demo_dev/scripts/make_gcc |
eba2eb3a | 69 | --- ./demo_clean/scripts/make_gcc 2020-10-01 22:47:25.854827921 +0100 |
33ad240c | 70 | +++ ./demo_dev/scripts/make_gcc 2021-01-01 11:34:25.583684883 +0000 |
126d8fa4 | 71 | @@ -10,4 +10,4 @@ BUILD_PATH=$SCRIPT_PATH/../build/make_gc |
830d0ba4 AIL |
72 | cmake -S "$CMAKE_PATH" \ |
73 | -B "$BUILD_PATH" \ | |
126d8fa4 | 74 | -D CMAKE_BUILD_TYPE=Release |
830d0ba4 | 75 | -cd "$BUILD_PATH" && make |
830d0ba4 AIL |
76 | +cd "$BUILD_PATH" && make -j4 |
77 | diff -pruN --exclude build ./demo_clean/src/CMakeLists.txt ./demo_dev/src/CMakeLists.txt | |
eba2eb3a | 78 | --- ./demo_clean/src/CMakeLists.txt 2020-10-01 22:47:25.850827994 +0100 |
126d8fa4 | 79 | +++ ./demo_dev/src/CMakeLists.txt 2020-10-01 22:47:24.842846271 +0100 |
830d0ba4 AIL |
80 | @@ -19,6 +19,4 @@ target_sources(${APP_NAME} |
81 | ${CMAKE_CURRENT_SOURCE_DIR}/LAppView.cpp | |
82 | ${CMAKE_CURRENT_SOURCE_DIR}/LAppView.hpp | |
83 | ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp | |
84 | - ${CMAKE_CURRENT_SOURCE_DIR}/TouchManager.cpp | |
85 | - ${CMAKE_CURRENT_SOURCE_DIR}/TouchManager.hpp | |
86 | ) | |
eba2eb3a AIL |
87 | diff -pruN --exclude build ./demo_clean/src/LAppDefine.cpp ./demo_dev/src/LAppDefine.cpp |
88 | --- ./demo_clean/src/LAppDefine.cpp 2020-10-01 22:47:25.850827994 +0100 | |
89 | +++ ./demo_dev/src/LAppDefine.cpp 2020-10-18 04:59:13.238452938 +0100 | |
90 | @@ -61,11 +61,11 @@ namespace LAppDefine { | |
91 | const csmInt32 PriorityForce = 3; | |
92 | ||
93 | // デバッグ用ログの表示オプション | |
94 | - const csmBool DebugLogEnable = true; | |
95 | + const csmBool DebugLogEnable = false; | |
96 | const csmBool DebugTouchLogEnable = false; | |
97 | ||
98 | // Frameworkから出力するログのレベル設定 | |
99 | - const CubismFramework::Option::LogLevel CubismLoggingLevel = CubismFramework::Option::LogLevel_Verbose; | |
100 | + const CubismFramework::Option::LogLevel CubismLoggingLevel = CubismFramework::Option::LogLevel_Warning; | |
101 | ||
102 | // デフォルトのレンダーターゲットサイズ | |
103 | const csmInt32 RenderTargetWidth = 1900; | |
830d0ba4 | 104 | diff -pruN --exclude build ./demo_clean/src/LAppDelegate.cpp ./demo_dev/src/LAppDelegate.cpp |
eba2eb3a | 105 | --- ./demo_clean/src/LAppDelegate.cpp 2020-10-01 22:47:25.850827994 +0100 |
126d8fa4 | 106 | +++ ./demo_dev/src/LAppDelegate.cpp 2020-10-01 22:47:24.698848890 +0100 |
830d0ba4 AIL |
107 | @@ -45,7 +45,8 @@ void LAppDelegate::ReleaseInstance() |
108 | s_instance = NULL; | |
109 | } | |
110 | ||
111 | -bool LAppDelegate::Initialize() | |
112 | +bool LAppDelegate::Initialize(int initWindowWidth, int initWindowHeight, | |
113 | + const char *windowTitle) | |
114 | { | |
115 | if (DebugLogEnable) | |
116 | { | |
117 | @@ -63,7 +64,13 @@ bool LAppDelegate::Initialize() | |
118 | } | |
119 | ||
120 | // Windowの生成_ | |
121 | - _window = glfwCreateWindow(RenderTargetWidth, RenderTargetHeight, "SAMPLE", NULL, NULL); | |
122 | + _window = glfwCreateWindow( | |
123 | + initWindowWidth ? initWindowWidth : RenderTargetWidth, | |
124 | + initWindowHeight ? initWindowHeight : RenderTargetHeight, | |
125 | + windowTitle ? windowTitle : "SAMPLE", | |
126 | + NULL, | |
127 | + NULL); | |
128 | + | |
129 | if (_window == NULL) | |
130 | { | |
131 | if (DebugLogEnable) | |
132 | @@ -95,10 +102,6 @@ bool LAppDelegate::Initialize() | |
133 | glEnable(GL_BLEND); | |
134 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | |
135 | ||
136 | - //コールバック関数の登録 | |
137 | - glfwSetMouseButtonCallback(_window, EventHandler::OnMouseCallBack); | |
138 | - glfwSetCursorPosCallback(_window, EventHandler::OnMouseCallBack); | |
139 | - | |
140 | // ウィンドウサイズ記憶 | |
141 | int width, height; | |
142 | glfwGetWindowSize(LAppDelegate::GetInstance()->GetWindow(), &width, &height); | |
143 | @@ -111,8 +114,6 @@ bool LAppDelegate::Initialize() | |
144 | // Cubism3の初期化 | |
145 | InitializeCubism(); | |
146 | ||
147 | - SetRootDirectory(); | |
148 | - | |
149 | //load model | |
150 | LAppLive2DManager::GetInstance(); | |
151 | ||
152 | @@ -214,49 +215,6 @@ void LAppDelegate::InitializeCubism() | |
153 | LAppPal::UpdateTime(); | |
154 | } | |
155 | ||
156 | -void LAppDelegate::OnMouseCallBack(GLFWwindow* window, int button, int action, int modify) | |
157 | -{ | |
158 | - if (_view == NULL) | |
159 | - { | |
160 | - return; | |
161 | - } | |
162 | - if (GLFW_MOUSE_BUTTON_LEFT != button) | |
163 | - { | |
164 | - return; | |
165 | - } | |
166 | - | |
167 | - if (GLFW_PRESS == action) | |
168 | - { | |
169 | - _captured = true; | |
170 | - _view->OnTouchesBegan(_mouseX, _mouseY); | |
171 | - } | |
172 | - else if (GLFW_RELEASE == action) | |
173 | - { | |
174 | - if (_captured) | |
175 | - { | |
176 | - _captured = false; | |
177 | - _view->OnTouchesEnded(_mouseX, _mouseY); | |
178 | - } | |
179 | - } | |
180 | -} | |
181 | - | |
182 | -void LAppDelegate::OnMouseCallBack(GLFWwindow* window, double x, double y) | |
183 | -{ | |
184 | - _mouseX = static_cast<float>(x); | |
185 | - _mouseY = static_cast<float>(y); | |
186 | - | |
187 | - if (!_captured) | |
188 | - { | |
189 | - return; | |
190 | - } | |
191 | - if (_view == NULL) | |
192 | - { | |
193 | - return; | |
194 | - } | |
195 | - | |
196 | - _view->OnTouchesMoved(_mouseX, _mouseY); | |
197 | -} | |
198 | - | |
199 | GLuint LAppDelegate::CreateShader() | |
200 | { | |
201 | //バーテックスシェーダのコンパイル | |
202 | @@ -299,29 +257,9 @@ GLuint LAppDelegate::CreateShader() | |
203 | return programId; | |
204 | } | |
205 | ||
206 | -void LAppDelegate::SetRootDirectory() | |
207 | +void LAppDelegate::SetRootDirectory(std::string rootDir) | |
208 | { | |
209 | - char path[1024]; | |
210 | - ssize_t len = readlink("/proc/self/exe", path, 1024 - 1); | |
211 | - | |
212 | - if (len != -1) | |
213 | - { | |
214 | - path[len] = '\0'; | |
215 | - } | |
216 | - | |
217 | - std::string pathString(path); | |
218 | - | |
219 | - pathString = pathString.substr(0, pathString.rfind("Demo")); | |
220 | - Csm::csmVector<string> splitStrings = this->Split(pathString, '/'); | |
221 | - | |
222 | - this->_rootDirectory = ""; | |
223 | - | |
224 | - for(int i = 0; i < splitStrings.GetSize(); i++) | |
225 | - { | |
226 | - this->_rootDirectory = this->_rootDirectory + "/" +splitStrings[i]; | |
227 | - } | |
228 | - | |
229 | - this->_rootDirectory += "/"; | |
230 | + this->_rootDirectory = rootDir + "/"; | |
231 | } | |
232 | ||
233 | Csm::csmVector<string> LAppDelegate::Split(const std::string& baseString, char delimiter) | |
234 | diff -pruN --exclude build ./demo_clean/src/LAppDelegate.hpp ./demo_dev/src/LAppDelegate.hpp | |
eba2eb3a | 235 | --- ./demo_clean/src/LAppDelegate.hpp 2020-10-01 22:47:25.850827994 +0100 |
126d8fa4 | 236 | +++ ./demo_dev/src/LAppDelegate.hpp 2020-10-01 22:47:24.842846271 +0100 |
830d0ba4 AIL |
237 | @@ -40,7 +40,8 @@ public: |
238 | /** | |
239 | * @brief APPに必要なものを初期化する。 | |
240 | */ | |
241 | - bool Initialize(); | |
242 | + bool Initialize(int initWindowWidth = 0, int initWindowHeight = 0, | |
243 | + const char *windowTitle = "SAMPLE"); | |
244 | ||
245 | /** | |
246 | * @brief 解放する。 | |
247 | @@ -53,25 +54,6 @@ public: | |
248 | void Run(); | |
249 | ||
250 | /** | |
251 | - * @brief OpenGL用 glfwSetMouseButtonCallback用関数。 | |
252 | - * | |
253 | - * @param[in] window コールバックを呼んだWindow情報 | |
254 | - * @param[in] button ボタン種類 | |
255 | - * @param[in] action 実行結果 | |
256 | - * @param[in] modify | |
257 | - */ | |
258 | - void OnMouseCallBack(GLFWwindow* window, int button, int action, int modify); | |
259 | - | |
260 | - /** | |
261 | - * @brief OpenGL用 glfwSetCursorPosCallback用関数。 | |
262 | - * | |
263 | - * @param[in] window コールバックを呼んだWindow情報 | |
264 | - * @param[in] x x座標 | |
265 | - * @param[in] y x座標 | |
266 | - */ | |
267 | - void OnMouseCallBack(GLFWwindow* window, double x, double y); | |
268 | - | |
269 | - /** | |
270 | * @brief シェーダーを登録する。 | |
271 | */ | |
272 | GLuint CreateShader(); | |
273 | @@ -98,8 +80,10 @@ public: | |
274 | ||
275 | /** | |
276 | * @brief ルートディレクトリを設定する。 | |
277 | + * | |
278 | + * @param[in] rootDir : The root directory to set to. | |
279 | */ | |
280 | - void SetRootDirectory(); | |
281 | + void SetRootDirectory(std::string rootDir); | |
282 | ||
283 | /** | |
284 | * @brief ルートディレクトリを取得する。 | |
285 | @@ -146,24 +130,3 @@ private: | |
286 | int _windowWidth; ///< Initialize関数で設定したウィンドウ幅 | |
287 | int _windowHeight; ///< Initialize関数で設定したウィンドウ高さ | |
288 | }; | |
289 | - | |
290 | -class EventHandler | |
291 | -{ | |
292 | -public: | |
293 | - /** | |
294 | - * @brief glfwSetMouseButtonCallback用コールバック関数。 | |
295 | - */ | |
296 | - static void OnMouseCallBack(GLFWwindow* window, int button, int action, int modify) | |
297 | - { | |
298 | - LAppDelegate::GetInstance()->OnMouseCallBack(window, button, action, modify); | |
299 | - } | |
300 | - | |
301 | - /** | |
302 | - * @brief glfwSetCursorPosCallback用コールバック関数。 | |
303 | - */ | |
304 | - static void OnMouseCallBack(GLFWwindow* window, double x, double y) | |
305 | - { | |
306 | - LAppDelegate::GetInstance()->OnMouseCallBack(window, x, y); | |
307 | - } | |
308 | - | |
309 | -}; | |
310 | diff -pruN --exclude build ./demo_clean/src/LAppLive2DManager.cpp ./demo_dev/src/LAppLive2DManager.cpp | |
eba2eb3a | 311 | --- ./demo_clean/src/LAppLive2DManager.cpp 2020-10-01 22:47:25.850827994 +0100 |
126d8fa4 | 312 | +++ ./demo_dev/src/LAppLive2DManager.cpp 2020-10-02 02:00:49.961556700 +0100 |
830d0ba4 AIL |
313 | @@ -52,9 +52,10 @@ void LAppLive2DManager::ReleaseInstance( |
314 | ||
315 | LAppLive2DManager::LAppLive2DManager() | |
316 | : _viewMatrix(NULL) | |
317 | - , _sceneIndex(0) | |
318 | + , _projScaleFactor(1.0f) | |
319 | + , _translateX(0.0f) | |
320 | + , _translateY(0.0f) | |
321 | { | |
322 | - ChangeScene(_sceneIndex); | |
323 | } | |
324 | ||
325 | LAppLive2DManager::~LAppLive2DManager() | |
326 | @@ -98,26 +99,6 @@ void LAppLive2DManager::OnTap(csmFloat32 | |
327 | { | |
328 | LAppPal::PrintLog("[APP]tap point: {x:%.2f y:%.2f}", x, y); | |
329 | } | |
330 | - | |
331 | - for (csmUint32 i = 0; i < _models.GetSize(); i++) | |
332 | - { | |
333 | - if (_models[i]->HitTest(HitAreaNameHead, x, y)) | |
334 | - { | |
335 | - if (DebugLogEnable) | |
336 | - { | |
337 | - LAppPal::PrintLog("[APP]hit area: [%s]", HitAreaNameHead); | |
338 | - } | |
339 | - _models[i]->SetRandomExpression(); | |
340 | - } | |
341 | - else if (_models[i]->HitTest(HitAreaNameBody, x, y)) | |
342 | - { | |
343 | - if (DebugLogEnable) | |
344 | - { | |
345 | - LAppPal::PrintLog("[APP]hit area: [%s]", HitAreaNameBody); | |
346 | - } | |
347 | - _models[i]->StartRandomMotion(MotionGroupTapBody, PriorityNormal, FinishedMotion); | |
348 | - } | |
349 | - } | |
350 | } | |
351 | ||
352 | void LAppLive2DManager::OnUpdate() const | |
353 | @@ -125,7 +106,9 @@ void LAppLive2DManager::OnUpdate() const | |
354 | CubismMatrix44 projection; | |
355 | int width, height; | |
356 | glfwGetWindowSize(LAppDelegate::GetInstance()->GetWindow(), &width, &height); | |
357 | - projection.Scale(1.0f, static_cast<float>(width) / static_cast<float>(height)); | |
358 | + projection.Scale(_projScaleFactor, | |
359 | + _projScaleFactor * static_cast<float>(width) / static_cast<float>(height)); | |
360 | + projection.Translate(_translateX, _translateY); | |
361 | ||
362 | if (_viewMatrix != NULL) | |
363 | { | |
364 | @@ -148,26 +131,10 @@ void LAppLive2DManager::OnUpdate() const | |
365 | } | |
366 | } | |
367 | ||
368 | -void LAppLive2DManager::NextScene() | |
369 | -{ | |
370 | - csmInt32 no = (_sceneIndex + 1) % ModelDirSize; | |
371 | - ChangeScene(no); | |
372 | -} | |
373 | - | |
374 | -void LAppLive2DManager::ChangeScene(Csm::csmInt32 index) | |
375 | +void LAppLive2DManager::SetModel(std::string modelName) | |
376 | { | |
377 | - _sceneIndex = index; | |
378 | - if (DebugLogEnable) | |
379 | - { | |
380 | - LAppPal::PrintLog("[APP]model index: %d", _sceneIndex); | |
381 | - } | |
382 | - | |
383 | - // ModelDir[]に保持したディレクトリ名から | |
384 | - // model3.jsonのパスを決定する. | |
385 | - // ディレクトリ名とmodel3.jsonの名前を一致させておくこと. | |
386 | - std::string model = ModelDir[index]; | |
387 | - std::string modelPath = LAppDelegate::GetInstance()->GetRootDirectory() + ResourcesPath + model + "/"; | |
388 | - std::string modelJsonName = ModelDir[index]; | |
389 | + std::string modelPath = LAppDelegate::GetInstance()->GetRootDirectory() + ResourcesPath + modelName + "/"; | |
390 | + std::string modelJsonName = modelName; | |
391 | modelJsonName += ".model3.json"; | |
392 | ||
393 | ReleaseAllModel(); | |
394 | @@ -215,3 +182,20 @@ csmUint32 LAppLive2DManager::GetModelNum | |
395 | { | |
396 | return _models.GetSize(); | |
397 | } | |
398 | + | |
126d8fa4 | 399 | +void LAppLive2DManager::SetTracker(MouseCursorTracker *tracker) |
830d0ba4 AIL |
400 | +{ |
401 | + for (auto it = _models.Begin(); it != _models.End(); ++it) | |
402 | + { | |
126d8fa4 | 403 | + (*it)->SetTracker(tracker); |
830d0ba4 AIL |
404 | + } |
405 | +} | |
406 | + | |
407 | +void LAppLive2DManager::SetProjectionScaleTranslate(float scaleFactor, | |
408 | + float translateX, | |
409 | + float translateY) | |
410 | +{ | |
411 | + _projScaleFactor = scaleFactor; | |
412 | + _translateX = translateX; | |
413 | + _translateY = translateY; | |
414 | +} | |
415 | diff -pruN --exclude build ./demo_clean/src/LAppLive2DManager.hpp ./demo_dev/src/LAppLive2DManager.hpp | |
eba2eb3a | 416 | --- ./demo_clean/src/LAppLive2DManager.hpp 2020-10-01 22:47:25.846828066 +0100 |
126d8fa4 | 417 | +++ ./demo_dev/src/LAppLive2DManager.hpp 2020-10-01 23:36:24.583055381 +0100 |
830d0ba4 AIL |
418 | @@ -6,12 +6,15 @@ |
419 | */ | |
420 | #pragma once | |
421 | ||
422 | +#include <string> | |
423 | #include <CubismFramework.hpp> | |
424 | #include <Math/CubismMatrix44.hpp> | |
425 | #include <Type/csmVector.hpp> | |
426 | ||
427 | class LAppModel; | |
428 | ||
126d8fa4 | 429 | +class MouseCursorTracker; |
830d0ba4 AIL |
430 | + |
431 | /** | |
432 | * @brief サンプルアプリケーションにおいてCubismModelを管理するクラス<br> | |
433 | * モデル生成と破棄、タップイベントの処理、モデル切り替えを行う。 | |
434 | @@ -72,16 +75,12 @@ public: | |
435 | void OnUpdate() const; | |
436 | ||
437 | /** | |
438 | - * @brief 次のシーンに切り替える<br> | |
439 | - * サンプルアプリケーションではモデルセットの切り替えを行う。 | |
440 | - */ | |
441 | - void NextScene(); | |
442 | - | |
443 | - /** | |
444 | - * @brief シーンを切り替える<br> | |
445 | - * サンプルアプリケーションではモデルセットの切り替えを行う。 | |
446 | - */ | |
447 | - void ChangeScene(Csm::csmInt32 index); | |
448 | + * @brief Set model data | |
449 | + * | |
450 | + * @param[in] modelName : Name of model, should be the same for both | |
451 | + * the directory and the model3.json file | |
452 | + */ | |
453 | + void SetModel(std::string modelName); | |
454 | ||
455 | /** | |
456 | * @brief モデル個数を得る | |
457 | @@ -89,6 +88,24 @@ public: | |
458 | */ | |
459 | Csm::csmUint32 GetModelNum() const; | |
460 | ||
461 | + /** | |
126d8fa4 | 462 | + * @brief Set the pointer to the MouseCursorTracker instance |
830d0ba4 | 463 | + * |
126d8fa4 | 464 | + * @param[in] tracker : Pointer to MouseCursorTracker instance |
830d0ba4 | 465 | + */ |
126d8fa4 | 466 | + void SetTracker(MouseCursorTracker *tracker); |
830d0ba4 AIL |
467 | + |
468 | + /** | |
469 | + * @brief Set projection scale factor and translation parameters | |
470 | + * | |
471 | + * @param[in] scaleFactor : Scale factor applied in both X and Y directions | |
472 | + * @param[in] translateX : Translation in X direction | |
473 | + * @param[in] translateY : Translation in Y direction | |
474 | + */ | |
475 | + void SetProjectionScaleTranslate(float scaleFactor, | |
476 | + float translateX, | |
477 | + float translateY); | |
478 | + | |
479 | private: | |
480 | /** | |
481 | * @brief コンストラクタ | |
482 | @@ -102,5 +119,8 @@ private: | |
483 | ||
484 | Csm::CubismMatrix44* _viewMatrix; ///< モデル描画に用いるView行列 | |
485 | Csm::csmVector<LAppModel*> _models; ///< モデルインスタンスのコンテナ | |
486 | - Csm::csmInt32 _sceneIndex; ///< 表示するシーンのインデックス値 | |
487 | + | |
488 | + float _projScaleFactor; | |
489 | + float _translateX; | |
490 | + float _translateY; | |
491 | }; | |
492 | diff -pruN --exclude build ./demo_clean/src/LAppModel.cpp ./demo_dev/src/LAppModel.cpp | |
eba2eb3a AIL |
493 | --- ./demo_clean/src/LAppModel.cpp 2020-10-01 22:47:25.850827994 +0100 |
494 | +++ ./demo_dev/src/LAppModel.cpp 2020-10-18 09:26:08.998822685 +0100 | |
495 | @@ -21,6 +21,10 @@ | |
830d0ba4 AIL |
496 | #include "LAppTextureManager.hpp" |
497 | #include "LAppDelegate.hpp" | |
498 | ||
126d8fa4 | 499 | +#include "mouse_cursor_tracker.h" |
830d0ba4 | 500 | + |
eba2eb3a AIL |
501 | +#include <iostream> |
502 | + | |
830d0ba4 AIL |
503 | using namespace Live2D::Cubism::Framework; |
504 | using namespace Live2D::Cubism::Framework::DefaultParameterId; | |
505 | using namespace LAppDefine; | |
eba2eb3a | 506 | @@ -49,6 +53,7 @@ LAppModel::LAppModel() |
126d8fa4 AIL |
507 | : CubismUserModel() |
508 | , _modelSetting(NULL) | |
509 | , _userTimeSeconds(0.0f) | |
510 | + , _tracker(nullptr) | |
511 | { | |
512 | if (DebugLogEnable) | |
513 | { | |
eba2eb3a | 514 | @@ -335,59 +340,110 @@ void LAppModel::Update() |
830d0ba4 AIL |
515 | const csmFloat32 deltaTimeSeconds = LAppPal::GetDeltaTime(); |
516 | _userTimeSeconds += deltaTimeSeconds; | |
517 | ||
518 | - _dragManager->Update(deltaTimeSeconds); | |
519 | - _dragX = _dragManager->GetX(); | |
520 | - _dragY = _dragManager->GetY(); | |
521 | - | |
522 | - // モーションによるパラメータ更新の有無 | |
523 | - csmBool motionUpdated = false; | |
524 | - | |
525 | - //----------------------------------------------------------------- | |
526 | - _model->LoadParameters(); // 前回セーブされた状態をロード | |
527 | - if (_motionManager->IsFinished()) | |
eba2eb3a | 528 | - { |
830d0ba4 AIL |
529 | - // モーションの再生がない場合、待機モーションの中からランダムで再生する |
530 | - StartRandomMotion(MotionGroupIdle, PriorityIdle); | |
531 | - } | |
532 | - else | |
eba2eb3a AIL |
533 | + if (_tracker) |
534 | { | |
830d0ba4 AIL |
535 | - motionUpdated = _motionManager->UpdateMotion(_model, deltaTimeSeconds); // モーションを更新 |
536 | - } | |
537 | - _model->SaveParameters(); // 状態を保存 | |
538 | - //----------------------------------------------------------------- | |
2b1f0c7c | 539 | + auto idMan = CubismFramework::GetIdManager(); |
126d8fa4 | 540 | + auto params = _tracker->getParams(); |
2b1f0c7c | 541 | |
830d0ba4 AIL |
542 | - // まばたき |
543 | - if (!motionUpdated) | |
544 | - { | |
545 | - if (_eyeBlink != NULL) | |
2b1f0c7c | 546 | + _model->LoadParameters(); // 前回セーブされた状態をロード |
eba2eb3a AIL |
547 | + |
548 | + int paramsMotionPriority = static_cast<int>(params.motionPriority); | |
549 | + | |
550 | + if (paramsMotionPriority != PriorityNone) | |
2b1f0c7c | 551 | { |
830d0ba4 AIL |
552 | - // メインモーションの更新がないとき |
553 | - _eyeBlink->UpdateParameters(_model, deltaTimeSeconds); // 目パチ | |
eba2eb3a AIL |
554 | + StartMotion(params.motionGroup.c_str(), params.motionNumber, |
555 | + paramsMotionPriority); | |
556 | + } | |
557 | + else if (params.randomIdleMotion && _motionManager->IsFinished()) | |
558 | + { | |
2b1f0c7c AIL |
559 | + // モーションの再生がない場合、待機モーションの中からランダムで再生する |
560 | + StartRandomMotion(MotionGroupIdle, PriorityIdle); | |
561 | } | |
830d0ba4 | 562 | - } |
126d8fa4 | 563 | |
830d0ba4 | 564 | - if (_expressionManager != NULL) |
2b1f0c7c | 565 | - { |
830d0ba4 AIL |
566 | - _expressionManager->UpdateMotion(_model, deltaTimeSeconds); // 表情でパラメータ更新(相対変化) |
567 | - } | |
eba2eb3a AIL |
568 | + // FIXME pose does not return to normal after motion |
569 | + // if we don't have randomIdleMotion set | |
570 | + else | |
571 | + { | |
572 | + _motionManager->UpdateMotion(_model, deltaTimeSeconds); // モーションを更新 | |
573 | + } | |
574 | + _model->SaveParameters(); // 状態を保存 | |
126d8fa4 | 575 | |
830d0ba4 AIL |
576 | - //ドラッグによる変化 |
577 | - //ドラッグによる顔の向きの調整 | |
578 | - _model->AddParameterValue(_idParamAngleX, _dragX * 30); // -30から30の値を加える | |
579 | - _model->AddParameterValue(_idParamAngleY, _dragY * 30); | |
580 | - _model->AddParameterValue(_idParamAngleZ, _dragX * _dragY * -30); | |
eba2eb3a | 581 | + if (params.expression != "") |
126d8fa4 | 582 | + { |
eba2eb3a | 583 | + SetExpression(params.expression.c_str()); |
126d8fa4 | 584 | + } |
eba2eb3a | 585 | + if (_expressionManager != NULL) |
2b1f0c7c | 586 | + { |
eba2eb3a | 587 | + _expressionManager->UpdateMotion(_model, deltaTimeSeconds); // 表情でパラメータ更新(相対変化) |
2b1f0c7c | 588 | + } |
126d8fa4 AIL |
589 | |
590 | - //ドラッグによる体の向きの調整 | |
591 | - _model->AddParameterValue(_idParamBodyAngleX, _dragX * 10); // -10から10の値を加える | |
eba2eb3a AIL |
592 | + bool autoBlink = params.autoBlink && _eyeBlink; |
593 | + auto eyeLOpenIt = params.live2d.find("ParamEyeLOpen"); | |
594 | + auto eyeROpenIt = params.live2d.find("ParamEyeROpen"); | |
2b1f0c7c | 595 | |
830d0ba4 AIL |
596 | - //ドラッグによる目の向きの調整 |
597 | - _model->AddParameterValue(_idParamEyeBallX, _dragX); // -1から1の値を加える | |
598 | - _model->AddParameterValue(_idParamEyeBallY, _dragY); | |
eba2eb3a | 599 | + if (autoBlink) |
126d8fa4 | 600 | + { |
eba2eb3a AIL |
601 | + // Handle blink first |
602 | + _eyeBlink->UpdateParameters(_model, deltaTimeSeconds); | |
603 | + } | |
830d0ba4 AIL |
604 | |
605 | - // 呼吸など | |
606 | - if (_breath != NULL) | |
607 | - { | |
608 | - _breath->UpdateParameters(_model, deltaTimeSeconds); | |
eba2eb3a AIL |
609 | + if (eyeLOpenIt != params.live2d.end()) |
610 | + { | |
611 | + // If value specified, override blinking | |
612 | + _model->SetParameterValue(idMan->GetId("ParamEyeLOpen"), | |
613 | + eyeLOpenIt->second); | |
614 | + } | |
615 | + else if (!autoBlink) | |
616 | + { | |
617 | + // If no value specified and no auto blink, set to 1 | |
618 | + _model->SetParameterValue(idMan->GetId("ParamEyeLOpen"), 1); | |
619 | + | |
620 | + } | |
621 | + | |
622 | + if (eyeROpenIt != params.live2d.end()) | |
623 | + { | |
624 | + _model->SetParameterValue(idMan->GetId("ParamEyeROpen"), | |
625 | + eyeROpenIt->second); | |
626 | + } | |
627 | + else if (!autoBlink) | |
628 | + { | |
629 | + _model->SetParameterValue(idMan->GetId("ParamEyeROpen"), 1); | |
630 | + } | |
631 | + | |
632 | + | |
633 | + if (params.useLipSync && _lipSync) | |
634 | + { | |
635 | + csmFloat32 value = params.lipSyncParam; // 0 to 1 | |
636 | + | |
126d8fa4 AIL |
637 | + for (csmUint32 i = 0; i < _lipSyncIds.GetSize(); ++i) |
638 | + { | |
639 | + _model->AddParameterValue(_lipSyncIds[i], value, 0.8f); | |
640 | + } | |
2b1f0c7c AIL |
641 | + } |
642 | + else | |
643 | + { | |
126d8fa4 | 644 | + _model->SetParameterValue(idMan->GetId("ParamMouthOpenY"), |
eba2eb3a AIL |
645 | + params.live2d["ParamMouthOpenY"]); |
646 | + } | |
647 | + | |
648 | + for (auto const &entry : params.live2d) | |
649 | + { | |
650 | + std::string key = entry.first; | |
651 | + double val = entry.second; | |
652 | + | |
653 | + if (key != "ParamEyeLOpen" && key != "ParamEyeROpen" && | |
654 | + key != "ParamMouthOpenY") | |
655 | + { | |
656 | + _model->SetParameterValue(idMan->GetId(key.c_str()), val); | |
657 | + } | |
2b1f0c7c | 658 | + } |
126d8fa4 | 659 | + |
2b1f0c7c AIL |
660 | + if (params.autoBreath && _breath) |
661 | + { | |
662 | + // Note: _model->LoadParameters and SaveParameters is needed | |
663 | + // before - see above. | |
664 | + _breath->UpdateParameters(_model, deltaTimeSeconds); | |
665 | + } | |
830d0ba4 AIL |
666 | } |
667 | ||
668 | // 物理演算の設定 | |
eba2eb3a | 669 | @@ -396,17 +452,6 @@ void LAppModel::Update() |
830d0ba4 AIL |
670 | _physics->Evaluate(_model, deltaTimeSeconds); |
671 | } | |
672 | ||
673 | - // リップシンクの設定 | |
674 | - if (_lipSync) | |
675 | - { | |
676 | - csmFloat32 value = 0; // リアルタイムでリップシンクを行う場合、システムから音量を取得して0〜1の範囲で値を入力します。 | |
677 | - | |
678 | - for (csmUint32 i = 0; i < _lipSyncIds.GetSize(); ++i) | |
679 | - { | |
680 | - _model->AddParameterValue(_lipSyncIds[i], value, 0.8f); | |
681 | - } | |
682 | - } | |
683 | - | |
684 | // ポーズの設定 | |
685 | if (_pose != NULL) | |
686 | { | |
eba2eb3a | 687 | @@ -626,3 +671,14 @@ Csm::Rendering::CubismOffscreenFrame_Ope |
830d0ba4 AIL |
688 | { |
689 | return _renderBuffer; | |
690 | } | |
691 | + | |
126d8fa4 | 692 | +void LAppModel::SetTracker(MouseCursorTracker *tracker) |
830d0ba4 | 693 | +{ |
126d8fa4 | 694 | + _tracker = tracker; |
830d0ba4 AIL |
695 | +} |
696 | + | |
eba2eb3a AIL |
697 | +Csm::ICubismModelSetting* LAppModel::GetModelSetting(void) const |
698 | +{ | |
699 | + return _modelSetting; | |
700 | +} | |
701 | + | |
830d0ba4 | 702 | diff -pruN --exclude build ./demo_clean/src/LAppModel.hpp ./demo_dev/src/LAppModel.hpp |
eba2eb3a AIL |
703 | --- ./demo_clean/src/LAppModel.hpp 2020-10-01 22:47:25.850827994 +0100 |
704 | +++ ./demo_dev/src/LAppModel.hpp 2020-10-18 03:04:52.142045751 +0100 | |
830d0ba4 AIL |
705 | @@ -13,6 +13,7 @@ |
706 | #include <Type/csmRectF.hpp> | |
707 | #include <Rendering/OpenGL/CubismOffscreenSurface_OpenGLES2.hpp> | |
708 | ||
126d8fa4 | 709 | +#include "mouse_cursor_tracker.h" |
830d0ba4 AIL |
710 | |
711 | /** | |
712 | * @brief ユーザーが実際に使用するモデルの実装クラス<br> | |
eba2eb3a | 713 | @@ -113,6 +114,15 @@ public: |
830d0ba4 AIL |
714 | */ |
715 | Csm::Rendering::CubismOffscreenFrame_OpenGLES2& GetRenderBuffer(); | |
716 | ||
717 | + /** | |
126d8fa4 | 718 | + * @brief Set the pointer to the MouseCursorTracker instance |
830d0ba4 | 719 | + * |
126d8fa4 | 720 | + * @param[in] tracker : Pointer to MouseCursorTracker instance |
830d0ba4 | 721 | + */ |
126d8fa4 | 722 | + void SetTracker(MouseCursorTracker *tracker); |
830d0ba4 | 723 | + |
eba2eb3a AIL |
724 | + Csm::ICubismModelSetting* GetModelSetting(void) const; |
725 | + | |
830d0ba4 AIL |
726 | protected: |
727 | /** | |
728 | * @brief モデルを描画する処理。モデルを描画する空間のView-Projection行列を渡す。 | |
eba2eb3a | 729 | @@ -183,6 +193,8 @@ private: |
830d0ba4 AIL |
730 | const Csm::CubismId* _idParamEyeBallY; ///< パラメータID: ParamEyeBallXY |
731 | ||
732 | Csm::Rendering::CubismOffscreenFrame_OpenGLES2 _renderBuffer; ///< フレームバッファ以外の描画先 | |
733 | + | |
126d8fa4 | 734 | + MouseCursorTracker *_tracker; |
830d0ba4 AIL |
735 | }; |
736 | ||
737 | ||
738 | diff -pruN --exclude build ./demo_clean/src/LAppPal.cpp ./demo_dev/src/LAppPal.cpp | |
eba2eb3a AIL |
739 | --- ./demo_clean/src/LAppPal.cpp 2020-10-01 22:47:25.850827994 +0100 |
740 | +++ ./demo_dev/src/LAppPal.cpp 2020-10-18 04:57:43.289600308 +0100 | |
830d0ba4 AIL |
741 | @@ -6,6 +6,7 @@ |
742 | */ | |
743 | ||
744 | #include "LAppPal.hpp" | |
745 | +#include <stdexcept> | |
746 | #include <stdio.h> | |
747 | #include <stdlib.h> | |
748 | #include <stdarg.h> | |
eba2eb3a AIL |
749 | @@ -36,7 +37,6 @@ csmByte* LAppPal::LoadFileAsBytes(const |
750 | if (stat(path, &statBuf) == 0) | |
751 | { | |
752 | size = statBuf.st_size; | |
753 | - PrintLog(path); | |
754 | } | |
755 | ||
756 | std::fstream file; | |
757 | @@ -45,10 +45,7 @@ csmByte* LAppPal::LoadFileAsBytes(const | |
830d0ba4 AIL |
758 | file.open(path, std::ios::in | std::ios::binary); |
759 | if (!file.is_open()) | |
760 | { | |
761 | - if (DebugLogEnable) | |
762 | - { | |
763 | - PrintLog("file open error"); | |
764 | - } | |
765 | + throw std::runtime_error("Failed to open file " + filePath); | |
766 | return NULL; | |
767 | } | |
768 | file.read(buf, size); | |
769 | diff -pruN --exclude build ./demo_clean/src/LAppTextureManager.cpp ./demo_dev/src/LAppTextureManager.cpp | |
eba2eb3a | 770 | --- ./demo_clean/src/LAppTextureManager.cpp 2020-10-01 22:47:25.850827994 +0100 |
126d8fa4 | 771 | +++ ./demo_dev/src/LAppTextureManager.cpp 2020-10-01 22:47:24.654849690 +0100 |
830d0ba4 AIL |
772 | @@ -96,6 +96,46 @@ LAppTextureManager::TextureInfo* LAppTex |
773 | ||
774 | } | |
775 | ||
776 | +LAppTextureManager::TextureInfo* LAppTextureManager::CreateTextureFromColor( | |
777 | + uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha | |
778 | +) | |
779 | +{ | |
780 | + int width = 8, height = 8; | |
781 | + | |
782 | + uint8_t pixels[height][width][4]; | |
783 | + for (std::size_t h = 0; h < height; h++) | |
784 | + { | |
785 | + for (std::size_t w = 0; w < width; w++) | |
786 | + { | |
787 | + pixels[h][w][0] = red; | |
788 | + pixels[h][w][1] = green; | |
789 | + pixels[h][w][2] = blue; | |
790 | + pixels[h][w][3] = alpha; | |
791 | + } | |
792 | + } | |
793 | + | |
794 | + GLuint textureId; | |
795 | + glGenTextures(1, &textureId); | |
796 | + glBindTexture(GL_TEXTURE_2D, textureId); | |
797 | + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); | |
798 | + | |
799 | + glGenerateMipmap(GL_TEXTURE_2D); | |
800 | + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); | |
801 | + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); | |
802 | + glBindTexture(GL_TEXTURE_2D, 0); | |
803 | + | |
804 | + | |
805 | + LAppTextureManager::TextureInfo* textureInfo = new LAppTextureManager::TextureInfo(); | |
806 | + textureInfo->fileName = ""; | |
807 | + textureInfo->width = width; | |
808 | + textureInfo->height = height; | |
809 | + textureInfo->id = textureId; | |
810 | + | |
811 | + _textures.PushBack(textureInfo); | |
812 | + | |
813 | + return textureInfo; | |
814 | +} | |
815 | + | |
816 | void LAppTextureManager::ReleaseTextures() | |
817 | { | |
818 | for (Csm::csmUint32 i = 0; i < _textures.GetSize(); i++) | |
819 | diff -pruN --exclude build ./demo_clean/src/LAppTextureManager.hpp ./demo_dev/src/LAppTextureManager.hpp | |
eba2eb3a | 820 | --- ./demo_clean/src/LAppTextureManager.hpp 2020-10-01 22:47:25.846828066 +0100 |
126d8fa4 | 821 | +++ ./demo_dev/src/LAppTextureManager.hpp 2020-10-01 22:47:24.786847290 +0100 |
830d0ba4 AIL |
822 | @@ -72,6 +72,8 @@ public: |
823 | */ | |
824 | TextureInfo* CreateTextureFromPngFile(std::string fileName); | |
825 | ||
826 | + TextureInfo *CreateTextureFromColor(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha = 255); | |
827 | + | |
828 | /** | |
829 | * @brief 画像の解放 | |
830 | * | |
831 | diff -pruN --exclude build ./demo_clean/src/LAppView.cpp ./demo_dev/src/LAppView.cpp | |
eba2eb3a | 832 | --- ./demo_clean/src/LAppView.cpp 2020-10-01 22:47:25.850827994 +0100 |
126d8fa4 | 833 | +++ ./demo_dev/src/LAppView.cpp 2020-10-01 22:47:24.602850636 +0100 |
830d0ba4 AIL |
834 | @@ -13,7 +13,6 @@ |
835 | #include "LAppLive2DManager.hpp" | |
836 | #include "LAppTextureManager.hpp" | |
837 | #include "LAppDefine.hpp" | |
838 | -#include "TouchManager.hpp" | |
839 | #include "LAppSprite.hpp" | |
840 | #include "LAppModel.hpp" | |
841 | ||
842 | @@ -26,8 +25,6 @@ using namespace LAppDefine; | |
843 | LAppView::LAppView(): | |
844 | _programId(0), | |
845 | _back(NULL), | |
846 | - _gear(NULL), | |
847 | - _power(NULL), | |
848 | _renderSprite(NULL), | |
849 | _renderTarget(SelectTarget_None) | |
850 | { | |
851 | @@ -35,8 +32,6 @@ LAppView::LAppView(): | |
852 | _clearColor[1] = 1.0f; | |
853 | _clearColor[2] = 1.0f; | |
854 | _clearColor[3] = 0.0f; | |
855 | - // タッチ関係のイベント管理 | |
856 | - _touchManager = new TouchManager(); | |
857 | ||
858 | // デバイス座標からスクリーン座標に変換するための | |
859 | _deviceToScreen = new CubismMatrix44(); | |
860 | @@ -52,10 +47,7 @@ LAppView::~LAppView() | |
861 | ||
862 | delete _viewMatrix; | |
863 | delete _deviceToScreen; | |
864 | - delete _touchManager; | |
865 | delete _back; | |
866 | - delete _gear; | |
867 | - delete _power; | |
868 | } | |
869 | ||
870 | void LAppView::Initialize() | |
871 | @@ -97,9 +89,6 @@ void LAppView::Initialize() | |
872 | void LAppView::Render() | |
873 | { | |
874 | _back->Render(); | |
875 | - _gear->Render(); | |
876 | - _power->Render(); | |
877 | - | |
878 | ||
879 | LAppLive2DManager* Live2DManager = LAppLive2DManager::GetInstance(); | |
880 | ||
881 | @@ -139,35 +128,17 @@ void LAppView::InitializeSprite() | |
882 | glfwGetWindowSize(LAppDelegate::GetInstance()->GetWindow(), &width, &height); | |
883 | ||
884 | LAppTextureManager* textureManager = LAppDelegate::GetInstance()->GetTextureManager(); | |
885 | - const string resourcesPath = LAppDelegate::GetInstance()->GetRootDirectory() + ResourcesPath; | |
886 | ||
887 | - string imageName = BackImageName; | |
888 | - LAppTextureManager::TextureInfo* backgroundTexture = textureManager->CreateTextureFromPngFile(resourcesPath + imageName); | |
889 | + | |
890 | + LAppTextureManager::TextureInfo* backgroundTexture = | |
891 | + textureManager->CreateTextureFromColor(0, 255, 0); | |
892 | ||
893 | float x = width * 0.5f; | |
894 | float y = height * 0.5f; | |
895 | - float fWidth = static_cast<float>(backgroundTexture->width * 2.0f); | |
896 | - float fHeight = static_cast<float>(height) * 0.95f; | |
897 | + float fWidth = static_cast<float>(width); | |
898 | + float fHeight = static_cast<float>(height); | |
899 | _back = new LAppSprite(x, y, fWidth, fHeight, backgroundTexture->id, _programId); | |
900 | ||
901 | - imageName = GearImageName; | |
902 | - LAppTextureManager::TextureInfo* gearTexture = textureManager->CreateTextureFromPngFile(resourcesPath + imageName); | |
903 | - | |
904 | - x = static_cast<float>(width - gearTexture->width * 0.5f); | |
905 | - y = static_cast<float>(height - gearTexture->height * 0.5f); | |
906 | - fWidth = static_cast<float>(gearTexture->width); | |
907 | - fHeight = static_cast<float>(gearTexture->height); | |
908 | - _gear = new LAppSprite(x, y, fWidth, fHeight, gearTexture->id, _programId); | |
909 | - | |
910 | - imageName = PowerImageName; | |
911 | - LAppTextureManager::TextureInfo* powerTexture = textureManager->CreateTextureFromPngFile(resourcesPath + imageName); | |
912 | - | |
913 | - x = static_cast<float>(width - powerTexture->width * 0.5f); | |
914 | - y = static_cast<float>(powerTexture->height * 0.5f); | |
915 | - fWidth = static_cast<float>(powerTexture->width); | |
916 | - fHeight = static_cast<float>(powerTexture->height); | |
917 | - _power = new LAppSprite(x, y, fWidth, fHeight, powerTexture->id, _programId); | |
918 | - | |
919 | // 画面全体を覆うサイズ | |
920 | x = width * 0.5f; | |
921 | y = height * 0.5f; | |
922 | @@ -175,52 +146,6 @@ void LAppView::InitializeSprite() | |
923 | ||
924 | } | |
925 | ||
926 | -void LAppView::OnTouchesBegan(float px, float py) const | |
927 | -{ | |
928 | - _touchManager->TouchesBegan(px, py); | |
929 | -} | |
930 | - | |
931 | -void LAppView::OnTouchesMoved(float px, float py) const | |
932 | -{ | |
933 | - float viewX = this->TransformViewX(_touchManager->GetX()); | |
934 | - float viewY = this->TransformViewY(_touchManager->GetY()); | |
935 | - | |
936 | - _touchManager->TouchesMoved(px, py); | |
937 | - | |
938 | - LAppLive2DManager* Live2DManager = LAppLive2DManager::GetInstance(); | |
939 | - Live2DManager->OnDrag(viewX, viewY); | |
940 | -} | |
941 | - | |
942 | -void LAppView::OnTouchesEnded(float px, float py) const | |
943 | -{ | |
944 | - // タッチ終了 | |
945 | - LAppLive2DManager* live2DManager = LAppLive2DManager::GetInstance(); | |
946 | - live2DManager->OnDrag(0.0f, 0.0f); | |
947 | - { | |
948 | - | |
949 | - // シングルタップ | |
950 | - float x = _deviceToScreen->TransformX(_touchManager->GetX()); // 論理座標変換した座標を取得。 | |
951 | - float y = _deviceToScreen->TransformY(_touchManager->GetY()); // 論理座標変換した座標を取得。 | |
952 | - if (DebugTouchLogEnable) | |
953 | - { | |
954 | - LAppPal::PrintLog("[APP]touchesEnded x:%.2f y:%.2f", x, y); | |
955 | - } | |
956 | - live2DManager->OnTap(x, y); | |
957 | - | |
958 | - // 歯車にタップしたか | |
959 | - if (_gear->IsHit(px, py)) | |
960 | - { | |
961 | - live2DManager->NextScene(); | |
962 | - } | |
963 | - | |
964 | - // 電源ボタンにタップしたか | |
965 | - if (_power->IsHit(px, py)) | |
966 | - { | |
967 | - LAppDelegate::GetInstance()->AppEnd(); | |
968 | - } | |
969 | - } | |
970 | -} | |
971 | - | |
972 | float LAppView::TransformViewX(float deviceX) const | |
973 | { | |
974 | float screenX = _deviceToScreen->TransformX(deviceX); // 論理座標変換した座標を取得。 | |
975 | @@ -362,32 +287,4 @@ void LAppView::ResizeSprite() | |
976 | _back->ResetRect(x, y, fWidth, fHeight); | |
977 | } | |
978 | } | |
979 | - | |
980 | - if (_power) | |
981 | - { | |
982 | - GLuint id = _power->GetTextureId(); | |
983 | - LAppTextureManager::TextureInfo* texInfo = textureManager->GetTextureInfoById(id); | |
984 | - if (texInfo) | |
985 | - { | |
986 | - x = static_cast<float>(width - texInfo->width * 0.5f); | |
987 | - y = static_cast<float>(texInfo->height * 0.5f); | |
988 | - fWidth = static_cast<float>(texInfo->width); | |
989 | - fHeight = static_cast<float>(texInfo->height); | |
990 | - _power->ResetRect(x, y, fWidth, fHeight); | |
991 | - } | |
992 | - } | |
993 | - | |
994 | - if (_gear) | |
995 | - { | |
996 | - GLuint id = _gear->GetTextureId(); | |
997 | - LAppTextureManager::TextureInfo* texInfo = textureManager->GetTextureInfoById(id); | |
998 | - if (texInfo) | |
999 | - { | |
1000 | - x = static_cast<float>(width - texInfo->width * 0.5f); | |
1001 | - y = static_cast<float>(height - texInfo->height * 0.5f); | |
1002 | - fWidth = static_cast<float>(texInfo->width); | |
1003 | - fHeight = static_cast<float>(texInfo->height); | |
1004 | - _gear->ResetRect(x, y, fWidth, fHeight); | |
1005 | - } | |
1006 | - } | |
1007 | } | |
1008 | diff -pruN --exclude build ./demo_clean/src/LAppView.hpp ./demo_dev/src/LAppView.hpp | |
eba2eb3a | 1009 | --- ./demo_clean/src/LAppView.hpp 2020-10-01 22:47:25.846828066 +0100 |
126d8fa4 | 1010 | +++ ./demo_dev/src/LAppView.hpp 2020-10-01 22:47:24.802846999 +0100 |
830d0ba4 AIL |
1011 | @@ -14,7 +14,6 @@ |
1012 | #include "CubismFramework.hpp" | |
1013 | #include <Rendering/OpenGL/CubismOffscreenSurface_OpenGLES2.hpp> | |
1014 | ||
1015 | -class TouchManager; | |
1016 | class LAppSprite; | |
1017 | class LAppModel; | |
1018 | ||
1019 | @@ -66,30 +65,6 @@ public: | |
1020 | void ResizeSprite(); | |
1021 | ||
1022 | /** | |
1023 | - * @brief タッチされたときに呼ばれる。 | |
1024 | - * | |
1025 | - * @param[in] pointX スクリーンX座標 | |
1026 | - * @param[in] pointY スクリーンY座標 | |
1027 | - */ | |
1028 | - void OnTouchesBegan(float pointX, float pointY) const; | |
1029 | - | |
1030 | - /** | |
1031 | - * @brief タッチしているときにポインタが動いたら呼ばれる。 | |
1032 | - * | |
1033 | - * @param[in] pointX スクリーンX座標 | |
1034 | - * @param[in] pointY スクリーンY座標 | |
1035 | - */ | |
1036 | - void OnTouchesMoved(float pointX, float pointY) const; | |
1037 | - | |
1038 | - /** | |
1039 | - * @brief タッチが終了したら呼ばれる。 | |
1040 | - * | |
1041 | - * @param[in] pointX スクリーンX座標 | |
1042 | - * @param[in] pointY スクリーンY座標 | |
1043 | - */ | |
1044 | - void OnTouchesEnded(float pointX, float pointY) const; | |
1045 | - | |
1046 | - /** | |
1047 | * @brief X座標をView座標に変換する。 | |
1048 | * | |
1049 | * @param[in] deviceX デバイスX座標 | |
1050 | @@ -147,13 +122,10 @@ public: | |
1051 | void SetRenderTargetClearColor(float r, float g, float b); | |
1052 | ||
1053 | private: | |
1054 | - TouchManager* _touchManager; ///< タッチマネージャー | |
1055 | Csm::CubismMatrix44* _deviceToScreen; ///< デバイスからスクリーンへの行列 | |
1056 | Csm::CubismViewMatrix* _viewMatrix; ///< viewMatrix | |
1057 | GLuint _programId; ///< シェーダID | |
1058 | LAppSprite* _back; ///< 背景画像 | |
1059 | - LAppSprite* _gear; ///< ギア画像 | |
1060 | - LAppSprite* _power; ///< 電源画像 | |
1061 | ||
1062 | // レンダリング先を別ターゲットにする方式の場合に使用 | |
1063 | LAppSprite* _renderSprite; ///< モードによっては_renderBufferのテクスチャを描画 | |
1064 | diff -pruN --exclude build ./demo_clean/src/main.cpp ./demo_dev/src/main.cpp | |
eba2eb3a AIL |
1065 | --- ./demo_clean/src/main.cpp 2020-10-01 22:47:25.846828066 +0100 |
1066 | +++ ./demo_dev/src/main.cpp 2020-10-18 07:03:46.194220443 +0100 | |
1067 | @@ -5,18 +5,182 @@ | |
830d0ba4 AIL |
1068 | * that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html. |
1069 | */ | |
1070 | ||
1071 | +#include <thread> | |
1072 | +#include <stdexcept> | |
1073 | +#include <sstream> | |
eba2eb3a AIL |
1074 | +#include <vector> |
1075 | +#include <utility> | |
1076 | +#include <string> | |
830d0ba4 AIL |
1077 | + |
1078 | +#ifdef __cpp_lib_filesystem | |
1079 | +#include <filesystem> | |
1080 | +namespace fs = std::filesystem; | |
1081 | +#else | |
1082 | +#include <experimental/filesystem> | |
1083 | +namespace fs = std::experimental::filesystem; | |
1084 | +#endif | |
1085 | + | |
eba2eb3a | 1086 | +#include "ICubismModelSetting.hpp" |
830d0ba4 AIL |
1087 | #include "LAppDelegate.hpp" |
1088 | +#include "LAppLive2DManager.hpp" | |
eba2eb3a | 1089 | +#include "LAppModel.hpp" |
126d8fa4 | 1090 | +#include "mouse_cursor_tracker.h" |
830d0ba4 AIL |
1091 | + |
1092 | +struct CmdArgs | |
1093 | +{ | |
1094 | + int windowWidth; | |
1095 | + int windowHeight; | |
1096 | + std::string windowTitle; | |
1097 | + std::string rootDir; | |
1098 | + float scaleFactor; | |
1099 | + float translateX; | |
1100 | + float translateY; | |
1101 | + std::string modelName; | |
126d8fa4 | 1102 | + std::string cfgPath; // Path to config file for MouseCursorTracker |
830d0ba4 AIL |
1103 | +}; |
1104 | + | |
1105 | +CmdArgs parseArgv(int argc, char *argv[]) | |
1106 | +{ | |
1107 | + // I think the command-line args are simple enough to not justify using a library... | |
1108 | + CmdArgs cmdArgs; | |
1109 | + // Set default values | |
1110 | + cmdArgs.windowWidth = 600; | |
1111 | + cmdArgs.windowHeight = 600; | |
126d8fa4 | 1112 | + cmdArgs.windowTitle = "MouseTrackerForCubism example"; |
830d0ba4 AIL |
1113 | + cmdArgs.rootDir = fs::current_path(); |
1114 | + cmdArgs.scaleFactor = 8.0f; | |
1115 | + cmdArgs.translateX = 0.0f; | |
1116 | + cmdArgs.translateY = -2.8f; | |
1117 | + cmdArgs.modelName = "Haru"; | |
1118 | + cmdArgs.cfgPath = ""; | |
1119 | + | |
1120 | + int i = 1; | |
1121 | + while (i < argc) | |
1122 | + { | |
1123 | + std::string arg = argv[i]; | |
1124 | + std::stringstream ss; | |
1125 | + | |
1126 | + if (arg == "--window-width" || arg == "-W") // capital W for consistency with height | |
1127 | + { | |
1128 | + ss << argv[i + 1]; | |
1129 | + if (!(ss >> cmdArgs.windowWidth)) | |
1130 | + { | |
1131 | + throw std::runtime_error("Invalid argument for window width"); | |
1132 | + } | |
1133 | + } | |
1134 | + else if (arg == "--window-height" || arg == "-H") // avoiding "-h", typically for help | |
1135 | + { | |
1136 | + ss << argv[i + 1]; | |
1137 | + if (!(ss >> cmdArgs.windowHeight)) | |
1138 | + { | |
1139 | + throw std::runtime_error("Invalid argument for window height"); | |
1140 | + } | |
1141 | + } | |
1142 | + else if (arg == "--window-title" || arg == "-t") | |
1143 | + { | |
1144 | + cmdArgs.windowTitle = argv[i + 1]; | |
1145 | + } | |
1146 | + else if (arg == "--root-dir" || arg == "-d") | |
1147 | + { | |
1148 | + cmdArgs.rootDir = argv[i + 1]; | |
1149 | + } | |
1150 | + else if (arg == "--scale-factor" || arg == "-f") | |
1151 | + { | |
1152 | + ss << argv[i + 1]; | |
1153 | + if (!(ss >> cmdArgs.scaleFactor)) | |
1154 | + { | |
1155 | + throw std::runtime_error("Invalid argument for scale factor"); | |
1156 | + } | |
1157 | + } | |
1158 | + else if (arg == "--translate-x" || arg == "-x") | |
1159 | + { | |
1160 | + ss << argv[i + 1]; | |
1161 | + if (!(ss >> cmdArgs.translateX)) | |
1162 | + { | |
1163 | + throw std::runtime_error("Invalid argument for translate X"); | |
1164 | + } | |
1165 | + } | |
1166 | + else if (arg == "--translate-y" || arg == "-y") | |
1167 | + { | |
1168 | + ss << argv[i + 1]; | |
1169 | + if (!(ss >> cmdArgs.translateY)) | |
1170 | + { | |
1171 | + throw std::runtime_error("Invalid argument for translate Y"); | |
1172 | + } | |
1173 | + } | |
1174 | + else if (arg == "--model" || arg == "-m") | |
1175 | + { | |
1176 | + cmdArgs.modelName = argv[i + 1]; | |
1177 | + } | |
1178 | + else if (arg == "--config" || arg == "-c") | |
1179 | + { | |
1180 | + cmdArgs.cfgPath = argv[i + 1]; | |
1181 | + } | |
1182 | + else | |
1183 | + { | |
1184 | + throw std::runtime_error("Unrecognized argument: " + arg); | |
1185 | + } | |
1186 | + | |
1187 | + i += 2; | |
1188 | + } | |
1189 | + | |
1190 | + return cmdArgs; | |
1191 | +} | |
1192 | ||
1193 | int main(int argc, char* argv[]) | |
1194 | { | |
1195 | - // create the application instance | |
1196 | - if (LAppDelegate::GetInstance()->Initialize() == GL_FALSE) | |
1197 | + auto cmdArgs = parseArgv(argc, argv); | |
1198 | + | |
1199 | + LAppDelegate *delegate = LAppDelegate::GetInstance(); | |
1200 | + | |
1201 | + if (!delegate->Initialize(cmdArgs.windowWidth, | |
1202 | + cmdArgs.windowHeight, | |
1203 | + cmdArgs.windowTitle.c_str())) | |
1204 | { | |
1205 | - return 1; | |
1206 | + throw std::runtime_error("Unable to initialize LAppDelegate"); | |
1207 | } | |
1208 | ||
1209 | - LAppDelegate::GetInstance()->Run(); | |
1210 | + delegate->SetRootDirectory(cmdArgs.rootDir); | |
1211 | + | |
830d0ba4 AIL |
1212 | + LAppLive2DManager *manager = LAppLive2DManager::GetInstance(); |
1213 | + manager->SetModel(cmdArgs.modelName); | |
1214 | + | |
1215 | + manager->SetProjectionScaleTranslate(cmdArgs.scaleFactor, | |
1216 | + cmdArgs.translateX, | |
1217 | + cmdArgs.translateY); | |
eba2eb3a AIL |
1218 | + |
1219 | + LAppModel *model = manager->GetModel(0); | |
1220 | + if (!model) throw std::runtime_error("model is null"); | |
1221 | + | |
1222 | + Live2D::Cubism::Framework::ICubismModelSetting *modelSetting = model->GetModelSetting(); | |
1223 | + if (!modelSetting) throw std::runtime_error("modelSetting is null"); | |
1224 | + | |
1225 | + std::vector<std::pair<std::string, int> > motions; | |
1226 | + int motionGroupCount = modelSetting->GetMotionGroupCount(); | |
1227 | + for (int i = 0; i < motionGroupCount; i++) | |
1228 | + { | |
1229 | + const char *motionGroup = modelSetting->GetMotionGroupName(i); | |
1230 | + int motionCount = modelSetting->GetMotionCount(motionGroup); | |
1231 | + motions.push_back(std::make_pair(std::string(motionGroup), motionCount)); | |
1232 | + } | |
1233 | + | |
1234 | + std::vector<std::string> expressions; | |
1235 | + int expCount = modelSetting->GetExpressionCount(); | |
1236 | + for (int i = 0; i < expCount; i++) | |
1237 | + { | |
1238 | + const char *expName = modelSetting->GetExpressionName(i); | |
1239 | + expressions.push_back(std::string(expName)); | |
1240 | + } | |
1241 | + | |
1242 | + MouseCursorTracker tracker(cmdArgs.cfgPath, motions, expressions); | |
1243 | + | |
1244 | + std::thread trackerThread(&MouseCursorTracker::mainLoop, &tracker); | |
126d8fa4 | 1245 | + manager->SetTracker(&tracker); |
830d0ba4 AIL |
1246 | + |
1247 | + delegate->Run(); | |
1248 | + | |
126d8fa4 AIL |
1249 | + tracker.stop(); |
1250 | + trackerThread.join(); | |
830d0ba4 AIL |
1251 | |
1252 | return 0; | |
1253 | } | |
1254 | - |