Browse Source

various changes

vlod 1 year ago
parent
commit
14080f53cd

+ 2 - 0
Pika/gameplay/containers.h

@@ -43,6 +43,7 @@ Container *getContainer(const char* name, pika::memory::MemoryArena *memoryArena
 #include "containers/bezie/bezie.h"
 
 #include "containers/physicsTest/physicsTest.h"
+#include "containers/physicsTest/logo.h"
 
 #include "containers/angryBirds/angryBirds.h"
 
@@ -72,6 +73,7 @@ Container *getContainer(const char* name, pika::memory::MemoryArena *memoryArena
 	PIKA_DECLARE_CONTAINER(Holloknight)\
 	PIKA_DECLARE_CONTAINER(Bezie)\
 	PIKA_DECLARE_CONTAINER(PhysicsTest)\
+	PIKA_DECLARE_CONTAINER(Logo)\
 	PIKA_DECLARE_CONTAINER(IsometricGame) \
 	PIKA_DECLARE_CONTAINER(MarioEditor) \
 	PIKA_DECLARE_CONTAINER(MarioNeuralTrainer) \

+ 87 - 16
Pika/gameplay/containers/angryBirds/angryBirds.h

@@ -24,9 +24,10 @@ struct AngryBirds: public Container
 		woodblock,
 		stoneblock,
 		pig,
+		red,
 	};
 
-	glm::ivec2 sizes[9]{
+	glm::ivec2 sizes[10]{
 		glm::ivec2{40,40},
 		glm::ivec2{40,40},
 
@@ -39,20 +40,21 @@ struct AngryBirds: public Container
 		glm::ivec2(80,80),
 
 		glm::ivec2(70,70),
+		glm::ivec2(70,70),
 
 	};
 
-	float friction[9]
+	float friction[10]
 	{
-		0.8, 0.8, 0.8, 0.6, 0.8, 0.6, 0.8, 0.8, 0.8
+		0.8, 0.8, 0.8, 0.6, 0.8, 0.6, 0.8, 0.8, 0.8, 0.8
 	};
 
-	float elasticity[9]
+	float elasticity[10]
 	{
-		0.4, 0.4, 0.2, 0.2, 0.4, 0.2, 0.4, 0.2, 0.9
+		0.4, 0.4, 0.2, 0.2, 0.4, 0.2, 0.4, 0.2, 0.9, 0.9
 	};
 
-	const char *textureNames[9]
+	const char *textureNames[10]
 	{
 		PIKA_RESOURCES_PATH "sus/woodballs.png",
 		PIKA_RESOURCES_PATH "sus/woodsmall.png",
@@ -63,10 +65,11 @@ struct AngryBirds: public Container
 		PIKA_RESOURCES_PATH "sus/wood.png",
 		PIKA_RESOURCES_PATH "sus/stone.png",
 		PIKA_RESOURCES_PATH "sus/pig.png",
+		PIKA_RESOURCES_PATH "sus/red.png",
 	};
 
-	gl2d::Texture textures[9];
-	gl2d::TextureAtlas texturesAtlas[9];
+	gl2d::Texture textures[10];
+	gl2d::TextureAtlas texturesAtlas[10];
 	gl2d::Texture background;
 	gl2d::Texture sling;
 	glm::vec2 backgroundSize;
@@ -83,12 +86,12 @@ struct AngryBirds: public Container
 
 	std::unordered_map<ph2d::ph2dBodyId, GameBlock> gameBlocks;
 
-	void addBlock(int type, glm::vec2 pos)
+	void addBlock(int type, glm::vec2 pos, glm::vec2 velocity = {})
 	{
 		glm::ivec2 size = sizes[type];
 		ph2d::ph2dBodyId body = 0;
 
-		if (type == woodBalls || type == pig)
+		if (type == woodBalls || type == pig || type == red)
 		{
 			body = physicsEngine.addBody(pos,
 				ph2d::createCircleCollider(size.x/2));
@@ -110,8 +113,7 @@ struct AngryBirds: public Container
 		physicsEngine.bodies[body].dynamicFriction = friction[type];
 		physicsEngine.bodies[body].staticFriction = friction[type] + 0.1f;
 		physicsEngine.bodies[body].elasticity = elasticity[type];
-
-		
+		physicsEngine.bodies[body].motionState.velocity = velocity;
 	}
 
 	void removeBlock(ph2d::ph2dBodyId id)
@@ -137,11 +139,11 @@ struct AngryBirds: public Container
 	{
 		renderer.create(requestedInfo.requestedFBO.fbo);
 
-		for (int i = 0; i < 9; i++)
+		for (int i = 0; i < 10; i++)
 		{
 			textures[i] = pika::gl2d::loadTexture(textureNames[i], requestedInfo);
 
-			if (i == pig)
+			if (i == pig || i == red)
 			{
 				texturesAtlas[i] = gl2d::TextureAtlas(1, 1);
 			}
@@ -152,7 +154,7 @@ struct AngryBirds: public Container
 		}
 
 		physicsEngine.simulationphysicsSettings.gravity = glm::vec2(0, 9.81) * 100.f;
-		physicsEngine.simulationphysicsSettings.restingAngularVelocity = glm::radians(5.f);
+		physicsEngine.simulationphysicsSettings.restingAngularVelocity = glm::radians(50.f);
 		physicsEngine.simulationphysicsSettings.restingVelocity = 5;
 
 		background = pika::gl2d::loadTexture(PIKA_RESOURCES_PATH "sus/background.png", requestedInfo);
@@ -201,6 +203,7 @@ struct AngryBirds: public Container
 	"pig",
 	"eraser",
 	"move",
+	"red",
 	"none",
 	};
 
@@ -285,7 +288,7 @@ struct AngryBirds: public Container
 
 	#pragma endregion
 
-		pika::gl2d::cameraController(renderer.currentCamera, input, 100, 1);
+		pika::gl2d::cameraController(renderer.currentCamera, input, 500, 3);
 
 
 		glm::vec2 mousePosScreen = {input.mouseX, input.mouseY};
@@ -358,6 +361,14 @@ struct AngryBirds: public Container
 
 		renderer.renderRectangle({0, 720, 50, 80}, sling);
 
+		static int pressed = 0;
+		static glm::vec2 pressedPosition = {};
+
+		if (currentSelectedOption == 11 && pressed)
+		{
+			renderer.renderLine({pressedPosition}, mousePosWorld, Colors_Red, 4);
+		}
+
 		for (auto &index : physicsEngine.bodies)
 		{
 			auto &b = index.second;
@@ -388,6 +399,31 @@ struct AngryBirds: public Container
 				{}, 0, texturesAtlas[currentSelectedOption].get(0, 0));
 		}
 
+
+	
+
+		if (currentSelectedOption == 11)
+		{
+			
+			if (input.lMouse.pressed())
+			{
+				pressed = true;
+				pressedPosition = mousePosWorld;
+			}
+
+
+			if (input.lMouse.released() && pressed)
+			{
+				glm::vec2 vector =  pressedPosition - mousePosWorld;
+
+				addBlock(red, {0, 750}, vector * 3.f);
+
+				pressed = 0;
+			}
+
+
+		}
+
 	#pragma endregion
 
 
@@ -459,6 +495,41 @@ struct AngryBirds: public Container
 
 		}
 
+
+		if(0)
+		for (auto &A : physicsEngine.bodies)
+			for (auto &B : physicsEngine.bodies)
+			{
+				glm::vec2 tangentA = {};
+				glm::vec2 tangentB = {};
+				glm::vec2 contactPoint = {};
+				glm::vec2 n = {};
+				float p = 0;
+
+				if (A.first == B.first) { break; }
+
+				if (ph2d::BodyvsBody(A.second,
+					B.second,
+					p, n, contactPoint, tangentA, tangentB))
+				{
+					
+					renderer.renderLine(contactPoint,
+						contactPoint + n * 100.f, Colors_Green, 4);
+
+					renderer.renderRectangle({contactPoint - glm::vec2(2,2), 4,4}, Colors_White);
+
+					renderer.renderLine(contactPoint,
+						contactPoint + tangentA * 100.f, Colors_Red, 4);
+					renderer.renderLine(contactPoint,
+						contactPoint + tangentB * 100.f, Colors_Purple, 4);
+
+
+				}
+
+			}
+
+
+
 		renderer.renderRectangle({mousePosWorld - glm::vec2(3,3), 6, 6}, Colors_Red);
 
 	#pragma endregion

+ 568 - 0
Pika/gameplay/containers/physicsTest/logo.h

@@ -0,0 +1,568 @@
+#pragma once
+
+#include <gl2d/gl2d.h>
+#include <imgui.h>
+#include <baseContainer.h>
+#include <shortcutApi/shortcutApi.h>
+#include <pikaSizes.h>
+#include <imgui_spinner.h>
+#include <ph2d/ph2d.h>
+#include <unordered_set>
+#include <sstream>
+
+
+struct Logo: public Container
+{
+
+
+	// Function to generate a pastel color based on an input number
+	glm::vec3 generatePastelColor(int inputNumber)
+	{
+		srand(inputNumber);
+
+		// Seed random number generator based on input
+		//auto baseColor = glm::vec3(0,0,0);
+		//glm::vec3 baseColor = glm::ballRand<float>(1.0f);  // Random direction on a sphere
+		glm::vec3 baseColor(rand() % 100 / 100.f, rand() % 100 / 100.f, rand() % 100 / 100.f);
+		baseColor = glm::abs(baseColor);            // Ensure positive values
+
+		// Adjust saturation to pastel range by mixing with white
+		float pastelFactor = 0.7f;
+		glm::vec3 pastelColor = glm::mix(baseColor, glm::vec3(1.0f), pastelFactor);
+
+		// Map input number into [0,1] range
+		float modifier = (inputNumber % 1000) / 1000.0f;
+		pastelColor += modifier * 0.1f;
+
+		return glm::clamp(pastelColor, 0.0f, 1.0f);
+	}
+
+
+
+	gl2d::Renderer2D renderer;
+	ph2d::PhysicsEngine physicsEngine;
+	gl2d::Texture ballTexture;
+	gl2d::Texture logoTexture;
+
+	std::unordered_set<unsigned int> ropeIds;
+
+	std::unordered_map<unsigned int, glm::vec3> colors;
+
+	//static constexpr float floorPos = 850;
+	static constexpr float floorPos = 1000;
+
+	bool simulate = 1;
+
+	//todo user can request imgui ids; shortcut manager context; allocators
+	static ContainerStaticInfo containerInfo()
+	{
+		ContainerStaticInfo info = {};
+		info.defaultHeapMemorySize = pika::MB(20);
+		info.requestImguiFbo = true;
+		info.pushAnImguiIdForMe = true;
+		info.andInputWithWindowHasFocus = 0;
+		info.andInputWithWindowHasFocusLastFrame = 0;
+
+		return info;
+	}
+
+
+	bool create(RequestedContainerInfo &requestedInfo, pika::StaticString<256> commandLineArgument)
+	{
+		renderer.create(requestedInfo.requestedFBO.fbo);
+	
+		ballTexture = pika::gl2d::loadTexture(PIKA_RESOURCES_PATH "ball.png", requestedInfo);
+		logoTexture = pika::gl2d::loadTexture(PIKA_RESOURCES_PATH "logo2.png", requestedInfo);
+
+		physicsEngine.simulationphysicsSettings.gravity = glm::vec2(0, 9.81) * 1.f;
+		//physicsEngine.simulationphysicsSettings.gravity = glm::vec2(0, 0);
+		physicsEngine.simulationphysicsSettings.airDragCoeficient = 0.01f;
+		physicsEngine.collisionChecksCount = 2;
+		physicsEngine.setFixedTimeStamp = 0;
+
+
+		auto file = requestedInfo.readEntireFileBinaryAsAString(PIKA_RESOURCES_PATH "physicsOrder.txt");
+		std::stringstream stream(file);
+
+		
+		{
+			unsigned int id = 0;
+			float r, g, b;
+
+			while (stream.good() && !stream.eof() && stream >> id)
+			{
+				stream >> r >> g >> b;
+
+				colors[id] = glm::vec3{r,g,b} / 255.f;
+			};
+
+		}
+
+	
+	
+		//physicsEngine.addBody({500, 200}, ph2d::createConvexPolygonCollider(shape, 5));
+
+
+		//physicsEngine.addBody({500, 1100}, 
+		//	ph2d::createBoxCollider({1100, 10}));
+		
+		//physicsEngine.addBody({1, 800}, ph2d::createBoxCollider({300, 250}));
+
+		//auto body = physicsEngine.addBody({500, 500}, ph2d::createBoxCollider({400, 50}));
+		//physicsEngine.bodies[body].flags.setFreezePosition();
+		//physicsEngine.bodies[body].flags.setFreezeRotation();
+
+		//physicsEngine.bodies[1].motionState.mass = 0;
+		//physicsEngine.bodies[1].motionState.momentOfInertia = 0;
+
+
+		//physicsEngine.addBody({700, 700}, ph2d::createBoxCollider({300, 300}));
+
+
+		//physicsEngine.addBody({600, 600}, ph2d::createBoxCollider({350, 350}));
+		//physicsEngine.bodies[1].motionState.rotation = glm::radians(30.f);
+
+		//physicsEngine.addBody({900, 500}, ph2d::createCircleCollider({40}));
+		//physicsEngine.addBody({550, 700}, ph2d::createCircleCollider({25}));
+
+		//physicsEngine.addBody({600, 600}, ph2d::createBoxCollider({50, 50}));
+
+
+		//std::cout << ph2d::vectorToRotation({0,1}) << "\n";
+		//std::cout << ph2d::vectorToRotation({-1,1}) << "\n";
+		//std::cout << ph2d::vectorToRotation({-1,0}) << "\n";
+		//std::cout << ph2d::vectorToRotation({0,-1}) << "\n";
+		//std::cout << ph2d::vectorToRotation({1,0}) << "\n";
+		//
+		//std::cout << "\n";
+		//std::cout << ph2d::rotationToVector(ph2d::vectorToRotation({0,1}) ).x << " " << ph2d::rotationToVector(ph2d::vectorToRotation({0,1}) ).y  << "\n";
+		//std::cout << ph2d::rotationToVector(ph2d::vectorToRotation({-1,1})).x << " " << ph2d::rotationToVector(ph2d::vectorToRotation({-1,1})).y << "\n";
+		//std::cout << ph2d::rotationToVector(ph2d::vectorToRotation({-1,0})).x << " " << ph2d::rotationToVector(ph2d::vectorToRotation({-1,0})).y << "\n";
+		//std::cout << ph2d::rotationToVector(ph2d::vectorToRotation({0,-1})).x << " " << ph2d::rotationToVector(ph2d::vectorToRotation({0,-1})).y << "\n";
+		//std::cout << ph2d::rotationToVector(ph2d::vectorToRotation({1,0}) ).x << " " << ph2d::rotationToVector(ph2d::vectorToRotation({1,0}) ).y  << "\n";
+
+		//auto b = physicsEngine.addHalfSpaceStaticObject({0, floorPos + 10}, {0.0, 1});
+		//physicsEngine.bodies[b].staticFriction = 0;
+		//physicsEngine.bodies[b].dynamicFriction = 0;
+		//physicsEngine.addBody({500, floorPos}, ph2d::createBoxCollider({900, 50}));
+		//physicsEngine.bodies.back().motionState.mass = 0;
+		//physicsEngine.bodies.back().motionState.momentOfInertia = 0;
+
+		return true;
+	}
+
+	bool update(pika::Input input, pika::WindowState windowState,
+		RequestedContainerInfo &requestedInfo)
+	{
+	#pragma region init stuff
+		int w = 0; int h = 0;
+		w = windowState.frameBufferW; //window w
+		h = windowState.frameBufferH; //window h
+
+		glClearColor(0.2, 0.22, 0.23, 1);
+		glClear(GL_COLOR_BUFFER_BIT); //clear screen
+
+		renderer.updateWindowMetrics(w, h);
+	#pragma endregion
+
+
+		//ph2d::AABB box1 = glm::vec4{300,300, 300,300};
+	//
+	//ph2d::AABB box2 = glm::vec4(glm::vec2(platform::getRelMousePosition()) - glm::vec2(50, 50), 100, 100);
+	//
+	//renderer.renderRectangleOutline(box1.asVec4(), Colors_White);
+	//
+	//auto color = Colors_White;
+	//
+	//if (ph2d::AABBvsAABB(box1, box2))
+	//{
+	//	color = Colors_Red;
+	//}
+	//
+	//renderer.renderRectangleOutline(box2.asVec4(), color);
+
+
+	//ph2d::Circle a = glm::vec3{450,450, 150};
+	//ph2d::Circle b = glm::vec3(glm::vec2(platform::getRelMousePosition()), 50);
+	//renderer.renderCircleOutline(a.center, a.r, Colors_White, 2, 32);
+	//
+	//auto color = Colors_White;
+	//if (ph2d::CirclevsCircle(a, b))
+	//{
+	//	color = Colors_Red;
+	//}
+	//renderer.renderCircleOutline(b.center, b.r, color, 2, 32);
+		static int simulationSpeed = 1;
+		float rightPos = 1000;
+
+		//physicsEngine.bodies[0].motionState.rotation = glm::radians(-30.f);
+
+
+		ImGui::PushStyleColor(ImGuiCol_WindowBg, {0.3,0.3,0.3,0.8});
+		ImGui::Begin("Settings");
+
+		ImGui::DragInt("Speed", &simulationSpeed);
+
+		//physicsEngine.bodies[0].motionState.angularVelocity = 1.5;
+
+		ImGui::Text("Mouse pos %d, %d", input.mouseX, input.mouseY);
+
+
+		ImGui::Checkbox("Simulate", &simulate);
+
+		ImGui::End();
+		ImGui::PopStyleColor();
+
+		static int selected = -1;
+
+		//mouse
+		//if (!simulate && input.rMouse.held())
+		//{
+		//	physicsEngine.bodies[1].motionState.setPos({input.mouseX, input.mouseY});
+		//}
+
+		static glm::vec2 pressedPosition = {};
+
+		if (input.lMouse.pressed())
+		{
+			selected = -1;
+
+			for (auto b : physicsEngine.bodies)
+			{
+				if (b.second.intersectPoint({input.mouseX, input.mouseY}))
+				{
+					selected = b.first;
+					pressedPosition = {input.mouseX, input.mouseY};
+				}
+			}
+		}
+
+		if (selected > 0)
+		{
+			renderer.renderLine(pressedPosition, {input.mouseX, input.mouseY}, Colors_Blue, 4);
+		}
+
+		if (input.lMouse.released() && selected > 0)
+		{
+
+			glm::vec2 force = pressedPosition - glm::vec2({input.mouseX, input.mouseY});
+
+			//physicsEngine.bodies[selected].motionState.velocity += force;
+			force *= physicsEngine.bodies[selected].motionState.mass;
+			force *= 4.f;
+
+			physicsEngine.bodies[selected].applyImpulseWorldPosition(force,
+				//physicsEngine.bodies[selected].motionState.pos
+				pressedPosition
+			);
+
+			//physicsEngine.bodies[selected].motionState.angularVelocity = 10;
+
+			selected = -1;
+			pressedPosition = {};
+		}
+
+
+		for (int i = 0; i < simulationSpeed; i++)
+		{
+
+			//gravity
+			//if(simulate)
+			//for (int i=0; i<physicsEngine.bodies.size(); i++)
+			//{
+			//	if(physicsEngine.bodies[i].motionState.mass != 0 && physicsEngine.bodies[i].motionState.mass != INFINITY)
+			//		physicsEngine.bodies[i].motionState.acceleration += glm::vec2(0, 9.81) * 100.f;
+			//}
+
+			if (simulate)
+			{
+				physicsEngine.collisionChecksCount = 1;
+				physicsEngine.runSimulation(0.008);
+			}
+			else
+			{
+				physicsEngine.collisionChecksCount = 0;
+				//physicsEngine.runSimulation(0.008);
+			}
+
+			for (auto &it : physicsEngine.bodies)
+			{
+				auto &b = it.second;
+
+				auto bottom = b.getAABB().max().y;
+				auto left = b.getAABB().min().x;
+				auto right = b.getAABB().max().x;
+				auto top = b.getAABB().min().y;
+
+				if (bottom > floorPos)
+				{
+					float diff = bottom - floorPos;
+					b.motionState.pos.y -= diff;
+					b.motionState.lastPos = b.motionState.pos;
+				
+					b.motionState.velocity.y *= -0.9f;
+				}
+
+				if (left < 0)
+				{
+					b.motionState.pos.x -= left;
+					b.motionState.lastPos = b.motionState.pos;
+
+					b.motionState.velocity.x *= -0.9;
+				}
+
+				if (right > rightPos)
+				{
+					b.motionState.pos.x -= right - rightPos;
+					b.motionState.lastPos = b.motionState.pos;
+
+					b.motionState.velocity.x *= -0.9;
+				}
+
+				if (top < 0)
+				{
+					b.motionState.pos.y -= top;
+					b.motionState.lastPos = b.motionState.pos;
+
+					b.motionState.velocity.y *= -0.9;
+				}
+			}
+		}
+
+		//std::cout << physicsEngine.bodies[0].getAABB().max().x << "\n";
+
+		//renderer.renderRectangleOutline({300 - 25, 100 - 25, 50, 50}, Colors_Red);
+		//renderer.renderRectangleOutline({600 - 25, 200 - 25, 50, 50}, Colors_Red);
+
+
+		//auto a = physicsEngine.bodies[0].getAABB();
+		//auto b = physicsEngine.bodies[1].getAABB();
+		//ph2d::Circle a1 = glm::vec3{a.center(),a.size.x / 2};
+		//ph2d::Circle b1 = glm::vec3{b.center(),b.size.x / 2};
+		//if (ph2d::CirclevsCircle(a1, b1, p, n, contactPoint))
+		//{
+		//	penetrated = true;
+		//}
+
+
+		//auto a = physicsEngine.bodies[0].getAABB();
+		//auto b = physicsEngine.bodies[1];
+		//ph2d::LineEquation lineEquation;
+		//lineEquation.createFromRotationAndPoint(b.motionState.rotation,
+		//	b.motionState.pos);
+		//if (ph2d::HalfSpaceVSCircle(lineEquation, a, p, n, contactPoint))
+		//{
+		//	penetrated = true;
+		//}
+
+		//glm::vec2 cornersA[4] = {};
+		//glm::vec2 cornersB[4] = {};
+		//physicsEngine.bodies[0].getAABB().getCornersRotated(cornersA, physicsEngine.bodies[0].motionState.rotation);
+		//physicsEngine.bodies[1].getAABB().getCornersRotated(cornersB, physicsEngine.bodies[1].motionState.rotation);
+		//
+		//float rez = ph2d::calculatePenetrationAlongOneAxe(cornersA, 4, cornersB, 4, {1,0});
+		//if (rez > 0)
+		//{
+		//	penetrated = true;
+		//}
+
+		ImGui::Begin("Settings");
+		int count = physicsEngine.bodies.size();
+		ImGui::Text("Count: %d", count);
+
+		if (ImGui::Button("Make Photo"))
+		{
+
+			glm::ivec2 size = {};
+			auto pixels = logoTexture.readTextureData(0, &size);
+
+			auto samplePixel = [&](glm::vec2 uv)
+			{
+				uv = glm::clamp(uv, {0,0}, {1,1});
+				uv.y = 1 - uv.y;
+				uv *= glm::vec2(size.x-1, size.y-1);
+
+				uv = glm::ivec2(uv);
+
+				glm::vec4 rez = {};
+				rez.r = pixels[(4 * (uv.x + uv.y * size.x)) + 0];
+				rez.g = pixels[(4 * (uv.x + uv.y * size.x)) + 1];
+				rez.b = pixels[(4 * (uv.x + uv.y * size.x)) + 2];
+				rez.a = pixels[(4 * (uv.x + uv.y * size.x)) + 3];
+				return rez;
+			};
+
+			pika::memory::pushCustomAllocatorsToStandard();
+			{
+				std::ofstream f(PIKA_RESOURCES_PATH "physicsOrder.txt");
+
+				for (auto &o : physicsEngine.bodies)
+				{
+
+					f << o.first << " ";
+					
+					glm::vec2 uv = o.second.motionState.pos;
+					uv /= glm::vec2(rightPos, floorPos);
+					auto color = samplePixel(uv);
+					f << color.r << ' ' << color.g << ' ' << color.b << "\n";
+				}
+				f.close();
+			}
+			pika::memory::popCustomAllocatorsToStandard();
+		}
+
+		ImGui::End();
+
+		static bool start = 0;
+		if (input.buttons[pika::Button::P].held())
+		{
+			start = true;
+		}
+
+		if (start)
+		{
+			static int ballsCounter = 0;
+			static float timer = 0;
+			static float counter = 0;
+
+			if (ballsCounter < 600)
+			{
+				if (timer <= 0)
+				{
+					auto p = physicsEngine.addBody({rightPos/2, floorPos/2}, ph2d::createCircleCollider({24}));
+
+					glm::vec2 direction = {sin(counter), cos(counter)};
+					//direction.y = std::abs(direction.y);
+					//direction.y += 0.1;
+					direction = glm::normalize(direction);
+
+					physicsEngine.bodies[p].motionState.velocity = direction * 2000.f;
+					timer = 0.05;
+					ballsCounter++;
+				};
+
+				timer -= 0.008;
+				counter += 0.008 * 2.f;
+
+			};
+		}
+
+		for (auto &i : physicsEngine.bodies)
+		{
+			auto &b = i.second;
+
+			auto color = glm::vec4(generatePastelColor(i.first), 1);
+
+			if (i.first == selected)
+			{
+				color = Colors_Blue;
+			}
+
+			//if (b.intersectPoint({input.mouseX, input.mouseY}))
+			//{
+			//	color = Colors_Turqoise;
+			//}
+
+			color = glm::vec4(colors[i.first], 1);
+
+			//if (penetrated)
+			//{
+			//	color = Colors_Red;
+			//}
+
+			//if (OBBvsPoint(physicsEngine.bodies[i].getAABB(),
+			//	physicsEngine.bodies[i].motionState.rotation,
+			//	{input.mouseX, input.mouseY}))
+			//{
+			//	color = Colors_Blue;
+			//}
+
+			if (b.collider.type == ph2d::ColliderCircle)
+			{
+				renderer.renderCircleOutline(b.motionState.pos,
+					b.collider.collider.circle.radius, color, 2, 32);
+
+				glm::vec2 vector = {1,0};
+				vector = ph2d::rotateAroundCenter(vector, b.motionState.rotation);
+				renderer.renderLine(b.motionState.pos, b.motionState.pos + vector *
+					b.collider.collider.circle.radius, color, 4);
+
+					 
+				renderer.renderRectangle(b.getAABB().asVec4(), ballTexture, color, {}, b.motionState.rotation);
+
+			}
+			else if (b.collider.type == ph2d::ColliderBox)
+			{
+				float rotation = glm::degrees(b.motionState.rotation);
+
+				renderer.renderRectangleOutline(b.getAABB().asVec4(), color, 2, {}, rotation);
+			}
+			else if (b.collider.type == ph2d::ColliderHalfSpace)
+			{
+
+				ph2d::LineEquation lineEquation;
+				lineEquation.createFromRotationAndPoint(b.motionState.rotation,
+					b.motionState.pos);
+
+				glm::vec2 lineEquationStart = lineEquation.getClosestPointToOrigin();
+				lineEquationStart -= lineEquation.getLineVector() * 1000.f;
+				renderer.renderLine(lineEquationStart, lineEquationStart + lineEquation.getLineVector() * 2000.f, Colors_Red, 4);
+			}
+			else if (b.collider.type == ph2d::ColliderConvexPolygon)
+			{
+				auto &c = b.collider.collider.convexPolygon;
+
+				for (int i = 0; i < c.vertexCount; i++)
+				{
+					glm::vec2 p1 = c.vertexesObjectSpace[i] + b.motionState.pos;
+					glm::vec2 p2 = c.vertexesObjectSpace[(i + 1) % c.vertexCount] + b.motionState.pos;
+
+					p1 = ph2d::rotateAroundPoint(p1, b.motionState.pos, b.motionState.rotation);
+					p2 = ph2d::rotateAroundPoint(p2, b.motionState.pos, b.motionState.rotation);
+
+					renderer.renderLine(p1, p2, color, 4);
+				}
+
+			}
+
+		}
+
+		//renderer.renderRectangle({-100, floorPos, 100000, 20});
+
+		renderer.renderRectangle({
+			glm::vec2(input.mouseX,input.mouseY) - glm::vec2(4,4), 8, 8}, Colors_Red);
+
+		//glm::vec2 lineEquationStart = lineEquation.getClosestPointToOrigin();
+		//lineEquationStart -= lineEquation.getLineVector() * 1000.f;
+		//renderer.renderLine(lineEquationStart, lineEquationStart + lineEquation.getLineVector() * 2000.f, Colors_Red);
+
+
+		//ph2d::LineEquation lineEquation;
+		//lineEquation.createFromNormalAndPoint({0,1}, {0, floorPos});
+
+		//float pl = 0;
+		//pl = lineEquation.computeEquation(platform::getRelMousePosition());
+		//ImGui::Begin("Settings");
+		//ImGui::Text("Penetration line: %f", pl);
+		//ImGui::End();
+
+
+		//glm::vec2 p2 = platform::getRelMousePosition();
+		//p2 = ph2d::rotateAroundCenter(p2, glm::radians(45.f));
+		//renderer.renderRectangle({p2, 10, 10}, Colors_Red);
+
+
+
+
+		renderer.flush();
+
+		return true;
+	}
+
+	//optional
+	void destruct(RequestedContainerInfo &requestedInfo)
+	{
+
+	}
+
+};

+ 106 - 32
Pika/gameplay/containers/physicsTest/physicsTest.h

@@ -39,7 +39,11 @@ struct PhysicsTest: public Container
 
 	gl2d::Renderer2D renderer;
 	ph2d::PhysicsEngine physicsEngine;
+	gl2d::Texture ballTexture;
 
+	std::unordered_set<unsigned int> ropeIds;
+
+	//static constexpr float floorPos = 850;
 	static constexpr float floorPos = 850;
 
 	bool simulate = 1;
@@ -62,14 +66,18 @@ struct PhysicsTest: public Container
 	{
 		renderer.create(requestedInfo.requestedFBO.fbo);
 	
+		ballTexture = pika::gl2d::loadTexture(PIKA_RESOURCES_PATH "ball.png", requestedInfo);
+
 		physicsEngine.simulationphysicsSettings.gravity = glm::vec2(0, 9.81) * 100.f;
-		physicsEngine.collisionChecksCount = 1;
+		//physicsEngine.simulationphysicsSettings.gravity = glm::vec2(0, 0);
+		physicsEngine.simulationphysicsSettings.airDragCoeficient = 0.01f;
+		//physicsEngine.collisionChecksCount = 1;
 
-		for (int i = 0; i < 50; i++)
+		for (int i = 0; i < 0; i++)
 		{
 			//if (i == 1) { mass = 0; }
 
-			if (1)
+			if (0)
 			{
 				float w = rand() % 100 + 20;
 				float h = rand() % 100 + 20;
@@ -80,20 +88,36 @@ struct PhysicsTest: public Container
 				auto body = physicsEngine.addBody({rand() % 800 + 100, rand() % 800 + 100},
 					ph2d::createBoxCollider({w, h}));
 				//physicsEngine.bodies[body].motionState.rotation = ((rand() % 800) / 800.f) * 3.14159f;
-				physicsEngine.bodies[body].flags.setFreezeRotation();
+				//physicsEngine.bodies[body].flags.setFreezeRotation();
 			}
 
-			for (int j = 0; j < 1; j++)
+			for (int j = 0; j < 2; j++)
 			{
 				float r = rand() % 35 + 10;
 
 				auto body = physicsEngine.addBody({rand() % 800 + 100, rand() % 800 + 100},
 					ph2d::createCircleCollider({r}));
-				physicsEngine.bodies[body].flags.setFreezeRotation();
+				//physicsEngine.bodies[body].flags.setFreezeRotation();
 
 			}
 		}
 
+		if(0)
+		for (int i = 0; i < 20; i++)
+		{
+
+			float r = 20;
+			auto body = physicsEngine.addBody(
+				glm::vec2{300, 200} + glm::vec2{(i % 5) * 40, 0}
+				+ glm::vec2{0,(i / 5) * 40}
+				+glm::vec2{(i / 5) * 20, 0},
+
+
+				ph2d::createCircleCollider({r}));
+
+		}
+
+
 		glm::vec2 shape[5] = 
 		{
 			{0, -50},
@@ -105,27 +129,43 @@ struct PhysicsTest: public Container
 		for (int i = 0; i < 5; i++) { shape[i] *= 2; }
 
 
-		//auto bodyA = physicsEngine.addBody({500, 200}, ph2d::createCircleCollider({20}));
-		//physicsEngine.bodies[bodyA].flags.setKinematic(true);
-		//
-		//for (int i = 0; i < 10; i++)
-		//{
-		//	auto bodyB = physicsEngine.addBody({500, 220 + i * 20}, ph2d::createCircleCollider({20}));
-		//	physicsEngine.addConstrain({bodyA, bodyB, 40});
-		//	bodyA = bodyB;
-		//	
-		//
-		//}
-
+		//rope
 		if(0)
 		{
-			auto b = physicsEngine.addBody({500, 200}, ph2d::createConvexPolygonCollider(shape, 5));
-			physicsEngine.bodies[b].flags.setFreezeRotation();
+			auto bodyA = physicsEngine.addBody({200, 800}, ph2d::createCircleCollider({20}));
+			physicsEngine.bodies[bodyA].flags.setKinematic(true);
+			ropeIds.insert(bodyA);
+			for (int i = 0; i < 25; i++)
+			{
+				auto bodyB = physicsEngine.addBody({200 + i * 45, 800}, ph2d::createCircleCollider({20}));
+				physicsEngine.addConstrain({bodyA, bodyB, 35, 50000 * 1.2});
+				bodyA = bodyB;
+				ropeIds.insert(bodyA);
 
+
+				if (i == 24)
+				{
+					physicsEngine.bodies[bodyA].flags.setKinematic(true);
+				}
+			}
+		}
+
+		//physicsEngine.addBody({500, 200}, ph2d::createConvexPolygonCollider(shape, 5));
+
+		if(1)
+		{
+			auto b = physicsEngine.addBody({500, 200}, ph2d::createConvexPolygonCollider(shape, 5));
 			auto body = physicsEngine.addBody({500, 500}, ph2d::createCircleCollider({100}));
 
+			auto mass = physicsEngine.bodies[body].motionState.mass;
+			auto inertia = physicsEngine.bodies[body].motionState.momentOfInertia;
+
+			//physicsEngine.bodies[b].flags.setFreezeRotation();
+			physicsEngine.bodies[b].motionState.mass = mass;
+			physicsEngine.bodies[b].motionState.momentOfInertia = inertia;
+
 			//auto body = physicsEngine.addBody({500, 500}, ph2d::createBoxCollider({200, 200}));
-			physicsEngine.bodies[body].flags.setFreezeRotation();
+			//physicsEngine.bodies[body].flags.setFreezeRotation();
 		}
 
 		//physicsEngine.addBody({500, 1100}, 
@@ -133,7 +173,7 @@ struct PhysicsTest: public Container
 		
 		//physicsEngine.addBody({1, 800}, ph2d::createBoxCollider({300, 250}));
 
-		//auto body = physicsEngine.addBody({500, 500}, ph2d::createBoxCollider({400, 100}));
+		//auto body = physicsEngine.addBody({500, 500}, ph2d::createBoxCollider({400, 50}));
 		//physicsEngine.bodies[body].flags.setFreezePosition();
 		//physicsEngine.bodies[body].flags.setFreezeRotation();
 
@@ -166,7 +206,7 @@ struct PhysicsTest: public Container
 		//std::cout << ph2d::rotationToVector(ph2d::vectorToRotation({0,-1})).x << " " << ph2d::rotationToVector(ph2d::vectorToRotation({0,-1})).y << "\n";
 		//std::cout << ph2d::rotationToVector(ph2d::vectorToRotation({1,0}) ).x << " " << ph2d::rotationToVector(ph2d::vectorToRotation({1,0}) ).y  << "\n";
 
-		auto b = physicsEngine.addHalfSpaceStaticObject({0, floorPos}, {0.0, 1});
+		//auto b = physicsEngine.addHalfSpaceStaticObject({0, floorPos + 10}, {0.0, 1});
 		//physicsEngine.bodies[b].staticFriction = 0;
 		//physicsEngine.bodies[b].dynamicFriction = 0;
 		//physicsEngine.addBody({500, floorPos}, ph2d::createBoxCollider({900, 50}));
@@ -278,7 +318,7 @@ struct PhysicsTest: public Container
 
 			//physicsEngine.bodies[selected].motionState.velocity += force;
 			force *= physicsEngine.bodies[selected].motionState.mass;
-			force *= 2.f;
+			force *= 4.f;
 
 			physicsEngine.bodies[selected].applyImpulseWorldPosition(force,
 				//physicsEngine.bodies[selected].motionState.pos
@@ -323,14 +363,14 @@ struct PhysicsTest: public Container
 				auto right = b.getAABB().max().x;
 				auto top = b.getAABB().min().y;
 
-				//if (bottom > floorPos)
-				//{
-				//	float diff = bottom - floorPos;
-				//	b.motionState.pos.y -= diff;
-				//	b.motionState.lastPos = b.motionState.pos;
-				//
-				//	b.motionState.velocity.y *= -0.9;
-				//}
+				if (bottom > floorPos)
+				{
+					float diff = bottom - floorPos;
+					b.motionState.pos.y -= diff;
+					b.motionState.lastPos = b.motionState.pos;
+				
+					b.motionState.velocity.y *= -0.2f;
+				}
 
 				if (left < 0)
 				{
@@ -413,6 +453,29 @@ struct PhysicsTest: public Container
 		ImGui::Text("Penetration: %f", p);
 		ImGui::End();
 
+		if (input.buttons[pika::Button::P].held())
+		{
+			static float timer = 0;
+			static float counter = 0;
+
+			if (timer <= 0)
+			{
+				auto p = physicsEngine.addBody({input.mouseX, input.mouseY}, ph2d::createCircleCollider({22}));
+
+				glm::vec2 direction = {sin(counter), cos(counter)};
+				direction.y = std::abs(direction.y);
+				direction.y += 0.1;
+				direction = glm::normalize(direction);
+
+
+				physicsEngine.bodies[p].motionState.velocity = direction * 200.f;
+				timer = 0.2;
+			};
+
+			timer -= input.deltaTime;
+			counter += input.deltaTime * 2.f;
+		}
+
 		for (auto &i : physicsEngine.bodies)
 		{
 			auto &b = i.second;
@@ -451,6 +514,15 @@ struct PhysicsTest: public Container
 				renderer.renderLine(b.motionState.pos, b.motionState.pos + vector *
 					b.collider.collider.circle.radius, color, 4);
 
+				auto color = Colors_White;
+
+				if (ropeIds.find(i.first) == ropeIds.end())
+				{
+					color = glm::vec4(generatePastelColor(i.first), 1);
+				}
+					 
+				renderer.renderRectangle(b.getAABB().asVec4(), ballTexture, color, {}, b.motionState.rotation);
+
 			}
 			else if (b.collider.type == ph2d::ColliderBox)
 			{
@@ -503,6 +575,8 @@ struct PhysicsTest: public Container
 			//	contactPoint + tangentB * 100.f, Colors_Purple, 4);
 		}
 
+		renderer.renderRectangle({
+			glm::vec2(input.mouseX,input.mouseY) - glm::vec2(4,4), 8, 8}, Colors_Red);
 
 		//glm::vec2 lineEquationStart = lineEquation.getClosestPointToOrigin();
 		//lineEquationStart -= lineEquation.getLineVector() * 1000.f;

BIN
Pika/resources/ball.png


BIN
Pika/resources/logo.png


BIN
Pika/resources/logo2.png


+ 2 - 2
Pika/resources/logs.txt

@@ -1,2 +1,2 @@
-#2024-12-04 14:44:42: Created container: PhysicsTest
-#2024-12-04 14:45:14: Destroyed continer: PhysicsTest #1
+#2024-12-05 15:58:02: Created container: AngryBirds
+#2024-12-05 16:01:25: Destroyed continer: AngryBirds #1

+ 600 - 0
Pika/resources/physicsOrder.txt

@@ -0,0 +1,600 @@
+1 0 0 0
+393 255 255 255
+2 0 0 0
+3 0 0 0
+387 255 255 255
+4 0 0 0
+5 0 0 0
+397 255 255 255
+6 0 0 0
+7 255 255 255
+407 0 0 0
+8 255 255 255
+9 0 0 0
+401 0 0 0
+10 0 0 0
+11 0 0 0
+395 255 255 255
+12 0 0 0
+13 0 0 0
+405 0 0 0
+14 0 0 0
+15 0 0 0
+415 0 0 0
+16 0 0 0
+17 0 0 0
+409 0 0 0
+18 0 0 0
+19 0 0 0
+403 0 0 0
+20 0 0 0
+21 0 0 0
+413 0 0 0
+22 0 0 0
+23 0 0 0
+487 255 255 255
+24 255 255 255
+25 0 0 0
+481 0 0 0
+26 0 0 0
+27 0 0 0
+411 255 255 255
+28 0 0 0
+29 0 0 0
+485 255 255 255
+30 0 0 0
+31 0 0 0
+431 255 255 255
+32 0 0 0
+33 0 0 0
+425 255 255 255
+34 0 0 0
+35 0 0 0
+419 255 255 255
+36 0 0 0
+37 0 0 0
+429 255 255 255
+38 0 0 0
+39 255 255 255
+439 0 0 0
+40 0 0 0
+41 0 0 0
+433 255 255 255
+42 0 0 0
+43 255 255 255
+427 0 0 0
+44 0 0 0
+45 0 0 0
+437 255 255 255
+46 0 0 0
+47 0 0 0
+447 0 0 0
+48 0 0 0
+49 0 0 0
+441 255 255 255
+50 0 0 0
+51 0 0 0
+435 255 255 255
+52 0 0 0
+53 0 0 0
+445 255 255 255
+54 0 0 0
+55 0 0 0
+391 0 0 0
+56 0 0 0
+57 0 0 0
+385 0 0 0
+58 0 0 0
+59 0 0 0
+443 255 255 255
+60 0 0 0
+61 0 0 0
+389 0 0 0
+62 0 0 0
+63 0 0 0
+463 0 0 0
+64 255 255 255
+65 0 0 0
+457 0 0 0
+66 0 0 0
+67 213 213 213
+451 255 255 255
+68 0 0 0
+69 0 0 0
+461 0 0 0
+70 0 0 0
+71 0 0 0
+471 0 0 0
+72 0 0 0
+73 255 255 255
+465 0 0 0
+74 0 0 0
+75 0 0 0
+459 0 0 0
+76 0 0 0
+77 255 255 255
+469 255 255 255
+78 0 0 0
+79 0 0 0
+479 255 255 255
+80 0 0 0
+81 0 0 0
+473 0 0 0
+82 0 0 0
+83 0 0 0
+467 255 255 255
+84 255 255 255
+85 255 255 255
+477 255 255 255
+86 0 0 0
+87 0 0 0
+88 0 0 0
+89 0 0 0
+90 0 0 0
+91 0 0 0
+475 255 255 255
+92 0 0 0
+93 0 0 0
+94 0 0 0
+95 0 0 0
+495 255 255 255
+96 0 0 0
+97 255 255 255
+489 255 255 255
+98 255 255 255
+99 255 255 255
+483 255 255 255
+100 0 0 0
+101 0 0 0
+493 0 0 0
+102 0 0 0
+103 0 0 0
+503 255 255 255
+104 0 0 0
+105 0 0 0
+497 255 255 255
+106 255 255 255
+107 255 255 255
+491 255 255 255
+108 0 0 0
+109 0 0 0
+501 220 220 220
+110 255 255 255
+111 255 255 255
+511 0 0 0
+112 255 255 255
+113 255 255 255
+505 255 255 255
+114 255 255 255
+115 255 255 255
+499 255 255 255
+116 0 0 0
+117 255 255 255
+509 0 0 0
+118 255 255 255
+119 255 255 255
+455 0 0 0
+120 255 255 255
+121 255 255 255
+449 255 255 255
+122 0 0 0
+123 255 255 255
+507 255 255 255
+124 0 0 0
+125 255 255 255
+453 255 255 255
+126 255 255 255
+127 255 255 255
+128 0 0 0
+314 255 255 255
+129 255 255 255
+130 0 0 0
+260 255 255 255
+131 255 255 255
+132 255 255 255
+318 0 0 0
+133 255 255 255
+134 255 255 255
+312 255 255 255
+135 255 255 255
+136 0 0 0
+258 255 255 255
+137 0 0 0
+138 0 0 0
+268 255 255 255
+139 0 0 0
+140 255 255 255
+262 255 255 255
+141 0 0 0
+142 255 255 255
+256 255 255 255
+143 255 255 255
+144 255 255 255
+266 0 0 0
+145 0 0 0
+146 255 255 255
+276 0 0 0
+147 0 0 0
+148 0 0 0
+270 0 0 0
+149 0 0 0
+150 0 0 0
+264 0 0 0
+151 0 0 0
+152 255 255 255
+274 255 255 255
+153 255 255 255
+154 0 0 0
+284 255 255 255
+155 0 0 0
+156 255 255 255
+278 255 255 255
+157 255 255 255
+158 255 255 255
+272 255 255 255
+159 0 0 0
+160 255 255 255
+161 255 255 255
+162 255 255 255
+292 0 0 0
+163 0 0 0
+164 255 255 255
+165 255 255 255
+166 255 255 255
+167 255 255 255
+168 255 255 255
+290 0 0 0
+169 255 255 255
+170 255 255 255
+300 0 0 0
+171 255 255 255
+172 255 255 255
+294 0 0 0
+173 255 255 255
+174 255 255 255
+288 255 255 255
+175 255 255 255
+176 0 0 0
+298 255 255 255
+177 0 0 0
+178 0 0 0
+308 255 255 255
+179 0 0 0
+180 0 0 0
+302 255 255 255
+181 0 0 0
+182 0 0 0
+296 0 0 0
+183 0 0 0
+184 255 255 255
+306 255 255 255
+185 105 105 105
+186 0 0 0
+316 255 255 255
+187 0 0 0
+188 0 0 0
+310 255 255 255
+189 255 255 255
+190 255 255 255
+304 255 255 255
+191 255 255 255
+192 0 0 0
+378 187 187 187
+193 255 255 255
+194 0 0 0
+324 254 254 254
+195 255 255 255
+196 255 255 255
+382 0 0 0
+197 0 0 0
+198 255 255 255
+376 255 255 255
+199 255 255 255
+200 255 255 255
+322 0 0 0
+201 255 255 255
+202 255 255 255
+332 255 255 255
+203 255 255 255
+204 255 255 255
+326 0 0 0
+205 255 255 255
+206 0 0 0
+320 255 255 255
+207 0 0 0
+208 255 255 255
+330 0 0 0
+209 255 255 255
+210 255 255 255
+549 255 255 255
+340 255 255 255
+211 0 0 0
+212 254 254 254
+334 255 255 255
+213 255 255 255
+214 0 0 0
+328 0 0 0
+215 0 0 0
+216 255 255 255
+338 255 255 255
+217 0 0 0
+218 255 255 255
+557 255 255 255
+348 0 0 0
+219 255 255 255
+220 255 255 255
+342 255 255 255
+221 255 255 255
+222 255 255 255
+545 255 255 255
+336 255 255 255
+223 255 255 255
+224 255 255 255
+282 255 255 255
+225 255 255 255
+226 255 255 255
+356 0 0 0
+227 255 255 255
+228 255 255 255
+286 255 255 255
+229 255 255 255
+230 255 255 255
+280 255 255 255
+231 255 255 255
+232 255 255 255
+354 0 0 0
+233 255 255 255
+234 255 255 255
+364 255 255 255
+235 255 255 255
+236 255 255 255
+358 0 0 0
+237 255 255 255
+238 0 0 0
+352 0 0 0
+239 0 0 0
+240 0 0 0
+362 255 255 255
+241 0 0 0
+242 0 0 0
+372 255 255 255
+243 255 255 255
+244 0 0 0
+366 255 255 255
+245 0 0 0
+246 0 0 0
+360 255 255 255
+247 0 0 0
+248 255 255 255
+370 255 255 255
+249 255 255 255
+250 0 0 0
+380 234 234 234
+251 255 255 255
+252 0 0 0
+374 255 255 255
+253 255 255 255
+254 0 0 0
+368 255 255 255
+255 0 0 0
+257 255 255 255
+259 255 255 255
+261 255 255 255
+263 255 255 255
+265 255 255 255
+267 255 255 255
+269 255 255 255
+271 0 0 0
+273 255 255 255
+275 255 255 255
+277 0 0 0
+279 255 255 255
+281 255 255 255
+283 255 255 255
+285 255 255 255
+287 255 255 255
+592 0 0 0
+289 255 255 255
+291 243 243 243
+596 0 0 0
+293 0 0 0
+295 0 0 0
+600 0 0 0
+297 0 0 0
+299 255 255 255
+301 0 0 0
+303 255 255 255
+305 255 255 255
+307 255 255 255
+309 255 255 255
+311 255 255 255
+313 255 255 255
+315 255 255 255
+317 0 0 0
+319 0 0 0
+321 0 0 0
+323 0 0 0
+325 0 0 0
+327 0 0 0
+329 0 0 0
+331 255 255 255
+333 255 255 255
+335 255 255 255
+337 255 255 255
+339 255 255 255
+341 255 255 255
+343 255 255 255
+553 255 255 255
+344 255 255 255
+345 0 0 0
+346 0 0 0
+347 0 0 0
+349 0 0 0
+350 0 0 0
+351 0 0 0
+353 0 0 0
+355 0 0 0
+357 0 0 0
+359 255 255 255
+361 255 255 255
+363 255 255 255
+365 255 255 255
+367 255 255 255
+369 255 255 255
+371 255 255 255
+373 255 255 255
+375 255 255 255
+377 255 255 255
+379 0 0 0
+381 255 255 255
+383 0 0 0
+529 0 0 0
+384 255 255 255
+386 0 0 0
+533 0 0 0
+388 255 255 255
+390 255 255 255
+537 0 0 0
+392 255 255 255
+394 255 255 255
+541 0 0 0
+396 255 255 255
+398 255 255 255
+399 255 255 255
+400 0 0 0
+402 0 0 0
+404 0 0 0
+406 0 0 0
+408 0 0 0
+410 255 255 255
+412 255 255 255
+414 0 0 0
+561 0 0 0
+416 254 254 254
+417 242 242 242
+418 255 255 255
+565 0 0 0
+420 255 255 255
+421 255 255 255
+422 255 255 255
+423 255 255 255
+569 0 0 0
+424 255 255 255
+426 255 255 255
+573 255 255 255
+428 0 0 0
+430 255 255 255
+513 0 0 0
+432 255 255 255
+434 255 255 255
+517 0 0 0
+436 255 255 255
+438 0 0 0
+521 0 0 0
+440 0 0 0
+442 255 255 255
+525 0 0 0
+444 255 255 255
+446 0 0 0
+593 255 255 255
+448 255 255 255
+450 255 255 255
+597 255 255 255
+452 255 255 255
+454 255 255 255
+456 233 233 233
+458 0 0 0
+460 0 0 0
+462 0 0 0
+464 0 0 0
+466 255 255 255
+468 255 255 255
+470 0 0 0
+472 0 0 0
+474 255 255 255
+476 255 255 255
+478 255 255 255
+480 255 255 255
+482 0 0 0
+484 0 0 0
+486 0 0 0
+488 0 0 0
+490 255 255 255
+492 255 255 255
+494 0 0 0
+577 0 0 0
+496 255 255 255
+498 255 255 255
+581 0 0 0
+500 255 255 255
+502 0 0 0
+585 0 0 0
+504 0 0 0
+506 255 255 255
+589 0 0 0
+508 254 254 254
+510 0 0 0
+512 0 0 0
+514 0 0 0
+515 255 255 255
+516 255 255 255
+518 255 255 255
+519 0 0 0
+520 0 0 0
+522 0 0 0
+523 0 0 0
+524 0 0 0
+526 0 0 0
+527 0 0 0
+528 0 0 0
+530 0 0 0
+531 255 255 255
+532 255 255 255
+534 0 0 0
+535 0 0 0
+536 0 0 0
+538 0 0 0
+539 0 0 0
+540 0 0 0
+542 255 255 255
+543 254 254 254
+544 255 255 255
+546 255 255 255
+547 255 255 255
+548 255 255 255
+550 255 255 255
+551 0 0 0
+552 255 255 255
+554 255 255 255
+555 255 255 255
+556 0 0 0
+558 0 0 0
+559 0 0 0
+560 0 0 0
+562 0 0 0
+563 0 0 0
+564 0 0 0
+566 0 0 0
+567 0 0 0
+568 0 0 0
+570 255 255 255
+571 255 255 255
+572 0 0 0
+574 255 255 255
+575 0 0 0
+576 0 0 0
+578 0 0 0
+579 0 0 0
+580 0 0 0
+582 0 0 0
+583 0 0 0
+584 0 0 0
+586 0 0 0
+587 0 0 0
+588 0 0 0
+590 0 0 0
+591 0 0 0
+594 0 0 0
+595 0 0 0
+598 0 0 0
+599 178 178 178

+ 2 - 13
Pika/thirdparty/ph2d/src/ph2d.cpp

@@ -1351,15 +1351,6 @@ namespace ph2d
 		else
 		{
 
-			//if (glm::length(motionState.velocity) < MIN_VELOCITY)
-			//{
-			//	motionState.velocity = glm::vec2(0.0f);
-			//}
-			//
-			//if (std::abs(motionState.angularVelocity) < MIN_ANGULAR_VELOCITY)
-			//{
-			//	motionState.angularVelocity = 0.0f;
-			//}
 
 			//linear motion
 			motionState.acceleration = glm::clamp(motionState.acceleration,
@@ -1403,14 +1394,12 @@ namespace ph2d
 			//rotation
 			motionState.angularVelocity += motionState.torque * (1.f/motionState.momentOfInertia) * deltaTime;
 
-			float toAdd = motionState.angularVelocity;
-			if (std::abs(toAdd) < s.restingAngularVelocity)
+			if (std::abs(motionState.angularVelocity) < s.restingAngularVelocity)
 			{
-				toAdd = {};
 				motionState.angularVelocity = 0;
 			}
 
-			motionState.rotation += toAdd * deltaTime;
+			motionState.rotation += motionState.angularVelocity * deltaTime;
 			motionState.torque = 0;
 		}