/* * Copyright (c) 2016-2016 Irlan Robson http://www.irlan.net * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages * arising from the use of this software. * Permission is granted to anyone to use this software for any purpose, * including commercial applications, and to alter it and redistribute it * freely, subject to the following restrictions: * 1. The origin of this software must not be misrepresented; you must not * claim that you wrote the original software. If you use this software * in a product, an acknowledgment in the product documentation would be * appreciated but is not required. * 2. Altered source versions must be plainly marked as such, and must not be * misrepresented as being the original software. * 3. This notice may not be removed or altered from any source distribution. */ #ifndef MODEL_H #define MODEL_H #include #include #include struct Settings { Settings() { lastTestID = -1; testID = 0; pause = false; singleStep = false; drawPoints = true; drawLines = true; drawTriangles = true; drawGrid = true; drawProfile = false; drawStats = false; } int lastTestID; int testID; bool pause; bool singleStep; bool drawPoints; bool drawLines; bool drawTriangles; bool drawGrid; bool drawProfile; bool drawStats; }; // extern Settings* g_settings; class Model { public: Model(); ~Model(); void Action_SaveTest(); void Action_SelectTest(int selection); void Action_RestartTest(); void Action_PreviousTest(); void Action_NextTest(); void Action_PlayPause(); void Action_SingleStep(); void Action_DefaultCamera(); void Action_LeftCamera(); void Action_RightCamera(); void Action_BottomCamera(); void Action_TopCamera(); void Action_BackCamera(); void Action_FrontCamera(); void Command_Step(); void Command_Press_Key(int button); void Command_Release_Key(int button); void Command_Press_Mouse_Left(const b3Vec2& ps); void Command_Release_Mouse_Left(const b3Vec2& ps); void Command_Move_Cursor(const b3Vec2& ps); void Command_ResizeCamera(float32 w, float32 h); void Command_RotateCameraX(float32 angle); void Command_RotateCameraY(float32 angle); void Command_TranslateCameraX(float32 d); void Command_TranslateCameraY(float32 d); void Command_ZoomCamera(float32 d); private: friend class View; friend class Controller; // UI State Settings m_settings; TestSettings m_testSettings; // App State Draw m_draw; Camera m_camera; Profiler m_profiler; TestbedListener m_profilerListener; Test* m_test; }; inline void Model::Action_SelectTest(int selection) { m_settings.testID = selection; m_settings.lastTestID = -1; } inline void Model::Action_RestartTest() { m_settings.lastTestID = -1; } inline void Model::Action_PreviousTest() { m_settings.testID = b3Clamp(m_settings.testID - 1, 0, int(g_testCount) - 1); m_settings.lastTestID = -1; } inline void Model::Action_NextTest() { m_settings.testID = b3Clamp(m_settings.testID + 1, 0, int(g_testCount) - 1); m_settings.lastTestID = -1; } inline void Model::Action_SaveTest() { m_test->Save(); } inline void Model::Action_PlayPause() { m_settings.pause = !m_settings.pause; } inline void Model::Action_SingleStep() { m_settings.pause = true; m_settings.singleStep = true; } inline void Model::Action_DefaultCamera() { m_camera.m_q = b3QuatRotationX(-0.125f * B3_PI); b3Quat d = b3QuatRotationY(0.125f * B3_PI); m_camera.m_q = d * m_camera.m_q; m_camera.m_q.Normalize(); m_camera.m_center.SetZero(); m_camera.m_zoom = 50.0f; } inline void Model::Action_LeftCamera() { m_camera.m_q = b3QuatRotationX(0.5f * B3_PI); m_camera.m_center.SetZero(); m_camera.m_zoom = 50.0f; } inline void Model::Action_RightCamera() { m_camera.m_q = b3QuatRotationX(-0.5f * B3_PI); m_camera.m_center.SetZero(); m_camera.m_zoom = 50.0f; } inline void Model::Action_BottomCamera() { m_camera.m_q = b3QuatRotationX(0.5f * B3_PI); m_camera.m_center.SetZero(); m_camera.m_zoom = 50.0f; } inline void Model::Action_TopCamera() { m_camera.m_q = b3QuatRotationX(-0.5f * B3_PI); m_camera.m_center.SetZero(); m_camera.m_zoom = 50.0f; } inline void Model::Action_BackCamera() { m_camera.m_q = b3QuatRotationX(-B3_PI); m_camera.m_center.SetZero(); m_camera.m_zoom = 50.0f; } inline void Model::Action_FrontCamera() { m_camera.m_q.SetIdentity(); m_camera.m_center.SetZero(); m_camera.m_zoom = 50.0f; } inline void Model::Command_Press_Key(int button) { m_test->KeyDown(button); } inline void Model::Command_Release_Key(int button) { m_test->KeyUp(button); } inline void Model::Command_Press_Mouse_Left(const b3Vec2& ps) { Ray3 pw = m_camera.ConvertScreenToWorld(ps); m_test->MouseLeftDown(pw); } inline void Model::Command_Release_Mouse_Left(const b3Vec2& ps) { Ray3 pw = m_camera.ConvertScreenToWorld(ps); m_test->MouseLeftUp(pw); } inline void Model::Command_Move_Cursor(const b3Vec2& ps) { Ray3 pw = m_camera.ConvertScreenToWorld(ps); m_test->MouseMove(pw); } inline void Model::Command_ResizeCamera(float32 w, float32 h) { m_camera.m_width = w; m_camera.m_height = h; } inline void Model::Command_RotateCameraX(float32 angle) { b3Quat d = b3QuatRotationX(angle); m_camera.m_q = m_camera.m_q * d; m_camera.m_q.Normalize(); } inline void Model::Command_RotateCameraY(float32 angle) { b3Quat d = b3QuatRotationY(angle); m_camera.m_q = d * m_camera.m_q; m_camera.m_q.Normalize(); } inline void Model::Command_TranslateCameraX(float32 d) { b3Transform transform = m_camera.BuildWorldTransform(); m_camera.m_center += d * transform.rotation.x; } inline void Model::Command_TranslateCameraY(float32 d) { b3Transform transform = m_camera.BuildWorldTransform(); m_camera.m_center += d * transform.rotation.y; } inline void Model::Command_ZoomCamera(float32 d) { m_camera.m_zoom += d; } #endif