Hex texturing test

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
master
sigonasr2 2 years ago
parent efaceb4fa4
commit cfc22af487
  1. BIN
      C++ProjectTemplate
  2. BIN
      hexTex.png
  3. 67
      main.cpp

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 540 B

@ -3,58 +3,51 @@
using namespace olc; using namespace olc;
class Circles : public olc::PixelGameEngine class Hexes : public olc::PixelGameEngine
{ {
public: public:
Circles() Hexes()
{ {
sAppName = "Circles"; sAppName = "Hexes";
} }
public: public:
Decal*hexImg;
int CIRCLE_PRECISION=32; vf2d offset={100,100};
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 bool OnUserCreate() override
{ {
// Called once at the start, so create things here // Called once at the start, so create things here
hexImg = new Decal(new Sprite("hexTex.png"));
return true; return true;
} }
bool OnUserUpdate(float fElapsedTime) override bool OnUserUpdate(float fElapsedTime) override
{ {
if (GetKey(UP).bHeld) {
offset.y+=fElapsedTime*200;
}
if (GetKey(DOWN).bHeld) {
offset.y-=fElapsedTime*200;
}
if (GetKey(LEFT).bHeld) {
offset.x+=fElapsedTime*200;
}
if (GetKey(RIGHT).bHeld) {
offset.x-=fElapsedTime*200;
}
// called once per frame // called once per frame
DrawCircleDecal({50,50},10,BLUE); float scale=20;
FillCircleDecal({100,100},20,GREEN); for (int x=0;x<20;x++) {
for (int y=0;y<20;y++) {
vf2d offset2={(y&1?-0.45F*scale:0)+offset.x+x*0.9F*scale,y*scale*0.7F+offset.y};
DrawPolygonDecal(hexImg,{
{0+offset2.x,0.5F*scale+offset2.y},{-0.45F*scale+offset2.x,0.25F*scale+offset2.y},{0+offset2.x,0+offset2.y},{0.45F*scale+offset2.x,0.25F*scale+offset2.y},{0.45F*scale+offset2.x,0.75F*scale+offset2.y},{0+offset2.x,1*scale+offset2.y},{-0.45F*scale+offset2.x,0.75F*scale+offset2.y},{-0.45F*scale+offset2.x,0.25F*scale+offset2.y}
},{
{1,1},{0,1},{0,0},{0,1},{0,0},{0,1},{0,0},{0,1}
});
}
}
return true; return true;
} }
}; };
@ -62,7 +55,7 @@ public:
int main() int main()
{ {
Circles demo; Hexes demo;
if (demo.Construct(256, 240, 4, 4)) if (demo.Construct(256, 240, 4, 4))
demo.Start(); demo.Start();

Loading…
Cancel
Save