Lab 1 / variant 1
This commit is contained in:
parent
69e67e5802
commit
3a80069160
6
programs/lab1/src/variants/common.hpp
Normal file
6
programs/lab1/src/variants/common.hpp
Normal file
@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
namespace BGTU::ComputerGraphicsLabWork::Lab1 {
|
||||
|
||||
}
|
@ -1,8 +1,10 @@
|
||||
#include <tuple>
|
||||
#include <bgtu/computer_graphics_lab_work/renderer_api/sprite.hpp>
|
||||
#include <bgtu/computer_graphics_lab_work/utilities/shapes/polygon.hpp>
|
||||
#include <bgtu/computer_graphics_lab_work/utilities/shapes/circle.hpp>
|
||||
#include "../variants.hpp"
|
||||
#include "../sprite_data.hpp"
|
||||
#include "common.hpp"
|
||||
|
||||
namespace BGTU::ComputerGraphicsLabWork::Lab1 {
|
||||
namespace Variant1 {
|
||||
@ -15,7 +17,7 @@ namespace BGTU::ComputerGraphicsLabWork::Lab1 {
|
||||
Utilities::Shapes::draw_polygon_edge(
|
||||
frame,
|
||||
{data->neg_rotated(data->radius / 2, 0), data->neg_rotated(data->radius / 2, 90), data->neg_rotated(data->radius / 2, 180), data->neg_rotated(data->radius / 2, 270),},
|
||||
1,
|
||||
2,
|
||||
{255, 0, 0}
|
||||
);
|
||||
}
|
||||
@ -35,14 +37,65 @@ namespace BGTU::ComputerGraphicsLabWork::Lab1 {
|
||||
{-data->radius, 0},
|
||||
{0, -data->radius}
|
||||
},
|
||||
2,
|
||||
3,
|
||||
{0, 255, 255}
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
class S3 : public RendererApi::Sprite<Lab1SpriteData::ShapeData, Utilities::ZoomedVoxelPainter<Utilities::DefaultVoxelDrawerCache::VoxelPainterImpl>> {
|
||||
public:
|
||||
void draw(
|
||||
BGTU::ComputerGraphicsLabWork::Utilities::ZoomedVoxelPainter<BGTU::ComputerGraphicsLabWork::Utilities::DefaultVoxelDrawerCache::VoxelPainterImpl> *frame,
|
||||
const BGTU::ComputerGraphicsLabWork::Lab1::Lab1SpriteData::ShapeData *data
|
||||
) const final {
|
||||
Utilities::Shapes::draw_circle_edge(
|
||||
frame,
|
||||
{0, 0},
|
||||
data->radius,
|
||||
5,
|
||||
{0, 127, 255}
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
class S4 : public RendererApi::Sprite<Lab1SpriteData::ShapeData, Utilities::ZoomedVoxelPainter<Utilities::DefaultVoxelDrawerCache::VoxelPainterImpl>> {
|
||||
public:
|
||||
void draw(
|
||||
BGTU::ComputerGraphicsLabWork::Utilities::ZoomedVoxelPainter<BGTU::ComputerGraphicsLabWork::Utilities::DefaultVoxelDrawerCache::VoxelPainterImpl> *frame,
|
||||
const BGTU::ComputerGraphicsLabWork::Lab1::Lab1SpriteData::ShapeData *data
|
||||
) const final {
|
||||
Utilities::Shapes::draw_circle_edge(
|
||||
frame,
|
||||
{0, 0},
|
||||
data->radius / (2.0 * std::sqrt(2)),
|
||||
1,
|
||||
{127, 127, 127}
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
class S5 : public RendererApi::Sprite<Lab1SpriteData::ShapeData, Utilities::ZoomedVoxelPainter<Utilities::DefaultVoxelDrawerCache::VoxelPainterImpl>> {
|
||||
public:
|
||||
void draw(
|
||||
BGTU::ComputerGraphicsLabWork::Utilities::ZoomedVoxelPainter<BGTU::ComputerGraphicsLabWork::Utilities::DefaultVoxelDrawerCache::VoxelPainterImpl> *frame,
|
||||
const BGTU::ComputerGraphicsLabWork::Lab1::Lab1SpriteData::ShapeData *data
|
||||
) const final {
|
||||
auto r2 = data->radius / 2;
|
||||
Utilities::Shapes::draw_polygon_edge(
|
||||
frame,
|
||||
{
|
||||
{-r2, -r2},
|
||||
{-r2, r2},
|
||||
{r2, r2},
|
||||
{r2, -r2}
|
||||
},
|
||||
3,
|
||||
{0, 255, 0}
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
variant_sprites variant1 = variant_sprites::make(Variant1::S1{}, Variant1::S2{});
|
||||
variant_sprites variant1 = variant_sprites::make(Variant1::S1{}, Variant1::S2{}, Variant1::S3{}, Variant1::S4{}, Variant1::S5{});
|
||||
}
|
@ -0,0 +1,101 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdlib>
|
||||
#include <bgtu/computer_graphics_lab_work/renderer_api/point.hpp>
|
||||
|
||||
namespace BGTU::ComputerGraphicsLabWork::Utilities::Shapes {
|
||||
template<class receiver_t>
|
||||
void iterate_circle_edge(
|
||||
RendererApi::PointI<2>::component_t cx, RendererApi::PointI<2>::component_t cy,
|
||||
RendererApi::PointI<2>::component_t r,
|
||||
receiver_t receiver
|
||||
) {
|
||||
RendererApi::PointI<2>::component_t x = 0, y = r;
|
||||
while (x < y) {
|
||||
RendererApi::PointI<2>::component_t D1 = x * x + y * y - r * r;
|
||||
RendererApi::PointI<2>::component_t D2 = x * x + (y - 1) * (y - 1) - r * r;
|
||||
|
||||
if (D1 > -D2)
|
||||
y--;
|
||||
|
||||
receiver(cx + x, cy + y);
|
||||
receiver(cx + x, cy - y);
|
||||
receiver(cx + y, cy + x);
|
||||
receiver(cx + y, cy - x);
|
||||
receiver(cx - x, cy + y);
|
||||
receiver(cx - x, cy - y);
|
||||
receiver(cx - y, cy + x);
|
||||
receiver(cx - y, cy - x);
|
||||
x++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class receiver_t>
|
||||
void iterate_circle_edge(
|
||||
RendererApi::PointI<2> center,
|
||||
RendererApi::PointI<2>::component_t r,
|
||||
receiver_t receiver
|
||||
) {
|
||||
return iterate_circle_edge<receiver_t>(center.x, center.y, r, receiver);
|
||||
}
|
||||
|
||||
|
||||
template<class voxel_painter_t = RendererApi::VirtualVoxelPainter>
|
||||
void draw_circle_edge(
|
||||
voxel_painter_t *painter,
|
||||
RendererApi::PointI<2>::component_t cx, RendererApi::PointI<2>::component_t cy,
|
||||
RendererApi::PointI<2>::component_t r,
|
||||
double z,
|
||||
RendererApi::Color::Transparent outline
|
||||
) {
|
||||
iterate_circle_edge(
|
||||
cx, cy, r,
|
||||
[=](RendererApi::PointI<2>::component_t x, RendererApi::PointI<2>::component_t y) { painter->add_voxel(x, y, z, outline); }
|
||||
);
|
||||
}
|
||||
|
||||
template<class voxel_painter_t = RendererApi::VirtualVoxelPainter>
|
||||
void draw_circle_edge(
|
||||
voxel_painter_t *painter,
|
||||
RendererApi::PointI<2> center,
|
||||
RendererApi::PointI<2>::component_t r,
|
||||
double z,
|
||||
RendererApi::Color::Transparent outline
|
||||
) {
|
||||
iterate_circle_edge(
|
||||
center, r,
|
||||
[=](RendererApi::PointI<2>::component_t x, RendererApi::PointI<2>::component_t y) { painter->add_voxel(x, y, z, outline); }
|
||||
);
|
||||
}
|
||||
|
||||
template<class voxel_painter_t = RendererApi::VirtualVoxelPainter>
|
||||
void draw_circle_edge(
|
||||
voxel_painter_t *painter,
|
||||
RendererApi::PointI<2>::component_t cx, RendererApi::PointI<2>::component_t cy,
|
||||
RendererApi::PointI<2>::component_t r,
|
||||
double z,
|
||||
RendererApi::Color::Transparent outline,
|
||||
RendererApi::SpriteMetadata *owner
|
||||
) {
|
||||
iterate_circle_edge(
|
||||
cx, cy, r,
|
||||
[=](RendererApi::PointI<2>::component_t x, RendererApi::PointI<2>::component_t y) { painter->add_voxel(x, y, z, outline, owner); }
|
||||
);
|
||||
}
|
||||
|
||||
template<class voxel_painter_t = RendererApi::VirtualVoxelPainter>
|
||||
void draw_circle_edge(
|
||||
voxel_painter_t *painter,
|
||||
RendererApi::PointI<2> center,
|
||||
RendererApi::PointI<2>::component_t r,
|
||||
double z,
|
||||
RendererApi::Color::Transparent outline,
|
||||
RendererApi::SpriteMetadata *owner
|
||||
) {
|
||||
iterate_circle_edge(
|
||||
center, r,
|
||||
[=](RendererApi::PointI<2>::component_t x, RendererApi::PointI<2>::component_t y) { painter->add_voxel(x, y, z, outline, owner); }
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user