remove utils

This commit is contained in:
= 2024-01-19 18:44:22 +01:00
parent 45ac2ffa68
commit 179f34db80
3 changed files with 0 additions and 59 deletions

View File

@ -25,7 +25,6 @@ add_executable(Pong main.cpp
SdlWrapper.h SdlWrapper.h
Game.h Game.h
VisibleObjects/Ball.h VisibleObjects/Ball.h
utils.h
Vec2d/Vec2d.h Vec2d/Vec2d.h
Vec2d/Bump.h Vec2d/Bump.h
VisibleObjects/PlayerPaddle.h VisibleObjects/PlayerPaddle.h

View File

@ -3,7 +3,6 @@
// //
#pragma once #pragma once
#include "../utils.h"
#include "../Vec2d/Vec2d.h" #include "../Vec2d/Vec2d.h"
#include "PlayerPaddle.h" #include "PlayerPaddle.h"
#include <SDL2/SDL2_gfxPrimitives.h> #include <SDL2/SDL2_gfxPrimitives.h>

57
utils.h
View File

@ -1,57 +0,0 @@
//
// Created by love on 2024-01-18.
//
#pragma once
#include "SDL.h"
int roundUpToMultipleOfEight(int v) {
return (v + (8 - 1)) & -8;
}
// https://stackoverflow.com/questions/38334081/how-to-draw-circles-arcs-and-vector-graphics-in-sdl
void DrawCircle(SDL_Renderer *renderer, SDL_Point &center, int radius) {
// 35 / 49 is a slightly biased approximation of 1/sqrt(2)
const int arrSize = roundUpToMultipleOfEight(radius * 8 * 35 / 49);
SDL_Point points[arrSize];
int drawCount = 0;
const int32_t diameter = (radius * 2);
int32_t x = (radius - 1);
int32_t y = 0;
int32_t tx = 1;
int32_t ty = 1;
int32_t error = (tx - diameter);
while (x >= y) {
// Each of the following renders an octant of the circle
points[drawCount + 0] = {center.x + x, center.y - y};
points[drawCount + 1] = {center.x + x, center.y + y};
points[drawCount + 2] = {center.x - x, center.y - y};
points[drawCount + 3] = {center.x - x, center.y + y};
points[drawCount + 4] = {center.x + y, center.y - x};
points[drawCount + 5] = {center.x + y, center.y + x};
points[drawCount + 6] = {center.x - y, center.y - x};
points[drawCount + 7] = {center.x - y, center.y + x};
drawCount += 8;
if (error <= 0) {
++y;
error += ty;
ty += 2;
}
if (error > 0) {
--x;
tx += 2;
error += (tx - diameter);
}
}
SDL_RenderDrawPoints(renderer, points, drawCount);
}