From 09abf1b529b4226f585ecfbb20866715b901755b Mon Sep 17 00:00:00 2001 From: chai Date: Wed, 1 Dec 2021 13:34:22 +0800 Subject: +fpm --- Client/Source/PND/Animation/Animation.h | 0 Client/Source/PND/Common/Type.h | 10 +- Client/Source/PND/GameCode/Component.cpp | 0 Client/Source/PND/GameCode/Component.h | 0 .../PND/GameCode/Components/MovementComponent.h | 0 Client/Source/PND/GameCode/Entity.cpp | 0 Client/Source/PND/GameCode/Entity.h | 21 ++ Client/Source/PND/Math/Vector2.h | 15 ++ Client/Source/PND/main.cpp | 12 +- Client/Source/Phy2D/Common/Settings.h | 52 ++-- Client/Source/Phy2D/Dynamic/Arbiter.cpp | 14 +- Client/Source/Phy2D/Dynamic/Arbiter.h | 2 +- Client/Source/Phy2D/Dynamic/Body.cpp | 2 +- Client/Source/Phy2D/Dynamic/Body.h | 6 +- Client/Source/Phy2D/Dynamic/Collide.cpp | 12 +- Client/Source/Phy2D/Dynamic/Joint.cpp | 14 +- Client/Source/Phy2D/Dynamic/Joint.h | 8 +- Client/Source/Phy2D/Dynamic/World.cpp | 16 +- Client/Source/Phy2D/Dynamic/World.h | 24 +- Client/Source/Phy2D/Phy2D.h | 16 +- Client/Source/Phy2D/Rendering/Visualize.h | 8 +- Client/Source/Phy2D/Shapes/p2CircleShape.h | 16 +- Client/Source/Phy2D/Shapes/p2Shape.h | 14 +- Client/Source/Phy2D/Tests/test.h | 12 +- Client/Source/Phy2D/Tests/test_math.cpp | 44 ++-- Client/Source/Phy2D/Tests/test_p2d.cpp | 272 ++++++++++----------- Client/Source/Phy2DLite/Arbiter.cpp | 14 +- Client/Source/Phy2DLite/Arbiter.h | 2 +- Client/Source/Phy2DLite/Body.cpp | 2 +- Client/Source/Phy2DLite/Body.h | 6 +- Client/Source/Phy2DLite/Collide.cpp | 12 +- Client/Source/Phy2DLite/Joint.cpp | 14 +- Client/Source/Phy2DLite/Joint.h | 8 +- Client/Source/Phy2DLite/Phy2D.h | 16 +- Client/Source/Phy2DLite/Settings.h | 77 ++++-- Client/Source/Phy2DLite/Tests/test.h | 12 +- Client/Source/Phy2DLite/Tests/test_math.cpp | 44 ++-- Client/Source/Phy2DLite/Tests/test_p2d.cpp | 272 ++++++++++----------- Client/Source/Phy2DLite/World.cpp | 16 +- Client/Source/Phy2DLite/World.h | 24 +- Client/Source/fixedpoint/test_basic.c | 12 +- 41 files changed, 592 insertions(+), 529 deletions(-) create mode 100644 Client/Source/PND/Animation/Animation.h create mode 100644 Client/Source/PND/GameCode/Component.cpp create mode 100644 Client/Source/PND/GameCode/Component.h create mode 100644 Client/Source/PND/GameCode/Components/MovementComponent.h create mode 100644 Client/Source/PND/GameCode/Entity.cpp create mode 100644 Client/Source/PND/GameCode/Entity.h create mode 100644 Client/Source/PND/Math/Vector2.h (limited to 'Client/Source') diff --git a/Client/Source/PND/Animation/Animation.h b/Client/Source/PND/Animation/Animation.h new file mode 100644 index 0000000..e69de29 diff --git a/Client/Source/PND/Common/Type.h b/Client/Source/PND/Common/Type.h index 250405b..4033ab1 100644 --- a/Client/Source/PND/Common/Type.h +++ b/Client/Source/PND/Common/Type.h @@ -1,3 +1,7 @@ -#pragma once - -typedef float fixed; +#pragma once + +#include "libfixmath/libfixmath/fix16.h" + +typedef fix16_t fixed16; // Q16.16 + +typedef fixed16 fixed; diff --git a/Client/Source/PND/GameCode/Component.cpp b/Client/Source/PND/GameCode/Component.cpp new file mode 100644 index 0000000..e69de29 diff --git a/Client/Source/PND/GameCode/Component.h b/Client/Source/PND/GameCode/Component.h new file mode 100644 index 0000000..e69de29 diff --git a/Client/Source/PND/GameCode/Components/MovementComponent.h b/Client/Source/PND/GameCode/Components/MovementComponent.h new file mode 100644 index 0000000..e69de29 diff --git a/Client/Source/PND/GameCode/Entity.cpp b/Client/Source/PND/GameCode/Entity.cpp new file mode 100644 index 0000000..e69de29 diff --git a/Client/Source/PND/GameCode/Entity.h b/Client/Source/PND/GameCode/Entity.h new file mode 100644 index 0000000..df92bed --- /dev/null +++ b/Client/Source/PND/GameCode/Entity.h @@ -0,0 +1,21 @@ +#pragma once + +#include +#include + +#include "../Common/Type.h" + +class Component; + +// 游戏对象 +class Entity +{ +public: + + +private: + std::vector< Component*> m_Components; + + int m_ID; + +}; diff --git a/Client/Source/PND/Math/Vector2.h b/Client/Source/PND/Math/Vector2.h new file mode 100644 index 0000000..51c9f40 --- /dev/null +++ b/Client/Source/PND/Math/Vector2.h @@ -0,0 +1,15 @@ +#pragma once + + +#include +#include + +#include "../Common/Type.h" + + +class Vector2 +{ +public: + fixed x, y; + +}; diff --git a/Client/Source/PND/main.cpp b/Client/Source/PND/main.cpp index 8d0f257..f6bb3d7 100644 --- a/Client/Source/PND/main.cpp +++ b/Client/Source/PND/main.cpp @@ -1,7 +1,7 @@ - - -int main() -{ - - return 0; + + +int main() +{ + + return 0; } \ No newline at end of file diff --git a/Client/Source/Phy2D/Common/Settings.h b/Client/Source/Phy2D/Common/Settings.h index 5f7237f..5c24b57 100644 --- a/Client/Source/Phy2D/Common/Settings.h +++ b/Client/Source/Phy2D/Common/Settings.h @@ -1,27 +1,27 @@ -#pragma once - -#include "libfixmath/libfixmath/fixmath.h" - -namespace Phy2D -{ - -#define NUMBER_FLOAT false - -#if NUMBER_FLOAT -typedef float number; -#define NUMBER_MAX (FLT_MAX) -#define NUMBER_MIN (FLT_MIN) -#define SQRT(a) (sqrt((a))) -#define SIN(a) (sin((a))) -#define COS(a) (cos((a))) -#else -// 同时一定要开启内联函数扩展,否则执行效率会非常低 -typedef Fix16 number; -#define NUMBER_MAX (fix16_maximum) -#define NUMBER_MIN (fix16_minimum) -#define SQRT(a) ((a).sqrt()) -#define SIN(a) ((a).sin()) -#define COS(a) ((a).cos()) -#endif - +#pragma once + +#include "libfixmath/libfixmath/fixmath.h" + +namespace Phy2D +{ + +#define NUMBER_FLOAT false + +#if NUMBER_FLOAT +typedef float number; +#define NUMBER_MAX (FLT_MAX) +#define NUMBER_MIN (FLT_MIN) +#define SQRT(a) (sqrt((a))) +#define SIN(a) (sin((a))) +#define COS(a) (cos((a))) +#else +// 同时一定要开启内联函数扩展,否则执行效率会非常低 +typedef Fix16 number; +#define NUMBER_MAX (fix16_maximum) +#define NUMBER_MIN (fix16_minimum) +#define SQRT(a) ((a).sqrt()) +#define SIN(a) ((a).sin()) +#define COS(a) ((a).cos()) +#endif + } \ No newline at end of file diff --git a/Client/Source/Phy2D/Dynamic/Arbiter.cpp b/Client/Source/Phy2D/Dynamic/Arbiter.cpp index 11288a3..4163154 100644 --- a/Client/Source/Phy2D/Dynamic/Arbiter.cpp +++ b/Client/Source/Phy2D/Dynamic/Arbiter.cpp @@ -1,10 +1,10 @@ -#include "Arbiter.h" -#include "World.h" -#include "Body.h" -#include "Joint.h" - -using namespace Phy2D; - +#include "Arbiter.h" +#include "World.h" +#include "Body.h" +#include "Joint.h" + +using namespace Phy2D; + Arbiter::Arbiter(Body* b1, Body* b2) { if (b1 < b2) diff --git a/Client/Source/Phy2D/Dynamic/Arbiter.h b/Client/Source/Phy2D/Dynamic/Arbiter.h index b02b413..64bed72 100644 --- a/Client/Source/Phy2D/Dynamic/Arbiter.h +++ b/Client/Source/Phy2D/Dynamic/Arbiter.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include "../Common/Math.h" diff --git a/Client/Source/Phy2D/Dynamic/Body.cpp b/Client/Source/Phy2D/Dynamic/Body.cpp index 73bafe2..1d896fd 100644 --- a/Client/Source/Phy2D/Dynamic/Body.cpp +++ b/Client/Source/Phy2D/Dynamic/Body.cpp @@ -1,4 +1,4 @@ -#include "Body.h" +#include "Body.h" using namespace Phy2D; diff --git a/Client/Source/Phy2D/Dynamic/Body.h b/Client/Source/Phy2D/Dynamic/Body.h index 6d86e07..8c2ac72 100644 --- a/Client/Source/Phy2D/Dynamic/Body.h +++ b/Client/Source/Phy2D/Dynamic/Body.h @@ -1,6 +1,6 @@ -#pragma once - -#include "../Common/Math.h" +#pragma once + +#include "../Common/Math.h" namespace Phy2D { diff --git a/Client/Source/Phy2D/Dynamic/Collide.cpp b/Client/Source/Phy2D/Dynamic/Collide.cpp index 647147a..6849c0e 100644 --- a/Client/Source/Phy2D/Dynamic/Collide.cpp +++ b/Client/Source/Phy2D/Dynamic/Collide.cpp @@ -1,9 +1,9 @@ -#include "Arbiter.h" -#include "Body.h" -#include "World.h" -#include "Joint.h" - -using namespace Phy2D; +#include "Arbiter.h" +#include "Body.h" +#include "World.h" +#include "Joint.h" + +using namespace Phy2D; // Box vertex and edge numbering: // diff --git a/Client/Source/Phy2D/Dynamic/Joint.cpp b/Client/Source/Phy2D/Dynamic/Joint.cpp index e0d10f9..95f7c64 100644 --- a/Client/Source/Phy2D/Dynamic/Joint.cpp +++ b/Client/Source/Phy2D/Dynamic/Joint.cpp @@ -1,8 +1,8 @@ -#include "Joint.h" -#include "Body.h" -#include "World.h" - -using namespace Phy2D; +#include "Joint.h" +#include "Body.h" +#include "World.h" + +using namespace Phy2D; void Joint::Set(Body* b1, Body* b2, const Vec2& anchor) { @@ -98,5 +98,5 @@ void Joint::ApplyImpulse() P += impulse; } - - + + diff --git a/Client/Source/Phy2D/Dynamic/Joint.h b/Client/Source/Phy2D/Dynamic/Joint.h index 34d8d8d..ee08b40 100644 --- a/Client/Source/Phy2D/Dynamic/Joint.h +++ b/Client/Source/Phy2D/Dynamic/Joint.h @@ -1,6 +1,6 @@ -#pragma once - -#include "../Common/Math.h" +#pragma once + +#include "../Common/Math.h" namespace Phy2D { @@ -31,4 +31,4 @@ namespace Phy2D number softness; }; -} +} diff --git a/Client/Source/Phy2D/Dynamic/World.cpp b/Client/Source/Phy2D/Dynamic/World.cpp index 6b0174c..4f48b69 100644 --- a/Client/Source/Phy2D/Dynamic/World.cpp +++ b/Client/Source/Phy2D/Dynamic/World.cpp @@ -1,10 +1,10 @@ -#include "World.h" -#include "Body.h" -#include "Joint.h" -#include "Arbiter.h" - -using namespace Phy2D; - +#include "World.h" +#include "Body.h" +#include "Joint.h" +#include "Arbiter.h" + +using namespace Phy2D; + using std::vector; using std::map; @@ -126,4 +126,4 @@ void World::Step(number dt) b->force.Set(0.0f, 0.0f); b->torque = 0.0f; } -} +} diff --git a/Client/Source/Phy2D/Dynamic/World.h b/Client/Source/Phy2D/Dynamic/World.h index d5c652c..93c883d 100644 --- a/Client/Source/Phy2D/Dynamic/World.h +++ b/Client/Source/Phy2D/Dynamic/World.h @@ -1,12 +1,12 @@ -#pragma once - -#include -#include -#include "../Common/Math.h" -#include "Arbiter.h" - -namespace Phy2D -{ +#pragma once + +#include +#include +#include "../Common/Math.h" +#include "Arbiter.h" + +namespace Phy2D +{ struct Body; struct Joint; @@ -31,6 +31,6 @@ namespace Phy2D static bool accumulateImpulses; static bool warmStarting; static bool positionCorrection; - }; - -} + }; + +} diff --git a/Client/Source/Phy2D/Phy2D.h b/Client/Source/Phy2D/Phy2D.h index 48d2824..d2e97f8 100644 --- a/Client/Source/Phy2D/Phy2D.h +++ b/Client/Source/Phy2D/Phy2D.h @@ -1,8 +1,8 @@ -#pragma once - - -// 定点数的物理引擎 - -#include "Dynamic/World.h" -#include "Dynamic/Body.h" -#include "Dynamic/Joint.h" +#pragma once + + +// 定点数的物理引擎 + +#include "Dynamic/World.h" +#include "Dynamic/Body.h" +#include "Dynamic/Joint.h" diff --git a/Client/Source/Phy2D/Rendering/Visualize.h b/Client/Source/Phy2D/Rendering/Visualize.h index 70aae79..679422d 100644 --- a/Client/Source/Phy2D/Rendering/Visualize.h +++ b/Client/Source/Phy2D/Rendering/Visualize.h @@ -1,4 +1,4 @@ -#pragma once - -#include "glad/glad.h" - +#pragma once + +#include "glad/glad.h" + diff --git a/Client/Source/Phy2D/Shapes/p2CircleShape.h b/Client/Source/Phy2D/Shapes/p2CircleShape.h index ded0396..a13a6ab 100644 --- a/Client/Source/Phy2D/Shapes/p2CircleShape.h +++ b/Client/Source/Phy2D/Shapes/p2CircleShape.h @@ -1,8 +1,8 @@ -#pragma once - -#include "p2Shape.h" - -class p2CircleShape : public p2Shape -{ - -}; +#pragma once + +#include "p2Shape.h" + +class p2CircleShape : public p2Shape +{ + +}; diff --git a/Client/Source/Phy2D/Shapes/p2Shape.h b/Client/Source/Phy2D/Shapes/p2Shape.h index 79a98f0..4546314 100644 --- a/Client/Source/Phy2D/Shapes/p2Shape.h +++ b/Client/Source/Phy2D/Shapes/p2Shape.h @@ -1,7 +1,7 @@ -#pragma once - -class p2Shape -{ - -}; - +#pragma once + +class p2Shape +{ + +}; + diff --git a/Client/Source/Phy2D/Tests/test.h b/Client/Source/Phy2D/Tests/test.h index c73a192..c814e3f 100644 --- a/Client/Source/Phy2D/Tests/test.h +++ b/Client/Source/Phy2D/Tests/test.h @@ -1,6 +1,6 @@ -#pragma once - -#define TEST_MATH 1 -#define TEST_P2D 2 - -#define TEST TEST_P2D +#pragma once + +#define TEST_MATH 1 +#define TEST_P2D 2 + +#define TEST TEST_P2D diff --git a/Client/Source/Phy2D/Tests/test_math.cpp b/Client/Source/Phy2D/Tests/test_math.cpp index e047508..e7642c1 100644 --- a/Client/Source/Phy2D/Tests/test_math.cpp +++ b/Client/Source/Phy2D/Tests/test_math.cpp @@ -1,23 +1,23 @@ -#include "test.h" -#if TEST == TEST_MATH - -#include - -#include "../Common/Math.h" - -using namespace Phy2D; -using namespace std; - -int main(int argc, char **argv) -{ - Vec2 a = Vec2(1.f, 2.f); - Vec2 b = a; - - cout << (a+b).ToString(); - - getchar(); - - return 0; -} - +#include "test.h" +#if TEST == TEST_MATH + +#include + +#include "../Common/Math.h" + +using namespace Phy2D; +using namespace std; + +int main(int argc, char **argv) +{ + Vec2 a = Vec2(1.f, 2.f); + Vec2 b = a; + + cout << (a+b).ToString(); + + getchar(); + + return 0; +} + #endif \ No newline at end of file diff --git a/Client/Source/Phy2D/Tests/test_p2d.cpp b/Client/Source/Phy2D/Tests/test_p2d.cpp index ff040c5..9050ccd 100644 --- a/Client/Source/Phy2D/Tests/test_p2d.cpp +++ b/Client/Source/Phy2D/Tests/test_p2d.cpp @@ -1,20 +1,20 @@ -#include "test.h" -#if TEST == TEST_P2D - -#include "libfixmath/libfixmath/fixmath.h" -#include -#include -#include -#include "SDL2/SDL.h" -#include "../Rendering/Visualize.h" -#include "imgui/imgui.h" -#include "imgui/backends/imgui_impl_opengl2.h" -#include "imgui/backends/imgui_impl_sdl.h" - -#include "../Phy2D.h" - -using namespace std; -using namespace Phy2D; +#include "test.h" +#if TEST == TEST_P2D + +#include "libfixmath/libfixmath/fixmath.h" +#include +#include +#include +#include "SDL2/SDL.h" +#include "../Rendering/Visualize.h" +#include "imgui/imgui.h" +#include "imgui/backends/imgui_impl_opengl2.h" +#include "imgui/backends/imgui_impl_sdl.h" + +#include "../Phy2D.h" + +using namespace std; +using namespace Phy2D; namespace { @@ -464,72 +464,72 @@ static void InitDemo() demoIndex = 0; Demo5(bodies, joints); } - -int main(int argc, char **argv) { - - // Setup SDL - // (Some versions of SDL before <2.0.10 appears to have performance/stalling issues on a minority of Windows systems, - // depending on whether SDL_INIT_GAMECONTROLLER is enabled or disabled.. updating to latest version of SDL is recommended!) - if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0) - { - printf("Error: %s\n", SDL_GetError()); - return -1; - } - - // Setup window - SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); - SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); - SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2); - SDL_WindowFlags window_flags = (SDL_WindowFlags)(SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI); - SDL_Window* window = SDL_CreateWindow("Phy2D", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, window_flags); - SDL_GLContext gl_context = SDL_GL_CreateContext(window); - - if (!gladLoadGLLoader((GLADloadproc)SDL_GL_GetProcAddress)) { - std::cerr << "Failed to initialize the OpenGL context." << std::endl; - exit(1); - } - - SDL_GL_MakeCurrent(window, gl_context); - SDL_GL_SetSwapInterval(1); // Enable vsync - - // Setup Dear ImGui context - IMGUI_CHECKVERSION(); - ImGui::CreateContext(); - ImGuiIO& io = ImGui::GetIO(); (void)io; - //io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls - //io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls - - // Setup Dear ImGui style - ImGui::StyleColorsDark(); - //ImGui::StyleColorsClassic(); - - // Setup Platform/Renderer backends - ImGui_ImplSDL2_InitForOpenGL(window, gl_context); - ImGui_ImplOpenGL2_Init(); - - // Load Fonts - // - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use ImGui::PushFont()/PopFont() to select them. - // - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple. - // - If the file cannot be loaded, the function will return NULL. Please handle those errors in your application (e.g. use an assertion, or display an error and quit). - // - The fonts will be rasterized at a given size (w/ oversampling) and stored into a texture when calling ImFontAtlas::Build()/GetTexDataAsXXXX(), which ImGui_ImplXXXX_NewFrame below will call. - // - Read 'docs/FONTS.md' for more instructions and details. - // - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ ! - //io.Fonts->AddFontDefault(); - //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf", 16.0f); - //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Cousine-Regular.ttf", 15.0f); - //io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf", 16.0f); - //io.Fonts->AddFontFromFileTTF("../../misc/fonts/ProggyTiny.ttf", 10.0f); - //ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese()); - //IM_ASSERT(font != NULL); - - // Our state - bool show_demo_window = true; - bool show_another_window = false; - ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); - - glViewport(0, 0, (int)io.DisplaySize.x, (int)io.DisplaySize.y); + +int main(int argc, char **argv) { + + // Setup SDL + // (Some versions of SDL before <2.0.10 appears to have performance/stalling issues on a minority of Windows systems, + // depending on whether SDL_INIT_GAMECONTROLLER is enabled or disabled.. updating to latest version of SDL is recommended!) + if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0) + { + printf("Error: %s\n", SDL_GetError()); + return -1; + } + + // Setup window + SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); + SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); + SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2); + SDL_WindowFlags window_flags = (SDL_WindowFlags)(SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI); + SDL_Window* window = SDL_CreateWindow("Phy2D", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, window_flags); + SDL_GLContext gl_context = SDL_GL_CreateContext(window); + + if (!gladLoadGLLoader((GLADloadproc)SDL_GL_GetProcAddress)) { + std::cerr << "Failed to initialize the OpenGL context." << std::endl; + exit(1); + } + + SDL_GL_MakeCurrent(window, gl_context); + SDL_GL_SetSwapInterval(1); // Enable vsync + + // Setup Dear ImGui context + IMGUI_CHECKVERSION(); + ImGui::CreateContext(); + ImGuiIO& io = ImGui::GetIO(); (void)io; + //io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls + //io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls + + // Setup Dear ImGui style + ImGui::StyleColorsDark(); + //ImGui::StyleColorsClassic(); + + // Setup Platform/Renderer backends + ImGui_ImplSDL2_InitForOpenGL(window, gl_context); + ImGui_ImplOpenGL2_Init(); + + // Load Fonts + // - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use ImGui::PushFont()/PopFont() to select them. + // - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple. + // - If the file cannot be loaded, the function will return NULL. Please handle those errors in your application (e.g. use an assertion, or display an error and quit). + // - The fonts will be rasterized at a given size (w/ oversampling) and stored into a texture when calling ImFontAtlas::Build()/GetTexDataAsXXXX(), which ImGui_ImplXXXX_NewFrame below will call. + // - Read 'docs/FONTS.md' for more instructions and details. + // - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ ! + //io.Fonts->AddFontDefault(); + //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf", 16.0f); + //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Cousine-Regular.ttf", 15.0f); + //io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf", 16.0f); + //io.Fonts->AddFontFromFileTTF("../../misc/fonts/ProggyTiny.ttf", 10.0f); + //ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese()); + //IM_ASSERT(font != NULL); + + // Our state + bool show_demo_window = true; + bool show_another_window = false; + ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); + + glViewport(0, 0, (int)io.DisplaySize.x, (int)io.DisplaySize.y); glMatrixMode(GL_PROJECTION); glLoadIdentity(); @@ -543,41 +543,41 @@ int main(int argc, char **argv) { { // aspect < 1, set the width to -1 to 1, with larger height glOrtho(-zoom, zoom, -zoom / aspect + pan_y, zoom / aspect + pan_y, -1.0, 1.0); - } - - InitDemo(); - - // Main loop - bool done = false; - while (!done) - { - //glClearColor(clear_color.x * clear_color.w, clear_color.y * clear_color.w, clear_color.z * clear_color.w, clear_color.w); - glClearColor(0, 0, 0, 0); - glClear(GL_COLOR_BUFFER_BIT); - - // Poll and handle events (inputs, window resize, etc.) - // You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs. - // - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application. - // - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application. - // Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags. - SDL_Event event; - while (SDL_PollEvent(&event)) - { - ImGui_ImplSDL2_ProcessEvent(&event); - if (event.type == SDL_QUIT) - done = true; - if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_CLOSE && event.window.windowID == SDL_GetWindowID(window)) - done = true; - } - - // Start the Dear ImGui frame - ImGui_ImplOpenGL2_NewFrame(); - ImGui_ImplSDL2_NewFrame(); - ImGui::NewFrame(); - - // Rendering - ImGui::Render(); - + } + + InitDemo(); + + // Main loop + bool done = false; + while (!done) + { + //glClearColor(clear_color.x * clear_color.w, clear_color.y * clear_color.w, clear_color.z * clear_color.w, clear_color.w); + glClearColor(0, 0, 0, 0); + glClear(GL_COLOR_BUFFER_BIT); + + // Poll and handle events (inputs, window resize, etc.) + // You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs. + // - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application. + // - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application. + // Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags. + SDL_Event event; + while (SDL_PollEvent(&event)) + { + ImGui_ImplSDL2_ProcessEvent(&event); + if (event.type == SDL_QUIT) + done = true; + if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_CLOSE && event.window.windowID == SDL_GetWindowID(window)) + done = true; + } + + // Start the Dear ImGui frame + ImGui_ImplOpenGL2_NewFrame(); + ImGui_ImplSDL2_NewFrame(); + ImGui::NewFrame(); + + // Rendering + ImGui::Render(); + glMatrixMode(GL_MODELVIEW); glLoadIdentity(); @@ -604,22 +604,22 @@ int main(int argc, char **argv) { } glEnd(); glPointSize(1.0f); - - //glUseProgram(0); // You may want this if using this code in an OpenGL 3+ context where shaders may be bound - ImGui_ImplOpenGL2_RenderDrawData(ImGui::GetDrawData()); - SDL_GL_SwapWindow(window); - } - - // Cleanup - ImGui_ImplOpenGL2_Shutdown(); - ImGui_ImplSDL2_Shutdown(); - ImGui::DestroyContext(); - - SDL_GL_DeleteContext(gl_context); - SDL_DestroyWindow(window); - SDL_Quit(); - - return 0; -} - + + //glUseProgram(0); // You may want this if using this code in an OpenGL 3+ context where shaders may be bound + ImGui_ImplOpenGL2_RenderDrawData(ImGui::GetDrawData()); + SDL_GL_SwapWindow(window); + } + + // Cleanup + ImGui_ImplOpenGL2_Shutdown(); + ImGui_ImplSDL2_Shutdown(); + ImGui::DestroyContext(); + + SDL_GL_DeleteContext(gl_context); + SDL_DestroyWindow(window); + SDL_Quit(); + + return 0; +} + #endif \ No newline at end of file diff --git a/Client/Source/Phy2DLite/Arbiter.cpp b/Client/Source/Phy2DLite/Arbiter.cpp index 11288a3..4163154 100644 --- a/Client/Source/Phy2DLite/Arbiter.cpp +++ b/Client/Source/Phy2DLite/Arbiter.cpp @@ -1,10 +1,10 @@ -#include "Arbiter.h" -#include "World.h" -#include "Body.h" -#include "Joint.h" - -using namespace Phy2D; - +#include "Arbiter.h" +#include "World.h" +#include "Body.h" +#include "Joint.h" + +using namespace Phy2D; + Arbiter::Arbiter(Body* b1, Body* b2) { if (b1 < b2) diff --git a/Client/Source/Phy2DLite/Arbiter.h b/Client/Source/Phy2DLite/Arbiter.h index 2cdbc9f..2232210 100644 --- a/Client/Source/Phy2DLite/Arbiter.h +++ b/Client/Source/Phy2DLite/Arbiter.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include "Math.h" diff --git a/Client/Source/Phy2DLite/Body.cpp b/Client/Source/Phy2DLite/Body.cpp index 73bafe2..1d896fd 100644 --- a/Client/Source/Phy2DLite/Body.cpp +++ b/Client/Source/Phy2DLite/Body.cpp @@ -1,4 +1,4 @@ -#include "Body.h" +#include "Body.h" using namespace Phy2D; diff --git a/Client/Source/Phy2DLite/Body.h b/Client/Source/Phy2DLite/Body.h index a2366ce..050c719 100644 --- a/Client/Source/Phy2DLite/Body.h +++ b/Client/Source/Phy2DLite/Body.h @@ -1,6 +1,6 @@ -#pragma once - -#include "Math.h" +#pragma once + +#include "Math.h" namespace Phy2D { diff --git a/Client/Source/Phy2DLite/Collide.cpp b/Client/Source/Phy2DLite/Collide.cpp index 647147a..6849c0e 100644 --- a/Client/Source/Phy2DLite/Collide.cpp +++ b/Client/Source/Phy2DLite/Collide.cpp @@ -1,9 +1,9 @@ -#include "Arbiter.h" -#include "Body.h" -#include "World.h" -#include "Joint.h" - -using namespace Phy2D; +#include "Arbiter.h" +#include "Body.h" +#include "World.h" +#include "Joint.h" + +using namespace Phy2D; // Box vertex and edge numbering: // diff --git a/Client/Source/Phy2DLite/Joint.cpp b/Client/Source/Phy2DLite/Joint.cpp index e0d10f9..95f7c64 100644 --- a/Client/Source/Phy2DLite/Joint.cpp +++ b/Client/Source/Phy2DLite/Joint.cpp @@ -1,8 +1,8 @@ -#include "Joint.h" -#include "Body.h" -#include "World.h" - -using namespace Phy2D; +#include "Joint.h" +#include "Body.h" +#include "World.h" + +using namespace Phy2D; void Joint::Set(Body* b1, Body* b2, const Vec2& anchor) { @@ -98,5 +98,5 @@ void Joint::ApplyImpulse() P += impulse; } - - + + diff --git a/Client/Source/Phy2DLite/Joint.h b/Client/Source/Phy2DLite/Joint.h index 1aafed4..2efe876 100644 --- a/Client/Source/Phy2DLite/Joint.h +++ b/Client/Source/Phy2DLite/Joint.h @@ -1,6 +1,6 @@ -#pragma once - -#include "Math.h" +#pragma once + +#include "Math.h" namespace Phy2D { @@ -31,4 +31,4 @@ namespace Phy2D number softness; }; -} +} diff --git a/Client/Source/Phy2DLite/Phy2D.h b/Client/Source/Phy2DLite/Phy2D.h index ba13029..7ed7871 100644 --- a/Client/Source/Phy2DLite/Phy2D.h +++ b/Client/Source/Phy2DLite/Phy2D.h @@ -1,8 +1,8 @@ -#pragma once - - -// 定点数的物理引擎 - -#include "World.h" -#include "Body.h" -#include "Joint.h" +#pragma once + + +// 定点数的物理引擎 + +#include "World.h" +#include "Body.h" +#include "Joint.h" diff --git a/Client/Source/Phy2DLite/Settings.h b/Client/Source/Phy2DLite/Settings.h index 5f7237f..e976e26 100644 --- a/Client/Source/Phy2DLite/Settings.h +++ b/Client/Source/Phy2DLite/Settings.h @@ -1,27 +1,50 @@ -#pragma once - -#include "libfixmath/libfixmath/fixmath.h" - -namespace Phy2D -{ - -#define NUMBER_FLOAT false - -#if NUMBER_FLOAT -typedef float number; -#define NUMBER_MAX (FLT_MAX) -#define NUMBER_MIN (FLT_MIN) -#define SQRT(a) (sqrt((a))) -#define SIN(a) (sin((a))) -#define COS(a) (cos((a))) -#else -// 同时一定要开启内联函数扩展,否则执行效率会非常低 -typedef Fix16 number; -#define NUMBER_MAX (fix16_maximum) -#define NUMBER_MIN (fix16_minimum) -#define SQRT(a) ((a).sqrt()) -#define SIN(a) ((a).sin()) -#define COS(a) ((a).cos()) -#endif - -} \ No newline at end of file +#pragma once + +#define NUMBER_FLOAT 1 +#define NUMBER_LIBFIX 2 +#define NUMBER_FPM 3 + +#define NUMBER_ALIAS NUMBER_LIBFIX + +#if NUMBER_ALIAS == NUMBER_LIBFIX +#include "libfixmath/libfixmath/fixmath.h" +#elif NUMBER_ALIAS == NUMBER_FPM +#include "fpm/include/fpm/fixed.hpp" +#include "fpm/include/fpm/math.hpp" +#endif + +namespace Phy2D +{ + +#if NUMBER_ALIAS == NUMBER_FLOAT + +typedef float number; +#define NUMBER_MAX (FLT_MAX) +#define NUMBER_MIN (FLT_MIN) +#define SQRT(a) (sqrt((a))) +#define SIN(a) (sin((a))) +#define COS(a) (cos((a))) + +#elif NUMBER_ALIAS == NUMBER_LIBFIX + +// 同时一定要开启内联函数扩展,否则执行效率会非常低 +typedef Fix16 number; +#define NUMBER_MAX (fix16_maximum) +#define NUMBER_MIN (fix16_minimum) +#define SQRT(a) ((a).sqrt()) +#define SIN(a) ((a).sin()) +#define COS(a) ((a).cos()) + +#elif NUMBER_ALIAS == NUMBER_FPM + +typedef fpm::fixed_16_16 number; +#define NUMBER_MAX (number::max()) +#define NUMBER_MIN (number::min()) +#define SQRT(a) (fpm::sqrt((a))) +#define SIN(a) (fpm::sin((a))) +#define COS(a) (fpm::cos((a))) + +#endif + +} + diff --git a/Client/Source/Phy2DLite/Tests/test.h b/Client/Source/Phy2DLite/Tests/test.h index c73a192..c814e3f 100644 --- a/Client/Source/Phy2DLite/Tests/test.h +++ b/Client/Source/Phy2DLite/Tests/test.h @@ -1,6 +1,6 @@ -#pragma once - -#define TEST_MATH 1 -#define TEST_P2D 2 - -#define TEST TEST_P2D +#pragma once + +#define TEST_MATH 1 +#define TEST_P2D 2 + +#define TEST TEST_P2D diff --git a/Client/Source/Phy2DLite/Tests/test_math.cpp b/Client/Source/Phy2DLite/Tests/test_math.cpp index e047508..e7642c1 100644 --- a/Client/Source/Phy2DLite/Tests/test_math.cpp +++ b/Client/Source/Phy2DLite/Tests/test_math.cpp @@ -1,23 +1,23 @@ -#include "test.h" -#if TEST == TEST_MATH - -#include - -#include "../Common/Math.h" - -using namespace Phy2D; -using namespace std; - -int main(int argc, char **argv) -{ - Vec2 a = Vec2(1.f, 2.f); - Vec2 b = a; - - cout << (a+b).ToString(); - - getchar(); - - return 0; -} - +#include "test.h" +#if TEST == TEST_MATH + +#include + +#include "../Common/Math.h" + +using namespace Phy2D; +using namespace std; + +int main(int argc, char **argv) +{ + Vec2 a = Vec2(1.f, 2.f); + Vec2 b = a; + + cout << (a+b).ToString(); + + getchar(); + + return 0; +} + #endif \ No newline at end of file diff --git a/Client/Source/Phy2DLite/Tests/test_p2d.cpp b/Client/Source/Phy2DLite/Tests/test_p2d.cpp index bd04b85..a668301 100644 --- a/Client/Source/Phy2DLite/Tests/test_p2d.cpp +++ b/Client/Source/Phy2DLite/Tests/test_p2d.cpp @@ -1,20 +1,20 @@ -#include "test.h" -#if TEST == TEST_P2D - -#include "libfixmath/libfixmath/fixmath.h" -#include -#include -#include -#include "SDL2/SDL.h" -#include "imgui/imgui.h" -#include "imgui/backends/imgui_impl_opengl2.h" -#include "imgui/backends/imgui_impl_sdl.h" - -#include "../Phy2D.h" -#include "glad/glad.h" - -using namespace std; -using namespace Phy2D; +#include "test.h" +#if TEST == TEST_P2D + +#include "libfixmath/libfixmath/fixmath.h" +#include +#include +#include +#include "SDL2/SDL.h" +#include "imgui/imgui.h" +#include "imgui/backends/imgui_impl_opengl2.h" +#include "imgui/backends/imgui_impl_sdl.h" + +#include "../Phy2D.h" +#include "glad/glad.h" + +using namespace std; +using namespace Phy2D; namespace { @@ -464,72 +464,72 @@ static void InitDemo() demoIndex = 0; Demo5(bodies, joints); } - -int main(int argc, char **argv) { - - // Setup SDL - // (Some versions of SDL before <2.0.10 appears to have performance/stalling issues on a minority of Windows systems, - // depending on whether SDL_INIT_GAMECONTROLLER is enabled or disabled.. updating to latest version of SDL is recommended!) - if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0) - { - printf("Error: %s\n", SDL_GetError()); - return -1; - } - - // Setup window - SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); - SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); - SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2); - SDL_WindowFlags window_flags = (SDL_WindowFlags)(SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI); - SDL_Window* window = SDL_CreateWindow("Phy2D", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, window_flags); - SDL_GLContext gl_context = SDL_GL_CreateContext(window); - - if (!gladLoadGLLoader((GLADloadproc)SDL_GL_GetProcAddress)) { - std::cerr << "Failed to initialize the OpenGL context." << std::endl; - exit(1); - } - - SDL_GL_MakeCurrent(window, gl_context); - SDL_GL_SetSwapInterval(1); // Enable vsync - - // Setup Dear ImGui context - IMGUI_CHECKVERSION(); - ImGui::CreateContext(); - ImGuiIO& io = ImGui::GetIO(); (void)io; - //io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls - //io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls - - // Setup Dear ImGui style - ImGui::StyleColorsDark(); - //ImGui::StyleColorsClassic(); - - // Setup Platform/Renderer backends - ImGui_ImplSDL2_InitForOpenGL(window, gl_context); - ImGui_ImplOpenGL2_Init(); - - // Load Fonts - // - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use ImGui::PushFont()/PopFont() to select them. - // - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple. - // - If the file cannot be loaded, the function will return NULL. Please handle those errors in your application (e.g. use an assertion, or display an error and quit). - // - The fonts will be rasterized at a given size (w/ oversampling) and stored into a texture when calling ImFontAtlas::Build()/GetTexDataAsXXXX(), which ImGui_ImplXXXX_NewFrame below will call. - // - Read 'docs/FONTS.md' for more instructions and details. - // - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ ! - //io.Fonts->AddFontDefault(); - //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf", 16.0f); - //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Cousine-Regular.ttf", 15.0f); - //io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf", 16.0f); - //io.Fonts->AddFontFromFileTTF("../../misc/fonts/ProggyTiny.ttf", 10.0f); - //ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese()); - //IM_ASSERT(font != NULL); - - // Our state - bool show_demo_window = true; - bool show_another_window = false; - ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); - - glViewport(0, 0, (int)io.DisplaySize.x, (int)io.DisplaySize.y); + +int main(int argc, char **argv) { + + // Setup SDL + // (Some versions of SDL before <2.0.10 appears to have performance/stalling issues on a minority of Windows systems, + // depending on whether SDL_INIT_GAMECONTROLLER is enabled or disabled.. updating to latest version of SDL is recommended!) + if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0) + { + printf("Error: %s\n", SDL_GetError()); + return -1; + } + + // Setup window + SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); + SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); + SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2); + SDL_WindowFlags window_flags = (SDL_WindowFlags)(SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI); + SDL_Window* window = SDL_CreateWindow("Phy2D lite", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, window_flags); + SDL_GLContext gl_context = SDL_GL_CreateContext(window); + + if (!gladLoadGLLoader((GLADloadproc)SDL_GL_GetProcAddress)) { + std::cerr << "Failed to initialize the OpenGL context." << std::endl; + exit(1); + } + + SDL_GL_MakeCurrent(window, gl_context); + SDL_GL_SetSwapInterval(1); // Enable vsync + + // Setup Dear ImGui context + IMGUI_CHECKVERSION(); + ImGui::CreateContext(); + ImGuiIO& io = ImGui::GetIO(); (void)io; + //io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls + //io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls + + // Setup Dear ImGui style + ImGui::StyleColorsDark(); + //ImGui::StyleColorsClassic(); + + // Setup Platform/Renderer backends + ImGui_ImplSDL2_InitForOpenGL(window, gl_context); + ImGui_ImplOpenGL2_Init(); + + // Load Fonts + // - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use ImGui::PushFont()/PopFont() to select them. + // - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple. + // - If the file cannot be loaded, the function will return NULL. Please handle those errors in your application (e.g. use an assertion, or display an error and quit). + // - The fonts will be rasterized at a given size (w/ oversampling) and stored into a texture when calling ImFontAtlas::Build()/GetTexDataAsXXXX(), which ImGui_ImplXXXX_NewFrame below will call. + // - Read 'docs/FONTS.md' for more instructions and details. + // - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ ! + //io.Fonts->AddFontDefault(); + //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf", 16.0f); + //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Cousine-Regular.ttf", 15.0f); + //io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf", 16.0f); + //io.Fonts->AddFontFromFileTTF("../../misc/fonts/ProggyTiny.ttf", 10.0f); + //ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese()); + //IM_ASSERT(font != NULL); + + // Our state + bool show_demo_window = true; + bool show_another_window = false; + ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); + + glViewport(0, 0, (int)io.DisplaySize.x, (int)io.DisplaySize.y); glMatrixMode(GL_PROJECTION); glLoadIdentity(); @@ -543,41 +543,41 @@ int main(int argc, char **argv) { { // aspect < 1, set the width to -1 to 1, with larger height glOrtho(-zoom, zoom, -zoom / aspect + pan_y, zoom / aspect + pan_y, -1.0, 1.0); - } - - InitDemo(); - - // Main loop - bool done = false; - while (!done) - { - //glClearColor(clear_color.x * clear_color.w, clear_color.y * clear_color.w, clear_color.z * clear_color.w, clear_color.w); - glClearColor(0, 0, 0, 0); - glClear(GL_COLOR_BUFFER_BIT); - - // Poll and handle events (inputs, window resize, etc.) - // You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs. - // - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application. - // - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application. - // Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags. - SDL_Event event; - while (SDL_PollEvent(&event)) - { - ImGui_ImplSDL2_ProcessEvent(&event); - if (event.type == SDL_QUIT) - done = true; - if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_CLOSE && event.window.windowID == SDL_GetWindowID(window)) - done = true; - } - - // Start the Dear ImGui frame - ImGui_ImplOpenGL2_NewFrame(); - ImGui_ImplSDL2_NewFrame(); - ImGui::NewFrame(); - - // Rendering - ImGui::Render(); - + } + + InitDemo(); + + // Main loop + bool done = false; + while (!done) + { + //glClearColor(clear_color.x * clear_color.w, clear_color.y * clear_color.w, clear_color.z * clear_color.w, clear_color.w); + glClearColor(0, 0, 0, 0); + glClear(GL_COLOR_BUFFER_BIT); + + // Poll and handle events (inputs, window resize, etc.) + // You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs. + // - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application. + // - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application. + // Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags. + SDL_Event event; + while (SDL_PollEvent(&event)) + { + ImGui_ImplSDL2_ProcessEvent(&event); + if (event.type == SDL_QUIT) + done = true; + if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_CLOSE && event.window.windowID == SDL_GetWindowID(window)) + done = true; + } + + // Start the Dear ImGui frame + ImGui_ImplOpenGL2_NewFrame(); + ImGui_ImplSDL2_NewFrame(); + ImGui::NewFrame(); + + // Rendering + ImGui::Render(); + glMatrixMode(GL_MODELVIEW); glLoadIdentity(); @@ -604,22 +604,22 @@ int main(int argc, char **argv) { } glEnd(); glPointSize(1.0f); - - //glUseProgram(0); // You may want this if using this code in an OpenGL 3+ context where shaders may be bound - ImGui_ImplOpenGL2_RenderDrawData(ImGui::GetDrawData()); - SDL_GL_SwapWindow(window); - } - - // Cleanup - ImGui_ImplOpenGL2_Shutdown(); - ImGui_ImplSDL2_Shutdown(); - ImGui::DestroyContext(); - - SDL_GL_DeleteContext(gl_context); - SDL_DestroyWindow(window); - SDL_Quit(); - - return 0; -} - + + //glUseProgram(0); // You may want this if using this code in an OpenGL 3+ context where shaders may be bound + ImGui_ImplOpenGL2_RenderDrawData(ImGui::GetDrawData()); + SDL_GL_SwapWindow(window); + } + + // Cleanup + ImGui_ImplOpenGL2_Shutdown(); + ImGui_ImplSDL2_Shutdown(); + ImGui::DestroyContext(); + + SDL_GL_DeleteContext(gl_context); + SDL_DestroyWindow(window); + SDL_Quit(); + + return 0; +} + #endif \ No newline at end of file diff --git a/Client/Source/Phy2DLite/World.cpp b/Client/Source/Phy2DLite/World.cpp index 6b0174c..4f48b69 100644 --- a/Client/Source/Phy2DLite/World.cpp +++ b/Client/Source/Phy2DLite/World.cpp @@ -1,10 +1,10 @@ -#include "World.h" -#include "Body.h" -#include "Joint.h" -#include "Arbiter.h" - -using namespace Phy2D; - +#include "World.h" +#include "Body.h" +#include "Joint.h" +#include "Arbiter.h" + +using namespace Phy2D; + using std::vector; using std::map; @@ -126,4 +126,4 @@ void World::Step(number dt) b->force.Set(0.0f, 0.0f); b->torque = 0.0f; } -} +} diff --git a/Client/Source/Phy2DLite/World.h b/Client/Source/Phy2DLite/World.h index a7a6238..63bd983 100644 --- a/Client/Source/Phy2DLite/World.h +++ b/Client/Source/Phy2DLite/World.h @@ -1,12 +1,12 @@ -#pragma once - -#include -#include -#include "Math.h" -#include "Arbiter.h" - -namespace Phy2D -{ +#pragma once + +#include +#include +#include "Math.h" +#include "Arbiter.h" + +namespace Phy2D +{ struct Body; struct Joint; @@ -31,6 +31,6 @@ namespace Phy2D static bool accumulateImpulses; static bool warmStarting; static bool positionCorrection; - }; - -} + }; + +} diff --git a/Client/Source/fixedpoint/test_basic.c b/Client/Source/fixedpoint/test_basic.c index f10c97d..0d3f927 100644 --- a/Client/Source/fixedpoint/test_basic.c +++ b/Client/Source/fixedpoint/test_basic.c @@ -1,6 +1,6 @@ -// 测试定点数 - -int main() -{ - return 0; -} +// 测试定点数 + +int main() +{ + return 0; +} -- cgit v1.1-26-g67d0