Код: Выделить всё
#ifdef __APPLE__
#include
#else
#include
#endif
#include
#include
#include
#include
#include
#include
#include
#include
typedef struct point
{
float x;
float y;
}point;
typedef struct color
{
float r;
float g;
float b;
}color;
int number_of_segments = 200;
float logX = 200;
float logY = 200;
int PhyWidth = 1000;
int PhyHeight = 1000;
int windowPosX = 500;
int windowPosY = 500;
float centerX = logX / 2;
float centerY = logY / 2;
int alphaX = 0;
int alphaY = 0;
typedef unsigned char u8;
class square
{
private:
std::array
pts;
float width;
float height;
bool filled;
float max_x;
float min_x;
float max_y;
float min_y;
int id;
bool eaten = false;
color colour = {1.0, 1.0, 1.0};
bool main;
public:
square(point pt, int width, int height, bool filled, bool main)
{
this->width = width;
this->height = height;
this->filled = filled;
this->main = main;
float half_width = width/2;
float half_height = height/2;
min_x = pt.x - half_width;
max_x = pt.x + half_width;
min_y = pt.y - half_height;
max_y = pt.y + half_height;
this->pts[0] = {min_x, min_y};
this->pts[1] = {max_x, min_y};
this->pts[2] = {max_x, max_y};
this->pts[3] = {min_x, max_y};
}
square(point pt, int width, int height, bool main, color colour, int id)
{
this->id = id;
this->width = width;
this->height = height;
this->main = main;
this->colour = colour;
float half_width = width/2;
float half_height = height/2;
min_x = pt.x - half_width;
max_x = pt.x + half_width;
min_y = pt.y - half_height;
max_y = pt.y + half_height;
this->pts[0] = {min_x, min_y};
this->pts[1] = {max_x, min_y};
this->pts[2] = {max_x, max_y};
this->pts[3] = {min_x, max_y};
}
std::array get_pts()
{
return this->pts;
}
void set_eaten()
{
this->eaten = true;
}
bool get_eaten()
{
return eaten;
}
void draw()
{
int alphaX_copy = 0;
int alphaY_copy = 0;
if(main)
{
alphaX_copy = alphaX;
alphaY_copy = alphaY;
}
glColor4f(colour.r, colour.g, colour.b, 1);
glBegin(GL_POLYGON);
glVertex2f(this->pts[0].x + alphaX_copy, this->pts[0].y + alphaY_copy);
glVertex2f(this->pts[1].x + alphaX_copy, this->pts[1].y + alphaY_copy);
glVertex2f(this->pts[2].x + alphaX_copy, this->pts[2].y + alphaY_copy);
glVertex2f(this->pts[3].x + alphaX_copy, this->pts[3].y + alphaY_copy);
glEnd();
}
static bool intersected_squares(square& big_square, square& small_square)
{
for (size_t i = 0; i < 4; i++)
{
if( small_square.pts[i].x > (big_square.min_x + alphaX) && small_square.pts[i].x < (big_square.max_x + alphaX))
{
// means in the range of x
if(small_square.pts[i].y > (big_square.min_y + alphaY) && small_square.pts[i].y < (big_square.max_y + alphaY))
{
// std::cout
Подробнее здесь: [url]https://stackoverflow.com/questions/78462296/what-is-causing-the-memory-leaks[/url]