Make preparations for 3D flying effect integration.

This commit is contained in:
sigonasr2 2024-08-18 16:49:44 -05:00
parent 132710d800
commit 4fd6f22344
6 changed files with 1850 additions and 84 deletions

View File

@ -17,6 +17,7 @@ HamsterGame::HamsterGame(){
} }
bool HamsterGame::OnUserCreate(){ bool HamsterGame::OnUserCreate(){
olc::GFX3D::ConfigureDisplay();
camera=Camera2D{SCREEN_FRAME.size}; camera=Camera2D{SCREEN_FRAME.size};
camera.SetMode(Camera2D::Mode::LazyFollow); camera.SetMode(Camera2D::Mode::LazyFollow);
tv.Initialise(SCREEN_FRAME.size,{1,1}); tv.Initialise(SCREEN_FRAME.size,{1,1});
@ -26,6 +27,8 @@ bool HamsterGame::OnUserCreate(){
LoadLevel("TestLevel.tmx"); //THIS IS TEMPORARY. LoadLevel("TestLevel.tmx"); //THIS IS TEMPORARY.
border.ChangeBorder(Border::DEFAULT); border.ChangeBorder(Border::DEFAULT);
renderer.SetProjection(90.0f, (float)SCREEN_FRAME.size.y/(float)SCREEN_FRAME.size.x, 0.1f, 1000.0f, 0.0f, 0.0f, SCREEN_FRAME.size.x, SCREEN_FRAME.size.y);
return true; return true;
} }
@ -315,6 +318,9 @@ void HamsterGame::UpdateWaterTexture(){
animatedWaterTile.Decal()->Update(); animatedWaterTile.Decal()->Update();
} }
void HamsterGame::Apply3DTransform(std::vector<DecalInstance>&decals){
}
int main() int main()
{ {
HamsterGame game; HamsterGame game;

View File

@ -46,6 +46,7 @@ All rights reserved.
#include "TSXParser.h" #include "TSXParser.h"
#include "Terrain.h" #include "Terrain.h"
#include "SpecialRenderable.h" #include "SpecialRenderable.h"
#include "olcPGEX_Graphics3D.h"
struct Letter{ struct Letter{
vf2d pos; vf2d pos;
@ -102,4 +103,10 @@ private:
float updatePixelsTimer; float updatePixelsTimer;
Renderable animatedWaterTile; Renderable animatedWaterTile;
void UpdateWaterTexture(); void UpdateWaterTexture();
GFX3D::PipeLine renderer;
virtual void Apply3DTransform(std::vector<DecalInstance>&decals)override final;
const GFX3D::vec3d vUp = {0,1,0};
GFX3D::vec3d vEye = {0,0,-4};
const GFX3D::vec3d vLookDir = {0,0,1};
}; };

1728
src/olcPGEX_Graphics3D.h Normal file

File diff suppressed because it is too large Load Diff

View File

@ -575,17 +575,17 @@ namespace olc
void TransformedView::DrawDecal(const olc::vf2d & pos, olc::Decal * decal, const olc::vf2d & scale, const olc::Pixel & tint) void TransformedView::DrawDecal(const olc::vf2d & pos, olc::Decal * decal, const olc::vf2d & scale, const olc::Pixel & tint)
{ {
pge->DrawDecal(WorldToScreen(pos), decal, scale * m_vWorldScale * m_vRecipPixel, tint); pge->DrawDecal(WorldToScreen(pos), decal, scale * m_vWorldScale * m_vRecipPixel, tint,GFX3DTransform::TRANSFORM_REQUIRED);
} }
void TransformedView::DrawPartialDecal(const olc::vf2d & pos, olc::Decal * decal, const olc::vf2d & source_pos, const olc::vf2d & source_size, const olc::vf2d & scale, const olc::Pixel & tint) void TransformedView::DrawPartialDecal(const olc::vf2d & pos, olc::Decal * decal, const olc::vf2d & source_pos, const olc::vf2d & source_size, const olc::vf2d & scale, const olc::Pixel & tint)
{ {
pge->DrawPartialDecal(WorldToScreen(pos), decal, source_pos, source_size, scale * m_vWorldScale * m_vRecipPixel, tint); pge->DrawPartialDecal(WorldToScreen(pos), decal, source_pos, source_size, scale * m_vWorldScale * m_vRecipPixel, tint,GFX3DTransform::TRANSFORM_REQUIRED);
} }
void TransformedView::DrawPartialDecal(const olc::vf2d & pos, const olc::vf2d & size, olc::Decal * decal, const olc::vf2d & source_pos, const olc::vf2d & source_size, const olc::Pixel & tint) void TransformedView::DrawPartialDecal(const olc::vf2d & pos, const olc::vf2d & size, olc::Decal * decal, const olc::vf2d & source_pos, const olc::vf2d & source_size, const olc::Pixel & tint)
{ {
pge->DrawPartialDecal(WorldToScreen(pos), size * m_vWorldScale * m_vRecipPixel, decal, source_pos, source_size, tint); pge->DrawPartialDecal(WorldToScreen(pos), size * m_vWorldScale * m_vRecipPixel, decal, source_pos, source_size, tint,GFX3DTransform::TRANSFORM_REQUIRED);
} }
void TransformedView::DrawExplicitDecal(olc::Decal* decal, const olc::vf2d* pos, const olc::vf2d* uv, const olc::Pixel* col, uint32_t elements) void TransformedView::DrawExplicitDecal(olc::Decal* decal, const olc::vf2d* pos, const olc::vf2d* uv, const olc::Pixel* col, uint32_t elements)
@ -593,7 +593,7 @@ namespace olc
std::vector<olc::vf2d> vTransformed(elements); std::vector<olc::vf2d> vTransformed(elements);
for (uint32_t n = 0; n < elements; n++) for (uint32_t n = 0; n < elements; n++)
vTransformed[n] = WorldToScreen(pos[n]); vTransformed[n] = WorldToScreen(pos[n]);
pge->DrawExplicitDecal(decal, vTransformed.data(), uv, col, elements); pge->DrawExplicitDecal(decal, vTransformed.data(), uv, col, elements,GFX3DTransform::TRANSFORM_REQUIRED);
} }
void TransformedView::DrawWarpedDecal(olc::Decal* decal, const olc::vf2d* pos, const olc::Pixel& tint) void TransformedView::DrawWarpedDecal(olc::Decal* decal, const olc::vf2d* pos, const olc::Pixel& tint)
@ -604,7 +604,7 @@ namespace olc
WorldToScreen(pos[2]), WorldToScreen(pos[3]), WorldToScreen(pos[2]), WorldToScreen(pos[3]),
} }; } };
pge->DrawWarpedDecal(decal, vTransformed, tint); pge->DrawWarpedDecal(decal, vTransformed, tint,GFX3DTransform::TRANSFORM_REQUIRED);
} }
void TransformedView::DrawWarpedDecal(olc::Decal* decal, const olc::vf2d(&pos)[4], const olc::Pixel& tint) void TransformedView::DrawWarpedDecal(olc::Decal* decal, const olc::vf2d(&pos)[4], const olc::Pixel& tint)
@ -630,7 +630,7 @@ namespace olc
WorldToScreen(pos[2]), WorldToScreen(pos[3]), WorldToScreen(pos[2]), WorldToScreen(pos[3]),
} }; } };
pge->DrawPartialWarpedDecal(decal, vTransformed, source_pos, source_size, tint); pge->DrawPartialWarpedDecal(decal, vTransformed, source_pos, source_size, tint,GFX3DTransform::TRANSFORM_REQUIRED);
} }
void TransformedView::DrawPartialWarpedDecal(olc::Decal* decal, const std::array<olc::vf2d, 4>& pos, const olc::vf2d& source_pos, const olc::vf2d& source_size, const olc::Pixel& tint) void TransformedView::DrawPartialWarpedDecal(olc::Decal* decal, const std::array<olc::vf2d, 4>& pos, const olc::vf2d& source_pos, const olc::vf2d& source_size, const olc::Pixel& tint)
@ -640,42 +640,42 @@ namespace olc
void TransformedView::DrawRotatedDecal(const olc::vf2d & pos, olc::Decal * decal, const float fAngle, const olc::vf2d & center, const olc::vf2d & scale, const olc::Pixel & tint) void TransformedView::DrawRotatedDecal(const olc::vf2d & pos, olc::Decal * decal, const float fAngle, const olc::vf2d & center, const olc::vf2d & scale, const olc::Pixel & tint)
{ {
pge->DrawRotatedDecal(WorldToScreen(pos), decal, fAngle, center, scale * m_vWorldScale * m_vRecipPixel, tint); pge->DrawRotatedDecal(WorldToScreen(pos), decal, fAngle, center, scale * m_vWorldScale * m_vRecipPixel, tint,GFX3DTransform::TRANSFORM_REQUIRED);
} }
void TransformedView::DrawPartialRotatedDecal(const olc::vf2d & pos, olc::Decal * decal, const float fAngle, const olc::vf2d & center, const olc::vf2d & source_pos, const olc::vf2d & source_size, const olc::vf2d & scale, const olc::Pixel & tint) void TransformedView::DrawPartialRotatedDecal(const olc::vf2d & pos, olc::Decal * decal, const float fAngle, const olc::vf2d & center, const olc::vf2d & source_pos, const olc::vf2d & source_size, const olc::vf2d & scale, const olc::Pixel & tint)
{ {
pge->DrawPartialRotatedDecal(WorldToScreen(pos), decal, fAngle, center, source_pos, source_size, scale * m_vWorldScale * m_vRecipPixel, tint); pge->DrawPartialRotatedDecal(WorldToScreen(pos), decal, fAngle, center, source_pos, source_size, scale * m_vWorldScale * m_vRecipPixel, tint,GFX3DTransform::TRANSFORM_REQUIRED);
} }
void TransformedView::DrawStringDecal(const olc::vf2d & pos, const std::string & sText, const olc::Pixel col, const olc::vf2d & scale) void TransformedView::DrawStringDecal(const olc::vf2d & pos, const std::string & sText, const olc::Pixel col, const olc::vf2d & scale)
{ {
pge->DrawStringDecal(WorldToScreen(pos), sText, col, scale * m_vWorldScale * m_vRecipPixel); pge->DrawStringDecal(WorldToScreen(pos), sText, col, scale * m_vWorldScale * m_vRecipPixel,GFX3DTransform::TRANSFORM_REQUIRED);
} }
void TransformedView::DrawStringPropDecal(const olc::vf2d & pos, const std::string & sText, const olc::Pixel col, const olc::vf2d & scale ) void TransformedView::DrawStringPropDecal(const olc::vf2d & pos, const std::string & sText, const olc::Pixel col, const olc::vf2d & scale )
{ {
pge->DrawStringPropDecal(WorldToScreen(pos), sText, col, scale * m_vWorldScale * m_vRecipPixel); pge->DrawStringPropDecal(WorldToScreen(pos), sText, col, scale * m_vWorldScale * m_vRecipPixel,GFX3DTransform::TRANSFORM_REQUIRED);
} }
void TransformedView::FillRectDecal(const olc::vf2d & pos, const olc::vf2d & size, const olc::Pixel col) void TransformedView::FillRectDecal(const olc::vf2d & pos, const olc::vf2d & size, const olc::Pixel col)
{ {
pge->FillRectDecal(WorldToScreen(pos), (size * m_vWorldScale).ceil(), col); pge->FillRectDecal(WorldToScreen(pos), (size * m_vWorldScale).ceil(), col,GFX3DTransform::TRANSFORM_REQUIRED);
} }
void TransformedView::DrawRectDecal(const olc::vf2d& pos, const olc::vf2d& size, const olc::Pixel col) void TransformedView::DrawRectDecal(const olc::vf2d& pos, const olc::vf2d& size, const olc::Pixel col)
{ {
pge->DrawRectDecal(WorldToScreen(pos), (size * m_vWorldScale).ceil(), col); pge->DrawRectDecal(WorldToScreen(pos), (size * m_vWorldScale).ceil(), col,GFX3DTransform::TRANSFORM_REQUIRED);
} }
void TransformedView::DrawLineDecal(const olc::vf2d& pos1, const olc::vf2d& pos2, Pixel p) void TransformedView::DrawLineDecal(const olc::vf2d& pos1, const olc::vf2d& pos2, Pixel p)
{ {
pge->DrawLineDecal(WorldToScreen(pos1), WorldToScreen(pos2), p); pge->DrawLineDecal(WorldToScreen(pos1), WorldToScreen(pos2), p,GFX3DTransform::TRANSFORM_REQUIRED);
} }
void TransformedView::GradientFillRectDecal(const olc::vf2d & pos, const olc::vf2d & size, const olc::Pixel colTL, const olc::Pixel colBL, const olc::Pixel colBR, const olc::Pixel colTR) void TransformedView::GradientFillRectDecal(const olc::vf2d & pos, const olc::vf2d & size, const olc::Pixel colTL, const olc::Pixel colBL, const olc::Pixel colBR, const olc::Pixel colTR)
{ {
pge->GradientFillRectDecal(WorldToScreen(pos), size * m_vWorldScale, colTL, colBL, colBR, colTR); pge->GradientFillRectDecal(WorldToScreen(pos), size * m_vWorldScale, colTL, colBL, colBR, colTR,GFX3DTransform::TRANSFORM_REQUIRED);
} }
void TransformedView::DrawPolygonDecal(olc::Decal* decal, const std::vector<olc::vf2d>& pos, const std::vector<olc::vf2d>& uv, const olc::Pixel tint) void TransformedView::DrawPolygonDecal(olc::Decal* decal, const std::vector<olc::vf2d>& pos, const std::vector<olc::vf2d>& uv, const olc::Pixel tint)
@ -683,7 +683,7 @@ namespace olc
std::vector<olc::vf2d> vTransformed(pos.size()); std::vector<olc::vf2d> vTransformed(pos.size());
for (uint32_t n = 0; n < pos.size(); n++) for (uint32_t n = 0; n < pos.size(); n++)
vTransformed[n] = WorldToScreen(pos[n]); vTransformed[n] = WorldToScreen(pos[n]);
pge->DrawPolygonDecal(decal, vTransformed, uv, tint); pge->DrawPolygonDecal(decal, vTransformed, uv, tint,GFX3DTransform::TRANSFORM_REQUIRED);
} }
void TransformedView::DrawPolygonDecal(olc::Decal* decal, const std::vector<olc::vf2d>& pos, const std::vector<olc::vf2d>& uv, const std::vector<olc::Pixel> &tint) void TransformedView::DrawPolygonDecal(olc::Decal* decal, const std::vector<olc::vf2d>& pos, const std::vector<olc::vf2d>& uv, const std::vector<olc::Pixel> &tint)
@ -691,7 +691,7 @@ namespace olc
std::vector<olc::vf2d> vTransformed(pos.size()); std::vector<olc::vf2d> vTransformed(pos.size());
for (uint32_t n = 0; n < pos.size(); n++) for (uint32_t n = 0; n < pos.size(); n++)
vTransformed[n] = WorldToScreen(pos[n]); vTransformed[n] = WorldToScreen(pos[n]);
pge->DrawPolygonDecal(decal, vTransformed, uv, tint); pge->DrawPolygonDecal(decal, vTransformed, uv, tint,GFX3DTransform::TRANSFORM_REQUIRED);
} }
void TransformedView::DrawPolygonDecal(olc::Decal* decal, const std::vector<olc::vf2d>& pos, const std::vector<olc::vf2d>& uv, const std::vector<olc::Pixel>& colours, const olc::Pixel tint) void TransformedView::DrawPolygonDecal(olc::Decal* decal, const std::vector<olc::vf2d>& pos, const std::vector<olc::vf2d>& uv, const std::vector<olc::Pixel>& colours, const olc::Pixel tint)
@ -699,7 +699,7 @@ namespace olc
std::vector<olc::vf2d> vTransformed(pos.size()); std::vector<olc::vf2d> vTransformed(pos.size());
for (uint32_t n = 0; n < pos.size(); n++) for (uint32_t n = 0; n < pos.size(); n++)
vTransformed[n] = WorldToScreen(pos[n]); vTransformed[n] = WorldToScreen(pos[n]);
pge->DrawPolygonDecal(decal, vTransformed, uv, colours, tint); pge->DrawPolygonDecal(decal, vTransformed, uv, colours, tint,GFX3DTransform::TRANSFORM_REQUIRED);
} }

