generated from sigonasr2/CPlusPlusProjectTemplate
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
1.5 KiB
71 lines
1.5 KiB
2 years ago
|
#define OLC_PGE_APPLICATION
|
||
|
#include "pixelGameEngine.h"
|
||
|
|
||
|
using namespace olc;
|
||
|
|
||
|
class Circles : public olc::PixelGameEngine
|
||
|
{
|
||
|
public:
|
||
|
Circles()
|
||
|
{
|
||
|
sAppName = "Circles";
|
||
|
}
|
||
|
|
||
|
public:
|
||
|
|
||
|
int CIRCLE_PRECISION=32;
|
||
|
|
||
|
void DrawCircleDecal(vf2d pos,float radius,Pixel col=WHITE) {
|
||
|
std::vector<vf2d> poly;
|
||
|
std::vector<vf2d> uvs;
|
||
|
for (int i=0;i<CIRCLE_PRECISION;i++) {
|
||
|
poly.push_back({pos.x+sinf(2*M_PI/CIRCLE_PRECISION*i)*radius,pos.y+cosf(2*M_PI/CIRCLE_PRECISION*i)*radius});
|
||
|
uvs.push_back({0,0});
|
||
|
}
|
||
|
poly.push_back(poly[0]);
|
||
|
uvs.push_back({0,0});
|
||
|
SetDecalStructure(DecalStructure::LINE);
|
||
|
SetDecalMode(DecalMode::WIREFRAME);
|
||
|
DrawPolygonDecal(nullptr,poly,uvs,col);
|
||
|
SetDecalMode(DecalMode::NORMAL);
|
||
|
SetDecalStructure(DecalStructure::FAN);
|
||
|
}
|
||
|
void FillCircleDecal(vf2d pos,float radius,Pixel col=WHITE) {
|
||
|
std::vector<vf2d> poly;
|
||
|
std::vector<vf2d> uvs;
|
||
|
poly.push_back(pos);
|
||
|
uvs.push_back({0,0});
|
||
|
for (int i=0;i<CIRCLE_PRECISION;i++) {
|
||
|
poly.push_back({pos.x+sinf(2*M_PI/CIRCLE_PRECISION*i)*radius,pos.y+cosf(2*M_PI/CIRCLE_PRECISION*i)*radius});
|
||
|
uvs.push_back({0,0});
|
||
|
}
|
||
|
poly.push_back(poly[1]);
|
||
|
uvs.push_back({0,0});
|
||
|
DrawPolygonDecal(nullptr,poly,uvs,col);
|
||
|
}
|
||
|
|
||
|
bool OnUserCreate() override
|
||
|
{
|
||
|
// Called once at the start, so create things here
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
bool OnUserUpdate(float fElapsedTime) override
|
||
|
{
|
||
|
// called once per frame
|
||
|
DrawCircleDecal({50,50},10,BLUE);
|
||
|
FillCircleDecal({100,100},20,GREEN);
|
||
|
return true;
|
||
|
}
|
||
|
};
|
||
|
|
||
|
|
||
|
int main()
|
||
|
{
|
||
|
Circles demo;
|
||
|
if (demo.Construct(256, 240, 4, 4))
|
||
|
demo.Start();
|
||
|
|
||
|
return 0;
|
||
|
}
|