diff --git a/2dgk_6/2dgk_6/2dgk_6.vcxproj b/2dgk_6/2dgk_6/2dgk_6.vcxproj
index 89140f3..daf4610 100644
--- a/2dgk_6/2dgk_6/2dgk_6.vcxproj
+++ b/2dgk_6/2dgk_6/2dgk_6.vcxproj
@@ -154,11 +154,12 @@
+
-
+
@@ -166,10 +167,10 @@
+
-
diff --git a/2dgk_6/2dgk_6/2dgk_6.vcxproj.filters b/2dgk_6/2dgk_6/2dgk_6.vcxproj.filters
index e06774f..55e4241 100644
--- a/2dgk_6/2dgk_6/2dgk_6.vcxproj.filters
+++ b/2dgk_6/2dgk_6/2dgk_6.vcxproj.filters
@@ -18,9 +18,6 @@
Source Files
-
- Source Files
-
Source Files
@@ -30,6 +27,12 @@
Source Files
+
+ Source Files
+
+
+ Source Files
+
@@ -44,9 +47,6 @@
Header Files
-
- Header Files
-
Header Files
@@ -59,5 +59,8 @@
Header Files
+
+ Header Files
+
\ No newline at end of file
diff --git a/2dgk_6/2dgk_6/Constants.h b/2dgk_6/2dgk_6/Constants.h
index e23a090..f248345 100644
--- a/2dgk_6/2dgk_6/Constants.h
+++ b/2dgk_6/2dgk_6/Constants.h
@@ -1,7 +1,7 @@
#pragma once
namespace KapitanGame {
namespace Constants {
- constexpr const char* WINDOW_TITLE = "2DGK - Zadanie 5";
+ constexpr const char* WINDOW_TITLE = "2DGK - Zadanie 7-8";
//Analog joystick dead zone
constexpr int JOYSTICK_DEAD_ZONE = 8000;
//Screen dimension constants
@@ -13,5 +13,6 @@ namespace KapitanGame {
constexpr int TILE_HEIGHT = 32;
constexpr float SPEED = 0.16f;
constexpr float SMOOTH = 0.4f;
+ constexpr int CIRCLES_COUNT = 100;
}
}
diff --git a/2dgk_6/2dgk_6/KCircle.cpp b/2dgk_6/2dgk_6/KCircle.cpp
new file mode 100644
index 0000000..5b10346
--- /dev/null
+++ b/2dgk_6/2dgk_6/KCircle.cpp
@@ -0,0 +1,78 @@
+#include "KCircle.h"
+
+#include
+#include
+
+#include "Constants.h"
+#include "Utils.h"
+
+namespace KapitanGame {
+ std::atomic KCircle::IdCounter{ 0 };
+
+ KCircle::KCircle(const KVector2D& position, const KVector2D& velocity, const float& radius, const KTexture& texture) : Id(++IdCounter),
+ Position(position),
+ Velocity(velocity),
+ Radius(radius),
+ Texture(texture) {
+ }
+
+ void KCircle::CollisionDetectionStep(const std::vector& circles, const bool& shouldSeparate, const bool& shouldReflect) {
+ for (auto& other : circles) {
+ if (other.Id == Id) continue;
+ if (IsCollision(other)) {
+ auto separationVector = GetSeparationVector(other);
+ if (shouldSeparate)
+ Position += separationVector;
+ if (shouldReflect)
+ {
+ separationVector.Normalize();
+ Velocity = Velocity.Reflect(separationVector);
+ }
+ }
+ }
+ }
+
+ void KCircle::MovementStep(const float& timeStep) {
+ //Velocity.Normalize();
+ //Velocity *= 100;
+ Position += Velocity * timeStep;
+ }
+
+ bool KCircle::IsCollision(const KCircle& other) const {
+ return (Position - other.Position).Length() < Radius + other.Radius;
+ }
+
+ KVector2D KCircle::GetSeparationVector(const KCircle& other) const {
+ const KVector2D centerDiff = Position - other.Position;
+ const float centerDiffLength = centerDiff.Length();
+ return centerDiff / centerDiffLength * (Radius + other.Radius - centerDiffLength);
+ }
+
+ void KCircle::Render(SDL_Renderer* renderer) const {
+ Texture.Render(renderer, static_cast(Position.X) - Texture.GetWidth() / 2, static_cast(Position.Y) - Texture.GetHeight() / 2);
+ }
+
+ void KCircle::CollisionDetectionWithMapStep(const SDL_Rect& map) {
+
+ if (Position.X - map.x - Radius < 0)
+ {
+ Position.X += -(Position.X - map.x - Radius);
+ Velocity = Velocity.Reflect({ -1.f, 0.f });
+ }
+ if (Position.X + Radius - map.w > 0)
+ {
+ Velocity = Velocity.Reflect({ 1.f, 0.f });
+ Position.X += -(Position.X - map.w + Radius);
+ }
+ if (Position.Y - Radius - map.y < 0) {
+ Position.Y += -(Position.Y - map.y - Radius);
+ Velocity = Velocity.Reflect({ 0.f, 1.f });
+ }
+ if (Position.Y + Radius - map.h > 0) {
+ Position.Y += -(Position.Y - map.h + Radius);
+ Velocity = Velocity.Reflect({ 0.f, -1.f });
+ }
+ }
+
+}
+
diff --git a/2dgk_6/2dgk_6/KCircle.h b/2dgk_6/2dgk_6/KCircle.h
new file mode 100644
index 0000000..4dcaa40
--- /dev/null
+++ b/2dgk_6/2dgk_6/KCircle.h
@@ -0,0 +1,31 @@
+#pragma once
+#include
+#include
+#include
+
+#include "KTexture.h"
+#include "KVector2d.h"
+
+namespace KapitanGame {
+ class KCircle
+ {
+ public:
+ KCircle(const KVector2D& position, const KVector2D& velocity, const float& radius, const KTexture& texture);
+
+ void CollisionDetectionStep(const std::vector& circles, const bool& shouldSeparate, const bool& shouldReflect);
+ void MovementStep(const float& timeStep);
+ bool IsCollision(const KCircle& other) const;
+ KVector2D GetSeparationVector(const KCircle& other) const;
+ void Render(SDL_Renderer* renderer) const;
+ void CollisionDetectionWithMapStep(const SDL_Rect& map);
+ const int Id;
+ static std::atomic IdCounter;
+ private:
+ KVector2D Position{ 0.f, 0.f };
+ KVector2D Velocity{ 0.f, 0.f };
+ float Radius{ 1.f };
+ const KTexture& Texture;
+ };
+}
+
+
diff --git a/2dgk_6/2dgk_6/KGame.cpp b/2dgk_6/2dgk_6/KGame.cpp
index 8aec477..e4f2091 100644
--- a/2dgk_6/2dgk_6/KGame.cpp
+++ b/2dgk_6/2dgk_6/KGame.cpp
@@ -13,7 +13,7 @@
#include "KVector2d.h"
namespace KapitanGame {
- KGame::KGame() {
+ KGame::KGame() : HasSeparation(true), HasCollision(true) {
//Initialize SDL
if (SDL_Init(SDL_INIT_VIDEO) < 0)
{
@@ -45,11 +45,8 @@ namespace KapitanGame {
KGame::~KGame() {
//Free loaded images
- for (int i = 0; i <= static_cast(TileType::Dot); ++i)
- TileTextures[i].Free();
- PlayerTexture.Free();
- PlayerTexture2.Free();
+ CircleTexture.Free();
Input.Free();
@@ -68,64 +65,11 @@ namespace KapitanGame {
//Loading success flag
bool success = true;
- if (!PlayerTexture.LoadFromFile("textures/player.bmp", Renderer))
+ if (!CircleTexture.LoadFromFile("textures/00.bmp", Renderer))
{
printf("Failed to load player texture image!\n");
success = false;
}
- if (!PlayerTexture2.LoadFromFile("textures/player2.bmp", Renderer))
- {
- printf("Failed to load player texture image!\n");
- success = false;
- }
-
- for (int i = static_cast(TileType::Default); i <= static_cast(TileType::Dot); ++i)
- {
- if (!TileTextures[i].LoadFromFile("textures/0" + std::to_string(i) + ".bmp", Renderer))
- {
- printf("Failed to load 0%d texture image!\n", i);
- success = false;
- }
- }
-
- Tiles.clear();
- std::ifstream levelFile;
- levelFile.open("level.txt");
- if (levelFile.fail())
- {
- printf("Failed to load level.txt!\n");
- success = false;
- }
- else
- {
- int y = 0;
- std::string line;
- while (std::getline(levelFile, line)) {
- if (MapWidth < static_cast(line.length() * Constants::TILE_WIDTH))
- MapWidth = static_cast(line.length()) * Constants::TILE_WIDTH;
- for (auto i = 0ull; i < line.length(); ++i) {
- auto type = TileType::Default;
- switch (line[i])
- {
- case '|':
- type = TileType::VerticalWall;
- break;
- case '-':
- type = TileType::HorizontalWall;
- break;
- case '.':
- type = TileType::Dot;
- break;
- default:;
- }
- Tiles.emplace_back(i * Constants::TILE_WIDTH, y * Constants::TILE_HEIGHT, type);
- }
- ++y;
- }
- MapHeight = y * Constants::TILE_HEIGHT;
- levelFile.close();
- }
-
return success;
}
@@ -170,51 +114,21 @@ namespace KapitanGame {
//Event handler
SDL_Event e;
- SDL_Rect viewport;
- viewport.x = Constants::SCREEN_WIDTH / 2;
- viewport.y = Constants::SCREEN_HEIGHT / 2;
- viewport.w = Constants::SCREEN_WIDTH;
- viewport.h = Constants::SCREEN_HEIGHT;
+ SDL_Rect map{ 0,0,Constants::SCREEN_WIDTH, Constants::SCREEN_HEIGHT };
- KVector2D playerOnePosition(0, 0);
- KVector2D playerOneInput(0, 0);
- KVector2D playerOneVelocity(0, 0);
-
- KVector2D playerTwoPosition(0, 0);
- KVector2D playerTwoInput(0, 0);
- KVector2D playerTwoVelocity(0, 0);
-
- SDL_Rect playerAreaModeGauntlet;
- playerAreaModeGauntlet.x = 0;
- playerAreaModeGauntlet.y = 0;
- playerAreaModeGauntlet.w = Constants::SCREEN_WIDTH - Constants::WINDOW_DEAD_ZONE;
- playerAreaModeGauntlet.h = Constants::SCREEN_HEIGHT - Constants::WINDOW_DEAD_ZONE;
-
-
- SDL_Rect playerAreaModeZoom;
- playerAreaModeZoom.x = 0;
- playerAreaModeZoom.y = 0;
- playerAreaModeZoom.w = (MapWidth <= MapHeight ? MapWidth : static_cast(static_cast(MapHeight) * Constants::SCREEN_RATIO)) - Constants::WINDOW_DEAD_ZONE;
- playerAreaModeZoom.h = (MapHeight <= MapWidth ? MapHeight : static_cast(static_cast(MapWidth) / Constants::SCREEN_RATIO)) - Constants::WINDOW_DEAD_ZONE;
-
- float scale = 1.f;
-
- //Normalized direction
- int xDir = 0;
- int yDir = 0;
-
- uint32_t time, previousTime;
- time = previousTime = SDL_GetTicks();
+ for (int i = 0; i < Constants::CIRCLES_COUNT; ++i) {
+ KVector2D position(Utils::RandomNumber() * (Constants::SCREEN_WIDTH - 2 * CircleTexture.GetWidth()) + CircleTexture.GetWidth(), Utils::RandomNumber() * (Constants::SCREEN_HEIGHT - 2 * CircleTexture.GetHeight()) + CircleTexture.GetHeight());
+ Circles.emplace_back(position, KVector2D(100.f, 100.f), CircleTexture.GetWidth() / 2, CircleTexture);
+ }
+ uint32_t previousTime;
+ uint32_t time = previousTime = SDL_GetTicks();
printf("\n");
- bool zoom = false;
//While application is running
while (!quit)
{
previousTime = time;
time = SDL_GetTicks();
- playerOneInput.X = 0;
- playerOneInput.Y = 0;
Input.HandleInputPreEvents();
@@ -231,123 +145,31 @@ namespace KapitanGame {
}
Input.HandleInputPostEvents();
- playerTwoInput.X = Input.GetControllerAxis(Controllers::Controller1, SDL_CONTROLLER_AXIS_LEFTX);
- playerTwoInput.Y = Input.GetControllerAxis(Controllers::Controller1, SDL_CONTROLLER_AXIS_LEFTY);
-
- if (Input.IsKeyboardButtonHeld(SDL_SCANCODE_W))
+ if (Input.IsKeyboardButtonPressed(SDL_SCANCODE_S) || Input.IsControllerButtonPressed(Controllers::Controller1, SDL_CONTROLLER_BUTTON_START))
{
- playerOneInput.Y = -1;
+ HasSeparation = !HasSeparation;
}
- if (Input.IsKeyboardButtonHeld(SDL_SCANCODE_S))
+ if (Input.IsKeyboardButtonPressed(SDL_SCANCODE_C) || Input.IsControllerButtonPressed(Controllers::Controller1, SDL_CONTROLLER_BUTTON_BACK))
{
- playerOneInput.Y = 1;
- }
- if (Input.IsKeyboardButtonHeld(SDL_SCANCODE_A))
- {
- playerOneInput.X = -1;
- }
- if (Input.IsKeyboardButtonHeld(SDL_SCANCODE_D))
- {
- playerOneInput.X = 1;
+ HasCollision = !HasCollision;
}
- playerOneInput.Normalize();
- playerOneVelocity = playerOneInput * Constants::SPEED * (1 - Constants::SMOOTH) + playerOneVelocity * Constants::SMOOTH;
- playerOnePosition += playerOneVelocity;
+ for (auto& circle : Circles)
+ circle.CollisionDetectionStep(Circles, HasSeparation, HasCollision);
- if (Input.IsKeyboardButtonPressed(SDL_SCANCODE_F))
- {
- zoom = !zoom;
- }
-
- const auto& playerArea = zoom ? playerAreaModeZoom : playerAreaModeGauntlet;
-
-
- // keep player one near player two
- if (playerOnePosition.X < playerTwoPosition.X - playerArea.w) playerOnePosition.X = playerTwoPosition.X - playerArea.w;
- if (playerOnePosition.X > playerTwoPosition.X + playerArea.w) playerOnePosition.X = playerTwoPosition.X + playerArea.w;
- if (playerOnePosition.Y < playerTwoPosition.Y - playerArea.h) playerOnePosition.Y = playerTwoPosition.Y - playerArea.h;
- if (playerOnePosition.Y > playerTwoPosition.Y + playerArea.h) playerOnePosition.Y = playerTwoPosition.Y + playerArea.h;
-
- // keep player one in map
- if (playerOnePosition.X < 0) playerOnePosition.X = 0;
- if (playerOnePosition.X > MapWidth - PlayerTexture.GetWidth()) playerOnePosition.X = (MapWidth - PlayerTexture.GetWidth());
- if (playerOnePosition.Y < 0) playerOnePosition.Y = (0);
- if (playerOnePosition.Y > MapHeight - PlayerTexture.GetHeight()) playerOnePosition.Y = (MapHeight - PlayerTexture.GetHeight());
-
- //playerTwoInput.Normalize();
- //printf("\r \rX:%f, Y:%f", playerTwoInput.x, playerTwoInput.y);
- playerTwoVelocity = playerTwoInput * Constants::SPEED * (1 - Constants::SMOOTH) + playerTwoVelocity * Constants::SMOOTH;
-
- playerTwoPosition += playerTwoVelocity;
-
-
- if (playerTwoPosition.X < playerOnePosition.X - static_cast(playerArea.w)) playerTwoPosition.X = playerOnePosition.X - playerArea.w;
- if (playerTwoPosition.X > playerOnePosition.X + playerArea.w) playerTwoPosition.X = playerOnePosition.X + playerArea.w;
- if (playerTwoPosition.Y < playerOnePosition.Y - playerArea.h) playerTwoPosition.Y = playerOnePosition.Y - playerArea.h;
- if (playerTwoPosition.Y > playerOnePosition.Y + playerArea.h) playerTwoPosition.Y = playerOnePosition.Y + playerArea.h;
-
- if (playerTwoPosition.X < 0) playerTwoPosition.X = 0;
- if (playerTwoPosition.X > MapWidth - PlayerTexture.GetWidth()) playerTwoPosition.X = MapWidth - PlayerTexture.GetWidth();
- if (playerTwoPosition.Y < 0) playerTwoPosition.Y = 0;
- if (playerTwoPosition.Y > MapHeight - PlayerTexture.GetHeight()) playerTwoPosition.Y = MapHeight - PlayerTexture.GetHeight();
-
-
- scale = 1.f;
- if (zoom)
- {
- float xDist = std::abs(playerTwoPosition.X - playerOnePosition.X) - playerAreaModeGauntlet.w;
- float yDist = std::abs(playerTwoPosition.Y - playerOnePosition.Y) - playerAreaModeGauntlet.h;
- float xMaxDist = playerAreaModeZoom.w - playerAreaModeGauntlet.w;
- float yMaxDist = playerAreaModeZoom.h - playerAreaModeGauntlet.h;
- float t1 = Utils::Clamp(xDist / xMaxDist);
- float t2 = Utils::Clamp(yDist / yMaxDist);
- float t = std::max(std::max(t1, 0.f), std::max(t2, 0.f));
- scale = Utils::Lerp(scale, std::max(Constants::SCREEN_WIDTH * 1.0f / MapWidth, Constants::SCREEN_HEIGHT * 1.0f / MapHeight), t);
- //printf("\rscale: %f, t1: %f, t2: %f, t: %f", scale, t1, t2, t);
- }
-
- KVector2D focusPoint = (playerOnePosition + playerTwoPosition + KVector2D(PlayerTexture.GetWidth(), PlayerTexture.GetHeight())+KVector2D(Constants::WINDOW_DEAD_ZONE, Constants::WINDOW_DEAD_ZONE)/2)*scale/2;
- if (Input.IsKeyboardButtonHeld(SDL_SCANCODE_Q))
- {
- focusPoint = KVector2D(MapWidth / 2.f, MapHeight / 2.f);
- }
-
- //viewport.x += clamp((time - previous_time) * .05f) * (focusPoint.x - SCREEN_WIDTH / 2 - viewport.x);
- viewport.x = Utils::Lerp(viewport.x, static_cast(focusPoint.X - Constants::SCREEN_WIDTH / 2.f), static_cast(time - previousTime) * .05f);
- if ((focusPoint.X - Constants::SCREEN_WIDTH / 2.f) - static_cast(viewport.x) <= 0.005f)
- {
- viewport.x = static_cast(focusPoint.X - Constants::SCREEN_WIDTH / 2.f)/scale;
- }
- viewport.y = Utils::Lerp(viewport.y, static_cast(focusPoint.Y - Constants::SCREEN_HEIGHT / 2.f), static_cast(time - previousTime) * .05f);
- if (focusPoint.Y - static_cast(Constants::SCREEN_HEIGHT) / 2.0f - static_cast(viewport.y) <= 0.005f)
- {
- viewport.y = static_cast(focusPoint.Y - Constants::SCREEN_HEIGHT / 2.f) / scale;
- }
- if (viewport.x < 0)
- viewport.x = 0;
- if (viewport.y < 0)
- viewport.y = 0;
- if (viewport.x > MapWidth - static_cast(static_cast(viewport.w) / scale))
- viewport.x = MapWidth - static_cast(static_cast(viewport.w) / scale);
- if (viewport.y > MapHeight - static_cast(static_cast(viewport.h) / scale))
- viewport.y = MapHeight - static_cast(static_cast(viewport.h) / scale);
-
- //printf("\rp1(%f, %f), p2(%f, %f), viewport:(%d, %d, %d, %d), map(%d, %d), focus(%f, %f)", playerOnePosition.X * scale, playerOnePosition.Y * scale, playerTwoPosition.X * scale, playerTwoPosition.Y * scale, static_cast(viewport.x * scale), static_cast(viewport.y * scale), static_cast(static_cast(viewport.w) / scale), static_cast(static_cast(viewport.h) / scale), MapWidth, MapHeight, focusPoint.X, focusPoint.Y);
+ for (auto& circle : Circles)
+ circle.CollisionDetectionWithMapStep(map);
+ for (auto& circle : Circles)
+ circle.MovementStep(static_cast(time - previousTime) / 1000.f);
//Clear screen
SDL_SetRenderDrawColor(Renderer, 0, 0xFF, 0, 0xFF);
SDL_RenderClear(Renderer);
-
-
- for (auto& tile : Tiles)
- tile.Render(Renderer, TileTextures, viewport, scale);
-
- PlayerTexture.Render(Renderer, playerOnePosition.X - viewport.x, playerOnePosition.Y - viewport.y, nullptr, scale);
- PlayerTexture2.Render(Renderer, playerTwoPosition.X - viewport.x, playerTwoPosition.Y - viewport.y, nullptr, scale);
+ for (auto& circle : Circles)
+ circle.Render(Renderer);
//Update screen
SDL_RenderPresent(Renderer);
diff --git a/2dgk_6/2dgk_6/KGame.h b/2dgk_6/2dgk_6/KGame.h
index f3126d9..23d0e8f 100644
--- a/2dgk_6/2dgk_6/KGame.h
+++ b/2dgk_6/2dgk_6/KGame.h
@@ -1,13 +1,13 @@
#pragma once
#include "KTexture.h"
#include
-#include
+#include
+#include "KCircle.h"
#include "KInput.h"
namespace KapitanGame {
- class KTile;
class KGame
{
@@ -24,15 +24,13 @@ namespace KapitanGame {
SDL_Renderer* Renderer = nullptr;
- KTexture TileTextures[4];
- KTexture PlayerTexture;
- KTexture PlayerTexture2;
- std::vector Tiles;
+ KTexture CircleTexture;
- int MapHeight = -1;
- int MapWidth = -1;
+ std::vector Circles;
KInput Input;
-
+ bool HasSeparation;
+ bool HasCollision;
+ private:
bool LoadMedia();
SDL_Texture* LoadTexture(const std::string& path) const;
diff --git a/2dgk_6/2dgk_6/KVector2d.h b/2dgk_6/2dgk_6/KVector2d.h
index 339b01a..5ff7cfe 100644
--- a/2dgk_6/2dgk_6/KVector2d.h
+++ b/2dgk_6/2dgk_6/KVector2d.h
@@ -9,6 +9,11 @@ namespace KapitanGame {
KVector2D(const float x, const float y) : X(x), Y(y) {}
float Length() const { return sqrt(X * X + Y * Y); }
+ float Length2() const { return X * X + Y * Y; }
+
+ bool operator==(const KVector2D& v2) const {
+ return (*this - v2).Length2() < FLT_EPSILON * FLT_EPSILON;
+ }
KVector2D operator+(const KVector2D& v2) const {
return { X + v2.X, Y + v2.Y };
@@ -49,6 +54,12 @@ namespace KapitanGame {
Y /= scalar;
return *this;
}
+ float DotProduct(const KVector2D& v2) const {
+ return DotProduct(*this, v2);
+ }
+ KVector2D Reflect(const KVector2D& normal) const {
+ return Reflect(normal, *this);
+ }
void Normalize() {
const float l = Length();
@@ -56,6 +67,14 @@ namespace KapitanGame {
(*this) *= 1 / l;
}
}
+
+ static KVector2D Reflect(const KVector2D& normal, const KVector2D& vector) {
+ const float dn = 2 * vector.DotProduct(normal);
+ return vector - normal * dn;
+ }
+ static float DotProduct(const KVector2D& v1, const KVector2D& v2) {
+ return v1.X * v2.X + v1.Y * v2.Y ;
+ }
};
}
diff --git a/2dgk_6/2dgk_6/Utils.cpp b/2dgk_6/2dgk_6/Utils.cpp
new file mode 100644
index 0000000..6d102ff
--- /dev/null
+++ b/2dgk_6/2dgk_6/Utils.cpp
@@ -0,0 +1,16 @@
+#include "Utils.h"
+
+#include
+
+namespace KapitanGame {
+ namespace Utils {
+ double RandomNumber() {
+ // Making rng static ensures that it stays the same
+ // Between different invocations of the function
+ static std::default_random_engine rng(make_default_random_engine());
+
+ std::uniform_real_distribution dist(0.0, 1.0);
+ return dist(rng);
+ }
+ }
+}
diff --git a/2dgk_6/2dgk_6/Utils.h b/2dgk_6/2dgk_6/Utils.h
index 959b653..dc16e7f 100644
--- a/2dgk_6/2dgk_6/Utils.h
+++ b/2dgk_6/2dgk_6/Utils.h
@@ -2,6 +2,7 @@
#include
#include
#include
+#include
namespace KapitanGame {
namespace Utils {
@@ -16,15 +17,37 @@ namespace KapitanGame {
return std::string(buf.get(), buf.get() + size - 1); // We don't want the '\0' inside
}
template
- constexpr const T& Clamp(const T& x)
+ constexpr const T& Clamp01(const T& x)
{
- return std::max(std::min(1.f, x), 0.f);
+ return Clamp(x, 0.f, 1.f);
+ }
+ template
+ constexpr const T& Clamp(const T& x, const T& min, const T& max)
+ {
+ return std::max(std::min(max, x), min);
}
-
template
constexpr const T& Lerp(const T& a, const T& b, const float& t)
{
return a + (b - a) * t;
}
+
+ static std::default_random_engine make_default_random_engine()
+ {
+ // This gets a source of actual, honest-to-god randomness
+ std::random_device source;
+
+ // Here, we fill an array of random data from the source
+ unsigned int random_data[10];
+ for (auto& elem : random_data) {
+ elem = source();
+ }
+
+ // this creates the random seed sequence out of the random data
+ std::seed_seq seq(random_data + 0, random_data + 10);
+ return std::default_random_engine{ seq };
+ }
+
+ double RandomNumber();
}
}
\ No newline at end of file
diff --git a/2dgk_6/2dgk_6/textures/00.bmp b/2dgk_6/2dgk_6/textures/00.bmp
index 34f892e..7ffe609 100644
--- a/2dgk_6/2dgk_6/textures/00.bmp
+++ b/2dgk_6/2dgk_6/textures/00.bmp
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
-oid sha256:f46f203f44733ef973f3231b899951e6ab581739a57f3a3bab008ae5fe379711
+oid sha256:1dbb92f9be017b00038388d19298e8ee9b4da1cd54577c2b22b6b7ab8d81734a
size 3126
diff --git a/2dgk_6/2dgk_6/textures/01.bmp b/2dgk_6/2dgk_6/textures/01.bmp
deleted file mode 100644
index 563e1e1..0000000
--- a/2dgk_6/2dgk_6/textures/01.bmp
+++ /dev/null
@@ -1,3 +0,0 @@
-version https://git-lfs.github.com/spec/v1
-oid sha256:77efffc116983d8bc47f1866823f050823e035590f8bea75a050de01e052f0d5
-size 3126
diff --git a/2dgk_6/2dgk_6/textures/02.bmp b/2dgk_6/2dgk_6/textures/02.bmp
deleted file mode 100644
index 87bdec3..0000000
--- a/2dgk_6/2dgk_6/textures/02.bmp
+++ /dev/null
@@ -1,3 +0,0 @@
-version https://git-lfs.github.com/spec/v1
-oid sha256:744ed424d4794efdabecdfc0b8618d53de57f20b7229b12a0d1db40e1ecd9b30
-size 3126
diff --git a/2dgk_6/2dgk_6/textures/03.bmp b/2dgk_6/2dgk_6/textures/03.bmp
deleted file mode 100644
index adf47f9..0000000
--- a/2dgk_6/2dgk_6/textures/03.bmp
+++ /dev/null
@@ -1,3 +0,0 @@
-version https://git-lfs.github.com/spec/v1
-oid sha256:5ca36925a5793836bd24dbf79fbaa05f153d542cd11d2237bf69d51cea0ee13d
-size 3126
diff --git a/2dgk_6/2dgk_6/textures/player.bmp b/2dgk_6/2dgk_6/textures/player.bmp
deleted file mode 100644
index ab193d5..0000000
--- a/2dgk_6/2dgk_6/textures/player.bmp
+++ /dev/null
@@ -1,3 +0,0 @@
-version https://git-lfs.github.com/spec/v1
-oid sha256:71ab1fbb649b03c37d1aa219be3d1221ee6a4e6dd7c141bccf29a862de1cdd9a
-size 1878
diff --git a/2dgk_6/2dgk_6/textures/player2.bmp b/2dgk_6/2dgk_6/textures/player2.bmp
deleted file mode 100644
index d2f36d6..0000000
--- a/2dgk_6/2dgk_6/textures/player2.bmp
+++ /dev/null
@@ -1,3 +0,0 @@
-version https://git-lfs.github.com/spec/v1
-oid sha256:27e386557e6a6f069961b3abac29452491c283ec782bac480d4170b5b1ca6682
-size 1878