Cube.

When I rotate the object around OZ moves to the left.

Rotation around OX – the cube rises up.

Rotation around the OY-the cube is compressed.

The function I use for rotation:

```
void rotation(double angleX, double angleY, double angleZ, int x, int y, int z)
{
angleX = angleX * M_PI / 180;
angleY = angleY * M_PI / 180;
angleZ = angleZ * M_PI / 180;
double cX = cos(angleX);
double sX = sin(angleX);
double cY = cos(angleY);
double sY = sin(angleY);
double cZ = cos(angleZ);
double sZ = sin(angleZ);
double x0 = x;
double y0 = y * cX + z * sX;
double z0 = z * cX - y * sX;
double x1 = x0 * cY - z0 * sY;
double y1 = y0;
double z1 = z0 * cY + x0 * sY;
double x2 = x1 * cZ + y1 * sZ;
double y2 = y1 * cZ - x1 * sZ;
SDL_RenderDrawPoint(ren, x2, y2);
}
```

Full code:

```
#include <SDL.h>
#include <iostream>
#include <vector>
struct point
{
int x, y;
};
using namespace std;
int SCREEN_WIDTH = 640;
int SCREEN_HEIGHT = 480;
SDL_Window* win = NULL;
SDL_Renderer* ren = NULL;
void init() {
win = SDL_CreateWindow("Cube", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
ren = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED);
}
void quit() {
SDL_DestroyWindow(win);
win = NULL;
SDL_DestroyRenderer(ren);
ren = NULL;
SDL_Quit;
}
std::vector<point> lines(int centerX, int centerY)
{
std::vector<point> v;
//line 1
int x1 = centerX;
int y1 = centerY;
for (int i = 0; i < 100; i++)
{
x1 += 1;
v.push_back(point{ x1, y1 });
//SDL_RenderDrawPoint(ren, x1, y1);
}
//line 2
int x2 = x1;
int y2 = y1;
for (int i = 0; i < 100; i++)
{
y2 -= 1;
v.push_back(point{ x2, y2 });
//SDL_RenderDrawPoint(ren, x2, y2);
}
//line 3
int x3 = x2;
int y3 = y2;
for (int i = 0; i < 100; i++)
{
x3 -= 1;
v.push_back(point{ x3, y3 });
//SDL_RenderDrawPoint(ren, x3, y3);
}
//line 4
int x4 = x3;
int y4 = y3;
for (int i = 0; i < 100; i++)
{
y4 += 1;
v.push_back(point{ x4, y4 });
//SDL_RenderDrawPoint(ren, x4, y4);
}
//line 5
int x5 = x1;
int y5 = y1;
for (int i = 0; i < 50; i++)
{
y5 -= 1;
x5 += 1;
v.push_back(point{ x5, y5 });
//SDL_RenderDrawPoint(ren, x5, y5);
}
//line 6
int x6 = x5;
int y6 = y5;
for (int i = 0; i < 100; i++)
{
y6 -= 1;
v.push_back(point{ x6, y6 });
//SDL_RenderDrawPoint(ren, x6, y6);
}
//line 7
int x7 = x2;
int y7 = y2;
for (int i = 0; i < 50; i++)
{
y7 -= 1;
x7 += 1;
v.push_back(point{ x7, y7 });
//SDL_RenderDrawPoint(ren, x7, y7);
}
//line 8
int x8 = x7;
int y8 = y7;
for (int i = 0; i < 100; i++)
{
x8 -= 1;
v.push_back(point{ x8, y8 });
//SDL_RenderDrawPoint(ren, x8, y8);
}
//line 9
int x9 = x3;
int y9 = y3;
for (int i = 0; i < 50; i++)
{
y9 -= 1;
x9 += 1;
v.push_back(point{ x9, y9 });
//SDL_RenderDrawPoint(ren, x9, y9);
}
//line 10
int x10 = centerX;
int y10 = centerY;
for (int i = 0; i < 50; i++)
{
y10 -= 1;
x10 += 1;
v.push_back(point{ x10, y10 });
// SDL_RenderDrawPoint(ren, x10, y10);
}
//line 11
int x11 = x10;
int y11 = y10;
for (int i = 0; i < 100; i++)
{
x11 += 1;
v.push_back(point{ x11, y11 });
//SDL_RenderDrawPoint(ren, x11, y11);
}
//line 12
int x12 = x10;
int y12 = y10;
for (int i = 0; i < 100; i++)
{
y12 -= 1;
v.push_back(point{ x12, y12 });
//SDL_RenderDrawPoint(ren, x12, y12);
}
return v;
}
void rotation(double angleX, double angleY, double angleZ, int x, int y, int z)
{
angleX = angleX * M_PI / 180;
angleY = angleY * M_PI / 180;
angleZ = angleZ * M_PI / 180;
double cX = cos(angleX);
double sX = sin(angleX);
double cY = cos(angleY);
double sY = sin(angleY);
double cZ = cos(angleZ);
double sZ = sin(angleZ);
double x0 = x;
double y0 = y * cX + z * sX;
double z0 = z * cX - y * sX;
double x1 = x0 * cY - z0 * sY;
double y1 = y0;
double z1 = z0 * cY + x0 * sY;
double x2 = x1 * cZ + y1 * sZ;
double y2 = y1 * cZ - x1 * sZ;
SDL_RenderDrawPoint(ren, x2, y2);
}
int main(int arhc, char** argv) {
init();
SDL_SetRenderDrawColor(ren, 0xFF, 0xFF, 0xFF, 0xFF);
int centerX = SCREEN_WIDTH / 3;
int centerY = SCREEN_HEIGHT / 2 + 100;
int angleX = 0;
int angleY = 0;
int angleZ = 50;
auto v = lines(centerX, centerY);
for (int i = 0; i < 1000; i++)
rotation(angleX, angleY, angleZ, v(i).x, v(i).y, 100);
SDL_RenderPresent(ren);
SDL_Delay(500000);
quit();
return 0;
}
```

Used matrices. However, the result was the same.