View File

@ -7,3 +7,5 @@
#include "TMXParser.h" #include "TMXParser.h"
#define TSX_PARSER_SETUP #define TSX_PARSER_SETUP
#include "TSXParser.h" #include "TSXParser.h"
#define OLC_PGEX_GRAPHICS3D
#include "olcPGEX_Graphics3D.h"

View File

@ -863,6 +863,12 @@ namespace olc
LIST LIST
}; };
enum class GFX3DTransform
{
TRANSFORM_REQUIRED,
NO_TRANSFORM
};
// O------------------------------------------------------------------------------O // O------------------------------------------------------------------------------O
// | olc::Renderable - Convenience class to keep a sprite and decal together | // | olc::Renderable - Convenience class to keep a sprite and decal together |
// O------------------------------------------------------------------------------O // O------------------------------------------------------------------------------O
@ -899,6 +905,7 @@ namespace olc
olc::DecalStructure structure = olc::DecalStructure::FAN; olc::DecalStructure structure = olc::DecalStructure::FAN;
uint32_t points = 0; uint32_t points = 0;
bool depth = false; bool depth = false;
GFX3DTransform transform{GFX3DTransform::NO_TRANSFORM};
}; };
struct LayerDesc struct LayerDesc
@ -975,6 +982,7 @@ namespace olc
public: // User Override Interfaces public: // User Override Interfaces
// Called once on application startup, use to load your resources // Called once on application startup, use to load your resources
virtual bool OnUserCreate(); virtual bool OnUserCreate();
virtual void Apply3DTransform(std::vector<DecalInstance>&decals);
// Called every frame, and provides you with a time per frame value // Called every frame, and provides you with a time per frame value
virtual bool OnUserUpdate(float fElapsedTime); virtual bool OnUserUpdate(float fElapsedTime);
// Called once on application termination, so you can be one clean coder // Called once on application termination, so you can be one clean coder
@ -1113,42 +1121,42 @@ namespace olc
void SetDecalMode(const olc::DecalMode& mode); void SetDecalMode(const olc::DecalMode& mode);
void SetDecalStructure(const olc::DecalStructure& structure); void SetDecalStructure(const olc::DecalStructure& structure);
// Draws a whole decal, with optional scale and tinting // Draws a whole decal, with optional scale and tinting
void DrawDecal(const olc::vf2d& pos, olc::Decal* decal, const olc::vf2d& scale = { 1.0f,1.0f }, const olc::Pixel& tint = olc::WHITE); void DrawDecal(const olc::vf2d& pos, olc::Decal* decal, const olc::vf2d& scale = { 1.0f,1.0f }, const olc::Pixel& tint = olc::WHITE,const GFX3DTransform transform=GFX3DTransform::NO_TRANSFORM);
// Draws a region of a decal, with optional scale and tinting // Draws a region of a decal, with optional scale and tinting
void DrawPartialDecal(const olc::vf2d& pos, olc::Decal* decal, const olc::vf2d& source_pos, const olc::vf2d& source_size, const olc::vf2d& scale = { 1.0f,1.0f }, const olc::Pixel& tint = olc::WHITE); void DrawPartialDecal(const olc::vf2d& pos, olc::Decal* decal, const olc::vf2d& source_pos, const olc::vf2d& source_size, const olc::vf2d& scale = { 1.0f,1.0f }, const olc::Pixel& tint = olc::WHITE,const GFX3DTransform transform=GFX3DTransform::NO_TRANSFORM);
void DrawPartialDecal(const olc::vf2d& pos, const olc::vf2d& size, olc::Decal* decal, const olc::vf2d& source_pos, const olc::vf2d& source_size, const olc::Pixel& tint = olc::WHITE); void DrawPartialDecal(const olc::vf2d& pos, const olc::vf2d& size, olc::Decal* decal, const olc::vf2d& source_pos, const olc::vf2d& source_size, const olc::Pixel& tint = olc::WHITE,const GFX3DTransform transform=GFX3DTransform::NO_TRANSFORM);
// Draws fully user controlled 4 vertices, pos(pixels), uv(pixels), colours // Draws fully user controlled 4 vertices, pos(pixels), uv(pixels), colours
void DrawExplicitDecal(olc::Decal* decal, const olc::vf2d* pos, const olc::vf2d* uv, const olc::Pixel* col, uint32_t elements = 4); void DrawExplicitDecal(olc::Decal* decal, const olc::vf2d* pos, const olc::vf2d* uv, const olc::Pixel* col, uint32_t elements = 4,const GFX3DTransform transform=GFX3DTransform::NO_TRANSFORM);
// Draws a decal with 4 arbitrary points, warping the texture to look "correct" // Draws a decal with 4 arbitrary points, warping the texture to look "correct"
void DrawWarpedDecal(olc::Decal* decal, const olc::vf2d(&pos)[4], const olc::Pixel& tint = olc::WHITE); void DrawWarpedDecal(olc::Decal* decal, const olc::vf2d(&pos)[4], const olc::Pixel& tint = olc::WHITE,const GFX3DTransform transform=GFX3DTransform::NO_TRANSFORM);
void DrawWarpedDecal(olc::Decal* decal, const olc::vf2d* pos, const olc::Pixel& tint = olc::WHITE); void DrawWarpedDecal(olc::Decal* decal, const olc::vf2d* pos, const olc::Pixel& tint = olc::WHITE,const GFX3DTransform transform=GFX3DTransform::NO_TRANSFORM);
void DrawWarpedDecal(olc::Decal* decal, const std::array<olc::vf2d, 4>& pos, const olc::Pixel& tint = olc::WHITE); void DrawWarpedDecal(olc::Decal* decal, const std::array<olc::vf2d, 4>& pos, const olc::Pixel& tint = olc::WHITE,const GFX3DTransform transform=GFX3DTransform::NO_TRANSFORM);
// As above, but you can specify a region of a decal source sprite // As above, but you can specify a region of a decal source sprite
void DrawPartialWarpedDecal(olc::Decal* decal, const olc::vf2d(&pos)[4], const olc::vf2d& source_pos, const olc::vf2d& source_size, const olc::Pixel& tint = olc::WHITE); void DrawPartialWarpedDecal(olc::Decal* decal, const olc::vf2d(&pos)[4], const olc::vf2d& source_pos, const olc::vf2d& source_size, const olc::Pixel& tint = olc::WHITE,const GFX3DTransform transform=GFX3DTransform::NO_TRANSFORM);
void DrawPartialWarpedDecal(olc::Decal* decal, const olc::vf2d* pos, const olc::vf2d& source_pos, const olc::vf2d& source_size, const olc::Pixel& tint = olc::WHITE); void DrawPartialWarpedDecal(olc::Decal* decal, const olc::vf2d* pos, const olc::vf2d& source_pos, const olc::vf2d& source_size, const olc::Pixel& tint = olc::WHITE,const GFX3DTransform transform=GFX3DTransform::NO_TRANSFORM);
void DrawPartialWarpedDecal(olc::Decal* decal, const std::array<olc::vf2d, 4>& pos, const olc::vf2d& source_pos, const olc::vf2d& source_size, const olc::Pixel& tint = olc::WHITE); void DrawPartialWarpedDecal(olc::Decal* decal, const std::array<olc::vf2d, 4>& pos, const olc::vf2d& source_pos, const olc::vf2d& source_size, const olc::Pixel& tint = olc::WHITE,const GFX3DTransform transform=GFX3DTransform::NO_TRANSFORM);
// Draws a decal rotated to specified angle, wit point of rotation offset // Draws a decal rotated to specified angle, wit point of rotation offset
void DrawRotatedDecal(const olc::vf2d& pos, olc::Decal* decal, const float fAngle, const olc::vf2d& center = { 0.0f, 0.0f }, const olc::vf2d& scale = { 1.0f,1.0f }, const olc::Pixel& tint = olc::WHITE); void DrawRotatedDecal(const olc::vf2d& pos, olc::Decal* decal, const float fAngle, const olc::vf2d& center = { 0.0f, 0.0f }, const olc::vf2d& scale = { 1.0f,1.0f }, const olc::Pixel& tint = olc::WHITE,const GFX3DTransform transform=GFX3DTransform::NO_TRANSFORM);
void DrawPartialRotatedDecal(const olc::vf2d& pos, olc::Decal* decal, const float fAngle, const olc::vf2d& center, const olc::vf2d& source_pos, const olc::vf2d& source_size, const olc::vf2d& scale = { 1.0f, 1.0f }, const olc::Pixel& tint = olc::WHITE); void DrawPartialRotatedDecal(const olc::vf2d& pos, olc::Decal* decal, const float fAngle, const olc::vf2d& center, const olc::vf2d& source_pos, const olc::vf2d& source_size, const olc::vf2d& scale = { 1.0f, 1.0f }, const olc::Pixel& tint = olc::WHITE,const GFX3DTransform transform=GFX3DTransform::NO_TRANSFORM);
// Draws a multiline string as a decal, with tiniting and scaling // Draws a multiline string as a decal, with tiniting and scaling
void DrawStringDecal(const olc::vf2d& pos, const std::string& sText, const Pixel col = olc::WHITE, const olc::vf2d& scale = { 1.0f, 1.0f }); void DrawStringDecal(const olc::vf2d& pos, const std::string& sText, const Pixel col = olc::WHITE, const olc::vf2d& scale = { 1.0f, 1.0f },const GFX3DTransform transform=GFX3DTransform::NO_TRANSFORM);
void DrawStringPropDecal(const olc::vf2d& pos, const std::string& sText, const Pixel col = olc::WHITE, const olc::vf2d& scale = { 1.0f, 1.0f }); void DrawStringPropDecal(const olc::vf2d& pos, const std::string& sText, const Pixel col = olc::WHITE, const olc::vf2d& scale = { 1.0f, 1.0f },const GFX3DTransform transform=GFX3DTransform::NO_TRANSFORM);
// Draws a single shaded filled rectangle as a decal // Draws a single shaded filled rectangle as a decal
void DrawRectDecal(const olc::vf2d& pos, const olc::vf2d& size, const olc::Pixel col = olc::WHITE); void DrawRectDecal(const olc::vf2d& pos, const olc::vf2d& size, const olc::Pixel col = olc::WHITE,const GFX3DTransform transform=GFX3DTransform::NO_TRANSFORM);
void FillRectDecal(const olc::vf2d& pos, const olc::vf2d& size, const olc::Pixel col = olc::WHITE); void FillRectDecal(const olc::vf2d& pos, const olc::vf2d& size, const olc::Pixel col = olc::WHITE,const GFX3DTransform transform=GFX3DTransform::NO_TRANSFORM);
// Draws a corner shaded rectangle as a decal // Draws a corner shaded rectangle as a decal
void GradientFillRectDecal(const olc::vf2d& pos, const olc::vf2d& size, const olc::Pixel colTL, const olc::Pixel colBL, const olc::Pixel colBR, const olc::Pixel colTR); void GradientFillRectDecal(const olc::vf2d& pos, const olc::vf2d& size, const olc::Pixel colTL, const olc::Pixel colBL, const olc::Pixel colBR, const olc::Pixel colTR,const GFX3DTransform transform=GFX3DTransform::NO_TRANSFORM);
// Draws an arbitrary convex textured polygon using GPU // Draws an arbitrary convex textured polygon using GPU
void DrawPolygonDecal(olc::Decal* decal, const std::vector<olc::vf2d>& pos, const std::vector<olc::vf2d>& uv, const olc::Pixel tint = olc::WHITE); void DrawPolygonDecal(olc::Decal* decal, const std::vector<olc::vf2d>& pos, const std::vector<olc::vf2d>& uv, const olc::Pixel tint = olc::WHITE,const GFX3DTransform transform=GFX3DTransform::NO_TRANSFORM);
void DrawPolygonDecal(olc::Decal* decal, const std::vector<olc::vf2d>& pos, const std::vector<float>& depth, const std::vector<olc::vf2d>& uv, const olc::Pixel tint = olc::WHITE); void DrawPolygonDecal(olc::Decal* decal, const std::vector<olc::vf2d>& pos, const std::vector<float>& depth, const std::vector<olc::vf2d>& uv, const olc::Pixel tint = olc::WHITE,const GFX3DTransform transform=GFX3DTransform::NO_TRANSFORM);
void DrawPolygonDecal(olc::Decal* decal, const std::vector<olc::vf2d>& pos, const std::vector<olc::vf2d>& uv, const std::vector<olc::Pixel>& tint); void DrawPolygonDecal(olc::Decal* decal, const std::vector<olc::vf2d>& pos, const std::vector<olc::vf2d>& uv, const std::vector<olc::Pixel>& tint,const GFX3DTransform transform=GFX3DTransform::NO_TRANSFORM);
void DrawPolygonDecal(olc::Decal* decal, const std::vector<olc::vf2d>& pos, const std::vector<olc::vf2d>& uv, const std::vector<olc::Pixel>& colours, const olc::Pixel tint); void DrawPolygonDecal(olc::Decal* decal, const std::vector<olc::vf2d>& pos, const std::vector<olc::vf2d>& uv, const std::vector<olc::Pixel>& colours, const olc::Pixel tint,const GFX3DTransform transform=GFX3DTransform::NO_TRANSFORM);
void DrawPolygonDecal(olc::Decal* decal, const std::vector<olc::vf2d>& pos, const std::vector<float>& depth, const std::vector<olc::vf2d>& uv, const std::vector<olc::Pixel>& colours, const olc::Pixel tint); void DrawPolygonDecal(olc::Decal* decal, const std::vector<olc::vf2d>& pos, const std::vector<float>& depth, const std::vector<olc::vf2d>& uv, const std::vector<olc::Pixel>& colours, const olc::Pixel tint,const GFX3DTransform transform=GFX3DTransform::NO_TRANSFORM);
// Draws a line in Decal Space // Draws a line in Decal Space
void DrawLineDecal(const olc::vf2d& pos1, const olc::vf2d& pos2, Pixel p = olc::WHITE); void DrawLineDecal(const olc::vf2d& pos1, const olc::vf2d& pos2, Pixel p = olc::WHITE,const GFX3DTransform transform=GFX3DTransform::NO_TRANSFORM);
void DrawRotatedStringDecal(const olc::vf2d& pos, const std::string& sText, const float fAngle, const olc::vf2d& center = { 0.0f, 0.0f }, const olc::Pixel col = olc::WHITE, const olc::vf2d& scale = { 1.0f, 1.0f }); void DrawRotatedStringDecal(const olc::vf2d& pos, const std::string& sText, const float fAngle, const olc::vf2d& center = { 0.0f, 0.0f }, const olc::Pixel col = olc::WHITE, const olc::vf2d& scale = { 1.0f, 1.0f },const GFX3DTransform transform=GFX3DTransform::NO_TRANSFORM);
void DrawRotatedStringPropDecal(const olc::vf2d& pos, const std::string& sText, const float fAngle, const olc::vf2d& center = { 0.0f, 0.0f }, const olc::Pixel col = olc::WHITE, const olc::vf2d& scale = { 1.0f, 1.0f }); void DrawRotatedStringPropDecal(const olc::vf2d& pos, const std::string& sText, const float fAngle, const olc::vf2d& center = { 0.0f, 0.0f }, const olc::Pixel col = olc::WHITE, const olc::vf2d& scale = { 1.0f, 1.0f },const GFX3DTransform transform=GFX3DTransform::NO_TRANSFORM);
// Clears entire draw target to Pixel // Clears entire draw target to Pixel
void Clear(Pixel p); void Clear(Pixel p);
// Clears the rendering back buffer // Clears the rendering back buffer
@ -2831,7 +2839,7 @@ namespace olc
void PixelGameEngine::SetDecalStructure(const olc::DecalStructure& structure) void PixelGameEngine::SetDecalStructure(const olc::DecalStructure& structure)
{ nDecalStructure = structure; } { nDecalStructure = structure; }
void PixelGameEngine::DrawPartialDecal(const olc::vf2d& pos, olc::Decal* decal, const olc::vf2d& source_pos, const olc::vf2d& source_size, const olc::vf2d& scale, const olc::Pixel& tint) void PixelGameEngine::DrawPartialDecal(const olc::vf2d& pos, olc::Decal* decal, const olc::vf2d& source_pos, const olc::vf2d& source_size, const olc::vf2d& scale, const olc::Pixel& tint,const GFX3DTransform transform)
{ {
olc::vf2d vScreenSpacePos = olc::vf2d vScreenSpacePos =
{ {
@ -2861,10 +2869,11 @@ namespace olc
di.w = { 1,1,1,1 }; di.w = { 1,1,1,1 };
di.mode = nDecalMode; di.mode = nDecalMode;
di.structure = nDecalStructure; di.structure = nDecalStructure;
di.transform=transform;
vLayers[nTargetLayer].vecDecalInstance.push_back(di); vLayers[nTargetLayer].vecDecalInstance.push_back(di);
} }
void PixelGameEngine::DrawPartialDecal(const olc::vf2d& pos, const olc::vf2d& size, olc::Decal* decal, const olc::vf2d& source_pos, const olc::vf2d& source_size, const olc::Pixel& tint) void PixelGameEngine::DrawPartialDecal(const olc::vf2d& pos, const olc::vf2d& size, olc::Decal* decal, const olc::vf2d& source_pos, const olc::vf2d& source_size, const olc::Pixel& tint,const GFX3DTransform transform)
{ {
olc::vf2d vScreenSpacePos = olc::vf2d vScreenSpacePos =
{ {
@ -2889,11 +2898,12 @@ namespace olc
di.w = { 1,1,1,1 }; di.w = { 1,1,1,1 };
di.mode = nDecalMode; di.mode = nDecalMode;
di.structure = nDecalStructure; di.structure = nDecalStructure;
di.transform=transform;
vLayers[nTargetLayer].vecDecalInstance.push_back(di); vLayers[nTargetLayer].vecDecalInstance.push_back(di);
} }
void PixelGameEngine::DrawDecal(const olc::vf2d& pos, olc::Decal* decal, const olc::vf2d& scale, const olc::Pixel& tint) void PixelGameEngine::DrawDecal(const olc::vf2d& pos, olc::Decal* decal, const olc::vf2d& scale, const olc::Pixel& tint,const GFX3DTransform transform)
{ {
olc::vf2d vScreenSpacePos = olc::vf2d vScreenSpacePos =
{ {
@ -2916,10 +2926,11 @@ namespace olc
di.w = { 1, 1, 1, 1 }; di.w = { 1, 1, 1, 1 };
di.mode = nDecalMode; di.mode = nDecalMode;
di.structure = nDecalStructure; di.structure = nDecalStructure;
di.transform=transform;
vLayers[nTargetLayer].vecDecalInstance.push_back(di); vLayers[nTargetLayer].vecDecalInstance.push_back(di);
} }
void PixelGameEngine::DrawExplicitDecal(olc::Decal* decal, const olc::vf2d* pos, const olc::vf2d* uv, const olc::Pixel* col, uint32_t elements) void PixelGameEngine::DrawExplicitDecal(olc::Decal* decal, const olc::vf2d* pos, const olc::vf2d* uv, const olc::Pixel* col, uint32_t elements,const GFX3DTransform transform)
{ {
DecalInstance di; DecalInstance di;
di.decal = decal; di.decal = decal;
@ -2937,10 +2948,11 @@ namespace olc
} }
di.mode = nDecalMode; di.mode = nDecalMode;
di.structure = nDecalStructure; di.structure = nDecalStructure;
di.transform=transform;
vLayers[nTargetLayer].vecDecalInstance.push_back(di); vLayers[nTargetLayer].vecDecalInstance.push_back(di);
} }
void PixelGameEngine::DrawPolygonDecal(olc::Decal* decal, const std::vector<olc::vf2d>& pos, const std::vector<olc::vf2d>& uv, const olc::Pixel tint) void PixelGameEngine::DrawPolygonDecal(olc::Decal* decal, const std::vector<olc::vf2d>& pos, const std::vector<olc::vf2d>& uv, const olc::Pixel tint,const GFX3DTransform transform)
{ {
DecalInstance di; DecalInstance di;
di.decal = decal; di.decal = decal;
@ -2958,10 +2970,11 @@ namespace olc
} }
di.mode = nDecalMode; di.mode = nDecalMode;
di.structure = nDecalStructure; di.structure = nDecalStructure;
di.transform=transform;
vLayers[nTargetLayer].vecDecalInstance.push_back(di); vLayers[nTargetLayer].vecDecalInstance.push_back(di);
} }
void PixelGameEngine::DrawPolygonDecal(olc::Decal* decal, const std::vector<olc::vf2d>& pos, const std::vector<olc::vf2d>& uv, const std::vector<olc::Pixel> &tint) void PixelGameEngine::DrawPolygonDecal(olc::Decal* decal, const std::vector<olc::vf2d>& pos, const std::vector<olc::vf2d>& uv, const std::vector<olc::Pixel> &tint,const GFX3DTransform transform)
{ {
DecalInstance di; DecalInstance di;
di.decal = decal; di.decal = decal;
@ -2979,10 +2992,11 @@ namespace olc
} }
di.mode = nDecalMode; di.mode = nDecalMode;
di.structure = nDecalStructure; di.structure = nDecalStructure;
di.transform=transform;
vLayers[nTargetLayer].vecDecalInstance.push_back(di); vLayers[nTargetLayer].vecDecalInstance.push_back(di);
} }
void PixelGameEngine::DrawPolygonDecal(olc::Decal* decal, const std::vector<olc::vf2d>& pos, const std::vector<olc::vf2d>& uv, const std::vector<olc::Pixel>& colours, const olc::Pixel tint) void PixelGameEngine::DrawPolygonDecal(olc::Decal* decal, const std::vector<olc::vf2d>& pos, const std::vector<olc::vf2d>& uv, const std::vector<olc::Pixel>& colours, const olc::Pixel tint,const GFX3DTransform transform)
{ {
std::vector<olc::Pixel> newColours(colours.size(), olc::WHITE); std::vector<olc::Pixel> newColours(colours.size(), olc::WHITE);
std::transform(colours.begin(), colours.end(), newColours.begin(), std::transform(colours.begin(), colours.end(), newColours.begin(),
@ -2991,7 +3005,7 @@ namespace olc
} }
void PixelGameEngine::DrawPolygonDecal(olc::Decal* decal, const std::vector<olc::vf2d>& pos, const std::vector<float>& depth, const std::vector<olc::vf2d>& uv, const olc::Pixel tint) void PixelGameEngine::DrawPolygonDecal(olc::Decal* decal, const std::vector<olc::vf2d>& pos, const std::vector<float>& depth, const std::vector<olc::vf2d>& uv, const olc::Pixel tint,const GFX3DTransform transform)
{ {
DecalInstance di; DecalInstance di;
di.decal = decal; di.decal = decal;
@ -3009,10 +3023,11 @@ namespace olc
} }
di.mode = nDecalMode; di.mode = nDecalMode;
di.structure = nDecalStructure; di.structure = nDecalStructure;
di.transform=transform;
vLayers[nTargetLayer].vecDecalInstance.push_back(di); vLayers[nTargetLayer].vecDecalInstance.push_back(di);
} }
void PixelGameEngine::DrawPolygonDecal(olc::Decal* decal, const std::vector<olc::vf2d>& pos, const std::vector<float>& depth, const std::vector<olc::vf2d>& uv, const std::vector<olc::Pixel>& colours, const olc::Pixel tint) void PixelGameEngine::DrawPolygonDecal(olc::Decal* decal, const std::vector<olc::vf2d>& pos, const std::vector<float>& depth, const std::vector<olc::vf2d>& uv, const std::vector<olc::Pixel>& colours, const olc::Pixel tint,const GFX3DTransform transform)
{ {
DecalInstance di; DecalInstance di;
di.decal = decal; di.decal = decal;
@ -3030,6 +3045,7 @@ namespace olc
} }
di.mode = nDecalMode; di.mode = nDecalMode;
di.structure = nDecalStructure; di.structure = nDecalStructure;
di.transform=transform;
vLayers[nTargetLayer].vecDecalInstance.push_back(di); vLayers[nTargetLayer].vecDecalInstance.push_back(di);
} }
@ -3103,11 +3119,11 @@ namespace olc
} }
#endif #endif
void PixelGameEngine::DrawLineDecal(const olc::vf2d& pos1, const olc::vf2d& pos2, Pixel p) void PixelGameEngine::DrawLineDecal(const olc::vf2d& pos1, const olc::vf2d& pos2, Pixel p,const GFX3DTransform transform)
{ {
auto m = nDecalMode; auto m = nDecalMode;
nDecalMode = olc::DecalMode::WIREFRAME; nDecalMode = olc::DecalMode::WIREFRAME;
DrawPolygonDecal(nullptr, { pos1, pos2 }, { {0, 0}, {0,0} }, p); DrawPolygonDecal(nullptr, { pos1, pos2 }, { {0, 0}, {0,0} }, p,transform);
nDecalMode = m; nDecalMode = m;
/*DecalInstance di; /*DecalInstance di;
@ -3130,7 +3146,7 @@ namespace olc
vLayers[nTargetLayer].vecDecalInstance.push_back(di);*/ vLayers[nTargetLayer].vecDecalInstance.push_back(di);*/
} }
void PixelGameEngine::DrawRectDecal(const olc::vf2d& pos, const olc::vf2d& size, const olc::Pixel col) void PixelGameEngine::DrawRectDecal(const olc::vf2d& pos, const olc::vf2d& size, const olc::Pixel col,const GFX3DTransform transform)
{ {
auto m = nDecalMode; auto m = nDecalMode;
SetDecalMode(olc::DecalMode::WIREFRAME); SetDecalMode(olc::DecalMode::WIREFRAME);
@ -3138,29 +3154,28 @@ namespace olc
std::array<olc::vf2d, 4> points = { { {pos}, {pos.x, pos.y + vNewSize.y}, {pos + vNewSize}, {pos.x + vNewSize.x, pos.y} } }; std::array<olc::vf2d, 4> points = { { {pos}, {pos.x, pos.y + vNewSize.y}, {pos + vNewSize}, {pos.x + vNewSize.x, pos.y} } };
std::array<olc::vf2d, 4> uvs = { {{0,0},{0,0},{0,0},{0,0}} }; std::array<olc::vf2d, 4> uvs = { {{0,0},{0,0},{0,0},{0,0}} };
std::array<olc::Pixel, 4> cols = { {col, col, col, col} }; std::array<olc::Pixel, 4> cols = { {col, col, col, col} };
DrawExplicitDecal(nullptr, points.data(), uvs.data(), cols.data(), 4); DrawExplicitDecal(nullptr, points.data(), uvs.data(), cols.data(), 4,transform);
SetDecalMode(m); SetDecalMode(m);
} }
void PixelGameEngine::FillRectDecal(const olc::vf2d& pos, const olc::vf2d& size, const olc::Pixel col) void PixelGameEngine::FillRectDecal(const olc::vf2d& pos, const olc::vf2d& size, const olc::Pixel col,const GFX3DTransform transform)
{ {
olc::vf2d vNewSize = size;// (size - olc::vf2d(0.375f, 0.375f)).ceil(); olc::vf2d vNewSize = size;// (size - olc::vf2d(0.375f, 0.375f)).ceil();
std::array<olc::vf2d, 4> points = { { {pos}, {pos.x, pos.y + vNewSize.y}, {pos + vNewSize}, {pos.x + vNewSize.x, pos.y} } }; std::array<olc::vf2d, 4> points = { { {pos}, {pos.x, pos.y + vNewSize.y}, {pos + vNewSize}, {pos.x + vNewSize.x, pos.y} } };
std::array<olc::vf2d, 4> uvs = { {{0,0},{0,0},{0,0},{0,0}} }; std::array<olc::vf2d, 4> uvs = { {{0,0},{0,0},{0,0},{0,0}} };
std::array<olc::Pixel, 4> cols = { {col, col, col, col} }; std::array<olc::Pixel, 4> cols = { {col, col, col, col} };
DrawExplicitDecal(nullptr, points.data(), uvs.data(), cols.data(), 4); DrawExplicitDecal(nullptr, points.data(), uvs.data(), cols.data(), 4,transform);
} }
void PixelGameEngine::GradientFillRectDecal(const olc::vf2d& pos, const olc::vf2d& size, const olc::Pixel colTL, const olc::Pixel colBL, const olc::Pixel colBR, const olc::Pixel colTR) void PixelGameEngine::GradientFillRectDecal(const olc::vf2d& pos, const olc::vf2d& size, const olc::Pixel colTL, const olc::Pixel colBL, const olc::Pixel colBR, const olc::Pixel colTR,const GFX3DTransform transform)
{ {
std::array<olc::vf2d, 4> points = { { {pos}, {pos.x, pos.y + size.y}, {pos + size}, {pos.x + size.x, pos.y} } }; std::array<olc::vf2d, 4> points = { { {pos}, {pos.x, pos.y + size.y}, {pos + size}, {pos.x + size.x, pos.y} } };
std::array<olc::vf2d, 4> uvs = { {{0,0},{0,0},{0,0},{0,0}} }; std::array<olc::vf2d, 4> uvs = { {{0,0},{0,0},{0,0},{0,0}} };
std::array<olc::Pixel, 4> cols = { {colTL, colBL, colBR, colTR} }; std::array<olc::Pixel, 4> cols = { {colTL, colBL, colBR, colTR} };
DrawExplicitDecal(nullptr, points.data(), uvs.data(), cols.data(), 4); DrawExplicitDecal(nullptr, points.data(), uvs.data(), cols.data(), 4,transform);
} }
void PixelGameEngine::DrawRotatedDecal(const olc::vf2d& pos, olc::Decal* decal, const float fAngle, const olc::vf2d& center, const olc::vf2d& scale, const olc::Pixel& tint) void PixelGameEngine::DrawRotatedDecal(const olc::vf2d& pos, olc::Decal* decal, const float fAngle, const olc::vf2d& center, const olc::vf2d& scale, const olc::Pixel& tint,const GFX3DTransform transform)
{ {
DecalInstance di; DecalInstance di;
di.decal = decal; di.decal = decal;
@ -3183,11 +3198,12 @@ namespace olc
} }
di.mode = nDecalMode; di.mode = nDecalMode;
di.structure = nDecalStructure; di.structure = nDecalStructure;
di.transform=transform;
vLayers[nTargetLayer].vecDecalInstance.push_back(di); vLayers[nTargetLayer].vecDecalInstance.push_back(di);
} }
void PixelGameEngine::DrawPartialRotatedDecal(const olc::vf2d& pos, olc::Decal* decal, const float fAngle, const olc::vf2d& center, const olc::vf2d& source_pos, const olc::vf2d& source_size, const olc::vf2d& scale, const olc::Pixel& tint) void PixelGameEngine::DrawPartialRotatedDecal(const olc::vf2d& pos, olc::Decal* decal, const float fAngle, const olc::vf2d& center, const olc::vf2d& source_pos, const olc::vf2d& source_size, const olc::vf2d& scale, const olc::Pixel& tint,const GFX3DTransform transform)
{ {
DecalInstance di; DecalInstance di;
di.decal = decal; di.decal = decal;
@ -3212,10 +3228,11 @@ namespace olc
di.uv = { { uvtl.x, uvtl.y }, { uvtl.x, uvbr.y }, { uvbr.x, uvbr.y }, { uvbr.x, uvtl.y } }; di.uv = { { uvtl.x, uvtl.y }, { uvtl.x, uvbr.y }, { uvbr.x, uvbr.y }, { uvbr.x, uvtl.y } };
di.mode = nDecalMode; di.mode = nDecalMode;
di.structure = nDecalStructure; di.structure = nDecalStructure;
di.transform=transform;
vLayers[nTargetLayer].vecDecalInstance.push_back(di); vLayers[nTargetLayer].vecDecalInstance.push_back(di);
} }
void PixelGameEngine::DrawPartialWarpedDecal(olc::Decal* decal, const olc::vf2d* pos, const olc::vf2d& source_pos, const olc::vf2d& source_size, const olc::Pixel& tint) void PixelGameEngine::DrawPartialWarpedDecal(olc::Decal* decal, const olc::vf2d* pos, const olc::vf2d& source_pos, const olc::vf2d& source_size, const olc::Pixel& tint,const GFX3DTransform transform)
{ {
DecalInstance di; DecalInstance di;
di.points = 4; di.points = 4;
@ -3245,11 +3262,12 @@ namespace olc
} }
di.mode = nDecalMode; di.mode = nDecalMode;
di.structure = nDecalStructure; di.structure = nDecalStructure;
di.transform=transform;
vLayers[nTargetLayer].vecDecalInstance.push_back(di); vLayers[nTargetLayer].vecDecalInstance.push_back(di);
} }
} }
void PixelGameEngine::DrawWarpedDecal(olc::Decal* decal, const olc::vf2d* pos, const olc::Pixel& tint) void PixelGameEngine::DrawWarpedDecal(olc::Decal* decal, const olc::vf2d* pos, const olc::Pixel& tint,const GFX3DTransform transform)
{ {
// Thanks Nathan Reed, a brilliant article explaining whats going on here // Thanks Nathan Reed, a brilliant article explaining whats going on here
// http://www.reedbeta.com/blog/quadrilateral-interpolation-part-1/ // http://www.reedbeta.com/blog/quadrilateral-interpolation-part-1/
@ -3277,23 +3295,24 @@ namespace olc
} }
di.mode = nDecalMode; di.mode = nDecalMode;
di.structure = nDecalStructure; di.structure = nDecalStructure;
di.transform=transform;
vLayers[nTargetLayer].vecDecalInstance.push_back(di); vLayers[nTargetLayer].vecDecalInstance.push_back(di);
} }
} }
void PixelGameEngine::DrawWarpedDecal(olc::Decal* decal, const std::array<olc::vf2d, 4>& pos, const olc::Pixel& tint) void PixelGameEngine::DrawWarpedDecal(olc::Decal* decal, const std::array<olc::vf2d, 4>& pos, const olc::Pixel& tint,const GFX3DTransform transform)
{ DrawWarpedDecal(decal, pos.data(), tint); } { DrawWarpedDecal(decal, pos.data(), tint,transform); }
void PixelGameEngine::DrawWarpedDecal(olc::Decal* decal, const olc::vf2d(&pos)[4], const olc::Pixel& tint) void PixelGameEngine::DrawWarpedDecal(olc::Decal* decal, const olc::vf2d(&pos)[4], const olc::Pixel& tint,const GFX3DTransform transform)
{ DrawWarpedDecal(decal, &pos[0], tint); } { DrawWarpedDecal(decal, &pos[0], tint,transform); }
void PixelGameEngine::DrawPartialWarpedDecal(olc::Decal* decal, const std::array<olc::vf2d, 4>& pos, const olc::vf2d& source_pos, const olc::vf2d& source_size, const olc::Pixel& tint) void PixelGameEngine::DrawPartialWarpedDecal(olc::Decal* decal, const std::array<olc::vf2d, 4>& pos, const olc::vf2d& source_pos, const olc::vf2d& source_size, const olc::Pixel& tint,const GFX3DTransform transform)
{ DrawPartialWarpedDecal(decal, pos.data(), source_pos, source_size, tint); } { DrawPartialWarpedDecal(decal, pos.data(), source_pos, source_size, tint,transform); }
void PixelGameEngine::DrawPartialWarpedDecal(olc::Decal* decal, const olc::vf2d(&pos)[4], const olc::vf2d& source_pos, const olc::vf2d& source_size, const olc::Pixel& tint) void PixelGameEngine::DrawPartialWarpedDecal(olc::Decal* decal, const olc::vf2d(&pos)[4], const olc::vf2d& source_pos, const olc::vf2d& source_size, const olc::Pixel& tint,const GFX3DTransform transform)
{ DrawPartialWarpedDecal(decal, &pos[0], source_pos, source_size, tint); } { DrawPartialWarpedDecal(decal, &pos[0], source_pos, source_size, tint,transform); }
void PixelGameEngine::DrawStringDecal(const olc::vf2d& pos, const std::string& sText, const Pixel col, const olc::vf2d& scale) void PixelGameEngine::DrawStringDecal(const olc::vf2d& pos, const std::string& sText, const Pixel col, const olc::vf2d& scale,const GFX3DTransform transform)
{ {
olc::vf2d spos = { 0.0f, 0.0f }; olc::vf2d spos = { 0.0f, 0.0f };
for (auto c : sText) for (auto c : sText)
@ -3310,13 +3329,13 @@ namespace olc
{ {
int32_t ox = (c - 32) % 16; int32_t ox = (c - 32) % 16;
int32_t oy = (c - 32) / 16; int32_t oy = (c - 32) / 16;
DrawPartialDecal(pos + spos, fontRenderable.Decal(), {float(ox) * 8.0f, float(oy) * 8.0f}, {8.0f, 8.0f}, scale, col); DrawPartialDecal(pos + spos, fontRenderable.Decal(), {float(ox) * 8.0f, float(oy) * 8.0f}, {8.0f, 8.0f}, scale, col,transform);
spos.x += 8.0f * scale.x; spos.x += 8.0f * scale.x;
} }
} }
} }
void PixelGameEngine::DrawStringPropDecal(const olc::vf2d& pos, const std::string& sText, const Pixel col, const olc::vf2d& scale) void PixelGameEngine::DrawStringPropDecal(const olc::vf2d& pos, const std::string& sText, const Pixel col, const olc::vf2d& scale,const GFX3DTransform transform)
{ {
olc::vf2d spos = { 0.0f, 0.0f }; olc::vf2d spos = { 0.0f, 0.0f };
for (auto c : sText) for (auto c : sText)
@ -3333,13 +3352,13 @@ namespace olc
{ {
int32_t ox = (c - 32) % 16; int32_t ox = (c - 32) % 16;
int32_t oy = (c - 32) / 16; int32_t oy = (c - 32) / 16;
DrawPartialDecal(pos + spos, fontRenderable.Decal(), { float(ox) * 8.0f + float(vFontSpacing[c - 32].x), float(oy) * 8.0f }, { float(vFontSpacing[c - 32].y), 8.0f }, scale, col); DrawPartialDecal(pos + spos, fontRenderable.Decal(), { float(ox) * 8.0f + float(vFontSpacing[c - 32].x), float(oy) * 8.0f }, { float(vFontSpacing[c - 32].y), 8.0f }, scale, col,transform);
spos.x += float(vFontSpacing[c - 32].y) * scale.x; spos.x += float(vFontSpacing[c - 32].y) * scale.x;
} }
} }
} }
// Thanks Oso-Grande/Sopadeoso For these awesom and stupidly clever Text Rotation routines... duh XD // Thanks Oso-Grande/Sopadeoso For these awesom and stupidly clever Text Rotation routines... duh XD
void PixelGameEngine::DrawRotatedStringDecal(const olc::vf2d& pos, const std::string& sText, const float fAngle, const olc::vf2d& center, const Pixel col, const olc::vf2d& scale) void PixelGameEngine::DrawRotatedStringDecal(const olc::vf2d& pos, const std::string& sText, const float fAngle, const olc::vf2d& center, const Pixel col, const olc::vf2d& scale,const GFX3DTransform transform)
{ {
olc::vf2d spos = center; olc::vf2d spos = center;
for (auto c : sText) for (auto c : sText)
@ -3356,13 +3375,13 @@ namespace olc
{ {
int32_t ox = (c - 32) % 16; int32_t ox = (c - 32) % 16;
int32_t oy = (c - 32) / 16; int32_t oy = (c - 32) / 16;
DrawPartialRotatedDecal(pos, fontRenderable.Decal(), fAngle, spos, { float(ox) * 8.0f, float(oy) * 8.0f }, { 8.0f, 8.0f }, scale, col); DrawPartialRotatedDecal(pos, fontRenderable.Decal(), fAngle, spos, { float(ox) * 8.0f, float(oy) * 8.0f }, { 8.0f, 8.0f }, scale, col,transform);
spos.x -= 8.0f; spos.x -= 8.0f;
} }
} }
} }
void PixelGameEngine::DrawRotatedStringPropDecal(const olc::vf2d& pos, const std::string& sText, const float fAngle, const olc::vf2d& center, const Pixel col, const olc::vf2d& scale) void PixelGameEngine::DrawRotatedStringPropDecal(const olc::vf2d& pos, const std::string& sText, const float fAngle, const olc::vf2d& center, const Pixel col, const olc::vf2d& scale,const GFX3DTransform transform)
{ {
olc::vf2d spos = center; olc::vf2d spos = center;
for (auto c : sText) for (auto c : sText)
@ -3379,7 +3398,7 @@ namespace olc
{ {
int32_t ox = (c - 32) % 16; int32_t ox = (c - 32) % 16;
int32_t oy = (c - 32) / 16; int32_t oy = (c - 32) / 16;
DrawPartialRotatedDecal(pos, fontRenderable.Decal(), fAngle, spos, { float(ox) * 8.0f + float(vFontSpacing[c - 32].x), float(oy) * 8.0f }, { float(vFontSpacing[c - 32].y), 8.0f }, scale, col); DrawPartialRotatedDecal(pos, fontRenderable.Decal(), fAngle, spos, { float(ox) * 8.0f + float(vFontSpacing[c - 32].x), float(oy) * 8.0f }, { float(vFontSpacing[c - 32].y), 8.0f }, scale, col,transform);
spos.x -= float(vFontSpacing[c - 32].y); spos.x -= float(vFontSpacing[c - 32].y);
} }
} }
@ -3893,6 +3912,7 @@ namespace olc
m_tp2 = std::chrono::system_clock::now(); m_tp2 = std::chrono::system_clock::now();
} }
void PixelGameEngine::Apply3DTransform(std::vector<DecalInstance>&decals){}
void PixelGameEngine::olc_CoreUpdate() void PixelGameEngine::olc_CoreUpdate()
{ {
@ -3995,9 +4015,12 @@ namespace olc
renderer->DrawLayerQuad(layer->vOffset, layer->vScale, layer->tint); renderer->DrawLayerQuad(layer->vOffset, layer->vScale, layer->tint);
Apply3DTransform(layer->vecDecalInstance);
// Display Decals in order for this layer // Display Decals in order for this layer
for (auto& decal : layer->vecDecalInstance) for (auto& decal : layer->vecDecalInstance){
renderer->DrawDecal(decal); renderer->DrawDecal(decal);
}
layer->vecDecalInstance.clear(); layer->vecDecalInstance.clear();
} }
else else