Implemented new 3D rendering integration with GFX3D engine. GFX3D PGEX now uses decals for drawing. Camera follows the player into the sky.

main
sigonasr2 3 months ago
parent ff8f513807
commit 086e244866
  1. 12
      src/Hamster.cpp
  2. 2
      src/Hamster.h
  3. 50
      src/HamsterGame.cpp
  4. 7
      src/HamsterGame.h
  5. 14
      src/olcPGEX_Graphics3D.h
  6. 59
      src/olcPixelGameEngine.h

@ -143,9 +143,11 @@ void Hamster::DrawHamsters(TransformedView&tv){
const Animate2D::Frame&img{h.animations.GetState(h.internalAnimState)==HamsterGame::DEFAULT?anim.GetFrame(h.distanceTravelled/100.f):h.GetCurrentAnimation()}; const Animate2D::Frame&img{h.animations.GetState(h.internalAnimState)==HamsterGame::DEFAULT?anim.GetFrame(h.distanceTravelled/100.f):h.GetCurrentAnimation()};
const Animate2D::Frame&wheelTopImg{wheelTopAnim.GetFrame(h.distanceTravelled/80.f)}; const Animate2D::Frame&wheelTopImg{wheelTopAnim.GetFrame(h.distanceTravelled/80.f)};
const Animate2D::Frame&wheelBottomImg{wheelBottomAnim.GetFrame(h.distanceTravelled/80.f)}; const Animate2D::Frame&wheelBottomImg{wheelBottomAnim.GetFrame(h.distanceTravelled/80.f)};
HamsterGame::Game().SetZ(h.z);
if(h.HasPowerup(Powerup::WHEEL))tv.DrawPartialRotatedDecal(h.pos,wheelBottomImg.GetSourceImage()->Decal(),h.rot,wheelBottomImg.GetSourceRect().size/2,wheelBottomImg.GetSourceRect().pos,wheelBottomImg.GetSourceRect().size,vf2d{1.f,1.f}*h.imgScale,PixelLerp(h.shrinkEffectColor,WHITE,h.imgScale)); if(h.HasPowerup(Powerup::WHEEL))tv.DrawPartialRotatedDecal(h.pos,wheelBottomImg.GetSourceImage()->Decal(),h.rot,wheelBottomImg.GetSourceRect().size/2,wheelBottomImg.GetSourceRect().pos,wheelBottomImg.GetSourceRect().size,vf2d{1.f,1.f}*h.imgScale,PixelLerp(h.shrinkEffectColor,WHITE,h.imgScale));
tv.DrawPartialRotatedDecal(h.pos,img.GetSourceImage()->Decal(),h.rot,img.GetSourceRect().size/2,img.GetSourceRect().pos,img.GetSourceRect().size,vf2d{1.f,1.f}*h.imgScale,PixelLerp(h.shrinkEffectColor,WHITE,h.imgScale)); tv.DrawPartialRotatedDecal(h.pos,img.GetSourceImage()->Decal(),h.rot,img.GetSourceRect().size/2,img.GetSourceRect().pos,img.GetSourceRect().size,vf2d{1.f,1.f}*h.imgScale,PixelLerp(h.shrinkEffectColor,WHITE,h.imgScale));
if(h.HasPowerup(Powerup::WHEEL))tv.DrawPartialRotatedDecal(h.pos,wheelTopImg.GetSourceImage()->Decal(),h.rot,wheelTopImg.GetSourceRect().size/2,wheelTopImg.GetSourceRect().pos,wheelTopImg.GetSourceRect().size,vf2d{1.f,1.f}*h.imgScale,PixelLerp(h.shrinkEffectColor,{255,255,255,192},h.imgScale)); if(h.HasPowerup(Powerup::WHEEL))tv.DrawPartialRotatedDecal(h.pos,wheelTopImg.GetSourceImage()->Decal(),h.rot,wheelTopImg.GetSourceRect().size/2,wheelTopImg.GetSourceRect().pos,wheelTopImg.GetSourceRect().size,vf2d{1.f,1.f}*h.imgScale,PixelLerp(h.shrinkEffectColor,{255,255,255,192},h.imgScale));
HamsterGame::Game().SetZ(0.f);
} }
} }
@ -176,13 +178,11 @@ void Hamster::HandlePlayerControls(){
if(HamsterGame::Game().GetKey(A).bHeld){ if(HamsterGame::Game().GetKey(A).bHeld){
aimingDir+=vf2d{-1,0}; aimingDir+=vf2d{-1,0};
} }
if(HamsterGame::Game().GetKey(PGUP).bPressed){ if(HamsterGame::Game().GetKey(PGUP).bHeld){
HamsterGame::Game().tv.ZoomAtScreenPos(0.95f,HamsterGame::Game().tv.WorldToScreen(GetPos())); z+=0.25f*HamsterGame::Game().GetElapsedTime();
z+=HamsterGame::Game().GetElapsedTime();
} }
if(HamsterGame::Game().GetKey(PGDN).bPressed){ if(HamsterGame::Game().GetKey(PGDN).bHeld){
z=std::max(0.f,z-HamsterGame::Game().GetElapsedTime()); z=std::max(0.f,z-0.25f*HamsterGame::Game().GetElapsedTime());
HamsterGame::Game().tv.ZoomAtScreenPos(1.05f,HamsterGame::Game().tv.WorldToScreen(GetPos()));
} }
if(aimingDir!=vf2d{}){ if(aimingDir!=vf2d{}){
targetRot=aimingDir.norm().polar().y; targetRot=aimingDir.norm().polar().y;

@ -77,7 +77,7 @@ class Hamster{
vf2d pos; vf2d pos;
vf2d vel; vf2d vel;
vf2d lastSafeLocation{}; vf2d lastSafeLocation{};
float z; float z{};
float lastSafeLocationTimer{}; float lastSafeLocationTimer{};
float rot{}; float rot{};
float targetRot{}; float targetRot{};

@ -28,7 +28,7 @@ bool HamsterGame::OnUserCreate(){
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); renderer.SetProjection(90.0f, (float)SCREEN_FRAME.size.x/(float)SCREEN_FRAME.size.y, 0.1f, 1000.0f, 0, SCREEN_FRAME.pos.y, 512, SCREEN_FRAME.size.y);
return true; return true;
} }
@ -135,7 +135,7 @@ void HamsterGame::UpdateGame(const float fElapsedTime){
} }
void HamsterGame::DrawGame(){ void HamsterGame::DrawGame(){
tv.DrawPartialDecal({-3200,-3200},currentMap.value().GetData().GetMapData().MapSize*16+vf2d{3200,3200},animatedWaterTile.Decal(),{0,0},currentMap.value().GetData().GetMapData().MapSize*16+vf2d{3200,3200}); tv.DrawPartialDecal({-3200,-3200},currentMap.value().GetData().GetMapData().MapSize*16+vf2d{6400,6400},animatedWaterTile.Decal(),{0,0},currentMap.value().GetData().GetMapData().MapSize*16+vf2d{3200,3200});
DrawLevelTiles(); DrawLevelTiles();
Powerup::DrawPowerups(tv); Powerup::DrawPowerups(tv);
Hamster::DrawHamsters(tv); Hamster::DrawHamsters(tv);
@ -222,6 +222,9 @@ void HamsterGame::DrawLevelTiles(){
bool HamsterGame::OnUserUpdate(float fElapsedTime){ bool HamsterGame::OnUserUpdate(float fElapsedTime){
runTime+=fElapsedTime; runTime+=fElapsedTime;
vEye.z+=(Hamster::GetPlayer().GetZ()+1.f-vEye.z)*fLazyFollowRate*fElapsedTime;
UpdateGame(fElapsedTime); UpdateGame(fElapsedTime);
DrawGame(); DrawGame();
return true; return true;
@ -319,6 +322,49 @@ void HamsterGame::UpdateWaterTexture(){
} }
void HamsterGame::Apply3DTransform(std::vector<DecalInstance>&decals){ void HamsterGame::Apply3DTransform(std::vector<DecalInstance>&decals){
std::vector<DecalInstance>oldDecals;
std::vector<DecalInstance>foregroundDecals;
oldDecals.reserve(decals.size());
std::copy(decals.begin(),decals.end(),std::back_inserter(oldDecals));
decals.clear();
GFX3D::vec3d vLookTarget = GFX3D::Math::Vec_Add(vEye, vLookDir);
GFX3D::ClearDepth();
renderer.SetCamera(vEye, vLookTarget, vUp);
GFX3D::mat4x4 matRotateX=GFX3D::Math::Mat_MakeRotationX(0.f);
GFX3D::mat4x4 matRotateZ=GFX3D::Math::Mat_MakeRotationZ(0.f);
GFX3D::mat4x4 matWorld=GFX3D::Math::Mat_MultiplyMatrix(matRotateX,matRotateZ);
renderer.SetTransform(matWorld);
for(DecalInstance&decal:oldDecals){
if(decal.transform==GFX3DTransform::NO_TRANSFORM)foregroundDecals.emplace_back(decal);
else
if(decal.points==3){
GFX3D::triangle tri{{{decal.pos[0].x,decal.pos[0].y,decal.z[0],1.f},{decal.pos[1].x,decal.pos[1].y,decal.z[1],1.f},{decal.pos[2].x,decal.pos[2].y,decal.z[2],1.f}},{{decal.uv[0].x,decal.uv[0].y,0.f},{decal.uv[1].x,decal.uv[1].y,0.f},{decal.uv[2].x,decal.uv[2].y,0.f}},{decal.tint[0],decal.tint[1],decal.tint[2]}};
renderer.Render({tri},decal.decal);
}else if(decal.points==4){
GFX3D::triangle tri{{{decal.pos[0].x,decal.pos[0].y,decal.z[0],1.f},{decal.pos[1].x,decal.pos[1].y,decal.z[1],1.f},{decal.pos[2].x,decal.pos[2].y,decal.z[2],1.f}},{{decal.uv[0].x,decal.uv[0].y,0.f},{decal.uv[1].x,decal.uv[1].y,0.f},{decal.uv[2].x,decal.uv[2].y,0.f}},{decal.tint[0],decal.tint[1],decal.tint[2]}};
GFX3D::triangle tri2{{{decal.pos[0].x,decal.pos[0].y,decal.z[0],1.f},{decal.pos[2].x,decal.pos[2].y,decal.z[2],1.f},{decal.pos[3].x,decal.pos[3].y,decal.z[3],1.f}},{{decal.uv[0].x,decal.uv[0].y,0.f},{decal.uv[2].x,decal.uv[2].y,0.f},{decal.uv[3].x,decal.uv[3].y,0.f}},{decal.tint[0],decal.tint[2],decal.tint[3]}};
renderer.Render({tri,tri2},decal.decal,GFX3D::RENDER_TEXTURED|GFX3D::RENDER_DEPTH);
}else{
std::vector<GFX3D::triangle>tris;
tris.reserve(decal.points/3);
if(decal.structure!=DecalStructure::LIST)throw std::runtime_error{std::format("WARNING! Using triangle structure type {} is unsupported! Please only use DecalStructure::LIST!!",int(decal.structure))};
if(decal.points%3!=0)throw std::runtime_error{std::format("WARNING! Number of decal structure points is not a multiple of 3! Points provided: {}. THIS SHOULD NOT BE HAPPENING!",decal.points)};
for(int i{0};i<decal.points;i+=3){
GFX3D::triangle tri{{{decal.pos[i+0].x,decal.pos[i+0].y,decal.z[i+0],1.f},{decal.pos[i+1].x,decal.pos[i+1].y,decal.z[i+1],1.f},{decal.pos[i+2].x,decal.pos[i+2].y,decal.z[i+2],1.f}},{{decal.uv[i+0].x,decal.uv[i+0].y,0.f},{decal.uv[i+1].x,decal.uv[i+1].y,0.f},{decal.uv[i+2].x,decal.uv[i+2].y,0.f}},{decal.tint[i+0],decal.tint[i+1],decal.tint[i+2]}};
tris.emplace_back(tri);
}
renderer.Render(tris,decal.decal);
}
}
std::sort(decals.begin(),decals.end(),[](const DecalInstance&d1,const DecalInstance&d2){return d1.z[0]>d2.z[0];});
std::copy(foregroundDecals.begin(),foregroundDecals.end(),std::back_inserter(decals));
} }
int main() int main()

@ -106,7 +106,8 @@ private:
GFX3D::PipeLine renderer; GFX3D::PipeLine renderer;
virtual void Apply3DTransform(std::vector<DecalInstance>&decals)override final; virtual void Apply3DTransform(std::vector<DecalInstance>&decals)override final;
const GFX3D::vec3d vUp = {0,1,0}; GFX3D::vec3d vUp{0,-1,0};
GFX3D::vec3d vEye = {0,0,-4}; GFX3D::vec3d vEye{0.f,0,1};
const GFX3D::vec3d vLookDir = {0,0,1}; GFX3D::vec3d vLookDir{0,0,-1};
const float fLazyFollowRate{4.0f};
}; };

@ -149,7 +149,7 @@ namespace olc
public: public:
Math(); Math();
public: public:
static vec3d Mat_MultiplyVector(mat4x4 &m, vec3d &i); static vec3d Mat_MultiplyVector(mat4x4 &m, const vec3d &i);
static mat4x4 Mat_MultiplyMatrix(mat4x4 &m1, mat4x4 &m2); static mat4x4 Mat_MultiplyMatrix(mat4x4 &m1, mat4x4 &m2);
static mat4x4 Mat_MakeIdentity(); static mat4x4 Mat_MakeIdentity();
static mat4x4 Mat_MakeRotationX(float fAngleRad); static mat4x4 Mat_MakeRotationX(float fAngleRad);
@ -207,8 +207,8 @@ namespace olc
void SetTexture(olc::Sprite *texture); void SetTexture(olc::Sprite *texture);
//void SetMipMapTexture(olc::GFX3D::MipMap *texture); //void SetMipMapTexture(olc::GFX3D::MipMap *texture);
void SetLightSource(uint32_t nSlot, uint32_t nType, olc::Pixel col, olc::GFX3D::vec3d pos, olc::GFX3D::vec3d dir = { 0.0f, 0.0f, 1.0f, 1.0f }, float fParam = 0.0f); void SetLightSource(uint32_t nSlot, uint32_t nType, olc::Pixel col, olc::GFX3D::vec3d pos, olc::GFX3D::vec3d dir = { 0.0f, 0.0f, 1.0f, 1.0f }, float fParam = 0.0f);
uint32_t Render(std::vector<olc::GFX3D::triangle> &triangles, Decal*dec,uint32_t flags = RENDER_CULL_CW | RENDER_TEXTURED | RENDER_DEPTH); uint32_t Render(const std::vector<olc::GFX3D::triangle> &triangles, Decal*dec,uint32_t flags = RENDER_WIRE | RENDER_DEPTH);
uint32_t Render(std::vector<olc::GFX3D::triangle> &triangles, Decal* dec, uint32_t flags, int nOffset, int nCount); uint32_t Render(const std::vector<olc::GFX3D::triangle> &triangles, Decal* dec, uint32_t flags, int nOffset, int nCount);
uint32_t RenderLine(olc::GFX3D::vec3d &p1, olc::GFX3D::vec3d &p2, olc::Pixel col = olc::WHITE); uint32_t RenderLine(olc::GFX3D::vec3d &p1, olc::GFX3D::vec3d &p2, olc::Pixel col = olc::WHITE);
uint32_t RenderCircleXZ(olc::GFX3D::vec3d &p1, float r, olc::Pixel col = olc::WHITE); uint32_t RenderCircleXZ(olc::GFX3D::vec3d &p1, float r, olc::Pixel col = olc::WHITE);
@ -276,7 +276,7 @@ namespace olc
} }
olc::GFX3D::vec3d olc::GFX3D::Math::Mat_MultiplyVector(olc::GFX3D::mat4x4 &m, olc::GFX3D::vec3d &i) olc::GFX3D::vec3d olc::GFX3D::Math::Mat_MultiplyVector(olc::GFX3D::mat4x4 &m, const olc::GFX3D::vec3d &i)
{ {
vec3d v; vec3d v;
v.x = i.x * m.m[0][0] + i.y * m.m[1][0] + i.z * m.m[2][0] + i.w * m.m[3][0]; v.x = i.x * m.m[0][0] + i.y * m.m[1][0] + i.z * m.m[2][0] + i.w * m.m[3][0];
@ -848,7 +848,7 @@ namespace olc
} }
} }
uint32_t GFX3D::PipeLine::Render(std::vector<olc::GFX3D::triangle> &triangles, Decal*dec,uint32_t flags) uint32_t GFX3D::PipeLine::Render(const std::vector<olc::GFX3D::triangle> &triangles, Decal*dec,uint32_t flags)
{ {
return Render(triangles, dec,flags, 0, triangles.size()); return Render(triangles, dec,flags, 0, triangles.size());
} }
@ -934,7 +934,7 @@ namespace olc
return 0; return 0;
} }
uint32_t GFX3D::PipeLine::Render(std::vector<olc::GFX3D::triangle> &triangles, Decal* dec, uint32_t flags, int nOffset, int nCount) uint32_t GFX3D::PipeLine::Render(const std::vector<olc::GFX3D::triangle> &triangles, Decal* dec, uint32_t flags, int nOffset, int nCount)
{ {
// Calculate Transformation Matrix // Calculate Transformation Matrix
mat4x4 matWorldView = Math::Mat_MultiplyMatrix(matWorld, matView); mat4x4 matWorldView = Math::Mat_MultiplyMatrix(matWorld, matView);
@ -952,7 +952,7 @@ namespace olc
//#pragma omp parallel for schedule(static) //#pragma omp parallel for schedule(static)
for(int tx = nOffset; tx < nOffset+nCount; tx++) for(int tx = nOffset; tx < nOffset+nCount; tx++)
{ {
GFX3D::triangle &tri = triangles[tx]; const GFX3D::triangle &tri = triangles.at(tx);
GFX3D::triangle triTransformed; GFX3D::triangle triTransformed;
// Just copy through texture coordinates // Just copy through texture coordinates

@ -1057,6 +1057,8 @@ namespace olc
void SetLayerTint(uint8_t layer, const olc::Pixel& tint); void SetLayerTint(uint8_t layer, const olc::Pixel& tint);
void SetLayerCustomRenderFunction(uint8_t layer, std::function<void()> f); void SetLayerCustomRenderFunction(uint8_t layer, std::function<void()> f);
void SetZ(const float z);
std::vector<LayerDesc>& GetLayers(); std::vector<LayerDesc>& GetLayers();
uint32_t CreateLayer(); uint32_t CreateLayer();
@ -1258,6 +1260,7 @@ namespace olc
bool bPixelCohesion = false; bool bPixelCohesion = false;
DecalMode nDecalMode = DecalMode::NORMAL; DecalMode nDecalMode = DecalMode::NORMAL;
DecalStructure nDecalStructure = DecalStructure::FAN; DecalStructure nDecalStructure = DecalStructure::FAN;
float z = 0;
std::function<olc::Pixel(const int x, const int y, const olc::Pixel&, const olc::Pixel&)> funcPixelMode; std::function<olc::Pixel(const int x, const int y, const olc::Pixel&, const olc::Pixel&)> funcPixelMode;
std::chrono::time_point<std::chrono::system_clock> m_tp1, m_tp2; std::chrono::time_point<std::chrono::system_clock> m_tp1, m_tp2;
std::vector<olc::vi2d> vFontSpacing; std::vector<olc::vi2d> vFontSpacing;
@ -2872,10 +2875,11 @@ namespace olc
olc::vf2d uvbr = uvtl + ((source_size - olc::vf2d(0.02f, 0.02f)) * decal->vUVScale); olc::vf2d uvbr = uvtl + ((source_size - olc::vf2d(0.02f, 0.02f)) * decal->vUVScale);
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.w = { 1,1,1,1 }; di.w = { 1,1,1,1 };
di.z={z,z,z,z};
di.mode = nDecalMode; di.mode = nDecalMode;
di.structure = nDecalStructure; di.structure = nDecalStructure;
di.transform=transform; di.transform=transform;
vLayers[nTargetLayer].vecDecalInstance.push_back(di); vLayers[nTargetLayer].vecDecalInstance.emplace_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,const GFX3DTransform transform) 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)
@ -2901,10 +2905,11 @@ namespace olc
olc::vf2d uvbr = (source_pos + source_size - olc::vf2d(0.03f, 0.03f)) * decal->vUVScale; olc::vf2d uvbr = (source_pos + source_size - olc::vf2d(0.03f, 0.03f)) * decal->vUVScale;
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.w = { 1,1,1,1 }; di.w = { 1,1,1,1 };
di.z={z,z,z,z};
di.mode = nDecalMode; di.mode = nDecalMode;
di.structure = nDecalStructure; di.structure = nDecalStructure;
di.transform=transform; di.transform=transform;
vLayers[nTargetLayer].vecDecalInstance.push_back(di); vLayers[nTargetLayer].vecDecalInstance.emplace_back(di);
} }
@ -2932,7 +2937,8 @@ namespace olc
di.mode = nDecalMode; di.mode = nDecalMode;
di.structure = nDecalStructure; di.structure = nDecalStructure;
di.transform=transform; di.transform=transform;
vLayers[nTargetLayer].vecDecalInstance.push_back(di); di.z = {z,z,z,z};
vLayers[nTargetLayer].vecDecalInstance.emplace_back(di);
} }
void PixelGameEngine::DrawExplicitDecal(olc::Decal* decal, const olc::vf2d* pos, const olc::vf2d* uv, const olc::Pixel* col, uint32_t elements,const GFX3DTransform transform) void PixelGameEngine::DrawExplicitDecal(olc::Decal* decal, const olc::vf2d* pos, const olc::vf2d* uv, const olc::Pixel* col, uint32_t elements,const GFX3DTransform transform)
@ -2947,7 +2953,7 @@ namespace olc
std::vector<float>ws; std::vector<float>ws;
ws.resize(elements,1); ws.resize(elements,1);
std::vector<float>z; std::vector<float>z;
z.resize(elements,0.f); z.resize(elements,this->z);
DrawExplicitDecal(decal,pos,z.data(),uv,col,ws.data(),elements,transform); DrawExplicitDecal(decal,pos,z.data(),uv,col,ws.data(),elements,transform);
} }
@ -2973,7 +2979,7 @@ namespace olc
di.mode = nDecalMode; di.mode = nDecalMode;
di.structure = nDecalStructure; di.structure = nDecalStructure;
di.transform=transform; di.transform=transform;
vLayers[nTargetLayer].vecDecalInstance.push_back(di); vLayers[nTargetLayer].vecDecalInstance.emplace_back(di);
} }
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) 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)
@ -2984,6 +2990,7 @@ namespace olc
di.pos.resize(di.points); di.pos.resize(di.points);
di.uv.resize(di.points); di.uv.resize(di.points);
di.w.resize(di.points); di.w.resize(di.points);
di.z.resize(di.points,z);
di.tint.resize(di.points); di.tint.resize(di.points);
for (uint32_t i = 0; i < di.points; i++) for (uint32_t i = 0; i < di.points; i++)
{ {
@ -2995,7 +3002,7 @@ namespace olc
di.mode = nDecalMode; di.mode = nDecalMode;
di.structure = nDecalStructure; di.structure = nDecalStructure;
di.transform=transform; di.transform=transform;
vLayers[nTargetLayer].vecDecalInstance.push_back(di); vLayers[nTargetLayer].vecDecalInstance.emplace_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,const GFX3DTransform transform) 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)
@ -3006,6 +3013,7 @@ namespace olc
di.pos.resize(di.points); di.pos.resize(di.points);
di.uv.resize(di.points); di.uv.resize(di.points);
di.w.resize(di.points); di.w.resize(di.points);
di.z.resize(di.points,z);
di.tint.resize(di.points); di.tint.resize(di.points);
for (uint32_t i = 0; i < di.points; i++) for (uint32_t i = 0; i < di.points; i++)
{ {
@ -3017,7 +3025,7 @@ namespace olc
di.mode = nDecalMode; di.mode = nDecalMode;
di.structure = nDecalStructure; di.structure = nDecalStructure;
di.transform=transform; di.transform=transform;
vLayers[nTargetLayer].vecDecalInstance.push_back(di); vLayers[nTargetLayer].vecDecalInstance.emplace_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,const GFX3DTransform transform) 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)
@ -3037,6 +3045,7 @@ namespace olc
di.pos.resize(di.points); di.pos.resize(di.points);
di.uv.resize(di.points); di.uv.resize(di.points);
di.w.resize(di.points); di.w.resize(di.points);
di.z.resize(di.points,z);
di.tint.resize(di.points); di.tint.resize(di.points);
for (uint32_t i = 0; i < di.points; i++) for (uint32_t i = 0; i < di.points; i++)
{ {
@ -3048,7 +3057,7 @@ namespace olc
di.mode = nDecalMode; di.mode = nDecalMode;
di.structure = nDecalStructure; di.structure = nDecalStructure;
di.transform=transform; di.transform=transform;
vLayers[nTargetLayer].vecDecalInstance.push_back(di); vLayers[nTargetLayer].vecDecalInstance.emplace_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,const GFX3DTransform transform) 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)
@ -3059,6 +3068,7 @@ namespace olc
di.pos.resize(di.points); di.pos.resize(di.points);
di.uv.resize(di.points); di.uv.resize(di.points);
di.w.resize(di.points); di.w.resize(di.points);
di.z.resize(di.points,z);
di.tint.resize(di.points); di.tint.resize(di.points);
for (uint32_t i = 0; i < di.points; i++) for (uint32_t i = 0; i < di.points; i++)
{ {
@ -3070,7 +3080,7 @@ namespace olc
di.mode = nDecalMode; di.mode = nDecalMode;
di.structure = nDecalStructure; di.structure = nDecalStructure;
di.transform=transform; di.transform=transform;
vLayers[nTargetLayer].vecDecalInstance.push_back(di); vLayers[nTargetLayer].vecDecalInstance.emplace_back(di);
} }
@ -3097,7 +3107,7 @@ namespace olc
di.mode = nDecalMode; di.mode = nDecalMode;
di.structure = DecalStructure::LIST; di.structure = DecalStructure::LIST;
di.depth = true; di.depth = true;
vLayers[nTargetLayer].vecDecalInstance.push_back(di); vLayers[nTargetLayer].vecDecalInstance.emplace_back(di);
} }
void PixelGameEngine::LW3D_DrawWarpedDecal(olc::Decal* decal, const std::vector<std::array<float, 3>>& pos, const olc::Pixel& tint) void PixelGameEngine::LW3D_DrawWarpedDecal(olc::Decal* decal, const std::vector<std::array<float, 3>>& pos, const olc::Pixel& tint)
@ -3139,7 +3149,7 @@ namespace olc
di.mode = nDecalMode; di.mode = nDecalMode;
di.structure = nDecalStructure; di.structure = nDecalStructure;
di.depth = true; di.depth = true;
vLayers[nTargetLayer].vecDecalInstance.push_back(di); vLayers[nTargetLayer].vecDecalInstance.emplace_back(di);
} }
} }
#endif #endif
@ -3168,7 +3178,7 @@ namespace olc
di.w[1] = 1.0f; di.w[1] = 1.0f;
di.mode = olc::DecalMode::WIREFRAME; di.mode = olc::DecalMode::WIREFRAME;
di.structure = nDecalStructure; di.structure = nDecalStructure;
vLayers[nTargetLayer].vecDecalInstance.push_back(di);*/ vLayers[nTargetLayer].vecDecalInstance.emplace_back(di);*/
} }
void PixelGameEngine::DrawRectDecal(const olc::vf2d& pos, const olc::vf2d& size, const olc::Pixel col,const GFX3DTransform transform) void PixelGameEngine::DrawRectDecal(const olc::vf2d& pos, const olc::vf2d& size, const olc::Pixel col,const GFX3DTransform transform)
@ -3234,6 +3244,7 @@ namespace olc
di.pos.resize(4); di.pos.resize(4);
di.uv = { { 0.0f, 0.0f}, {0.0f, 1.0f}, {1.0f, 1.0f}, {1.0f, 0.0f} }; di.uv = { { 0.0f, 0.0f}, {0.0f, 1.0f}, {1.0f, 1.0f}, {1.0f, 0.0f} };
di.w = { 1, 1, 1, 1 }; di.w = { 1, 1, 1, 1 };
di.z={z,z,z,z};
di.tint = { tint, tint, tint, tint }; di.tint = { tint, tint, tint, tint };
di.points = 4; di.points = 4;
di.pos[0] = (olc::vf2d(0.0f, 0.0f) - center) * scale; di.pos[0] = (olc::vf2d(0.0f, 0.0f) - center) * scale;
@ -3251,7 +3262,7 @@ namespace olc
di.mode = nDecalMode; di.mode = nDecalMode;
di.structure = nDecalStructure; di.structure = nDecalStructure;
di.transform=transform; di.transform=transform;
vLayers[nTargetLayer].vecDecalInstance.push_back(di); vLayers[nTargetLayer].vecDecalInstance.emplace_back(di);
} }
@ -3262,6 +3273,7 @@ namespace olc
di.points = 4; di.points = 4;
di.tint = { tint, tint, tint, tint }; di.tint = { tint, tint, tint, tint };
di.w = { 1, 1, 1, 1 }; di.w = { 1, 1, 1, 1 };
di.z={z,z,z,z};
di.pos.resize(4); di.pos.resize(4);
di.pos[0] = (olc::vf2d(0.0f, 0.0f) - center) * scale; di.pos[0] = (olc::vf2d(0.0f, 0.0f) - center) * scale;
di.pos[1] = (olc::vf2d(0.0f, source_size.y) - center) * scale; di.pos[1] = (olc::vf2d(0.0f, source_size.y) - center) * scale;
@ -3281,7 +3293,7 @@ namespace olc
di.mode = nDecalMode; di.mode = nDecalMode;
di.structure = nDecalStructure; di.structure = nDecalStructure;
di.transform=transform; di.transform=transform;
vLayers[nTargetLayer].vecDecalInstance.push_back(di); vLayers[nTargetLayer].vecDecalInstance.emplace_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,const GFX3DTransform transform) 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)
@ -3291,6 +3303,7 @@ namespace olc
di.decal = decal; di.decal = decal;
di.tint = { tint, tint, tint, tint }; di.tint = { tint, tint, tint, tint };
di.w = { 1, 1, 1, 1 }; di.w = { 1, 1, 1, 1 };
di.z={z,z,z,z};
di.pos.resize(4); di.pos.resize(4);
di.uv = { { 0.0f, 0.0f}, {0.0f, 1.0f}, {1.0f, 1.0f}, {1.0f, 0.0f} }; di.uv = { { 0.0f, 0.0f}, {0.0f, 1.0f}, {1.0f, 1.0f}, {1.0f, 0.0f} };
olc::vf2d center; olc::vf2d center;
@ -3315,7 +3328,7 @@ namespace olc
di.mode = nDecalMode; di.mode = nDecalMode;
di.structure = nDecalStructure; di.structure = nDecalStructure;
di.transform=transform; di.transform=transform;
vLayers[nTargetLayer].vecDecalInstance.push_back(di); vLayers[nTargetLayer].vecDecalInstance.emplace_back(di);
} }
} }
@ -3328,6 +3341,7 @@ namespace olc
di.decal = decal; di.decal = decal;
di.tint = { tint, tint, tint, tint }; di.tint = { tint, tint, tint, tint };
di.w = { 1, 1, 1, 1 }; di.w = { 1, 1, 1, 1 };
di.z={z,z,z,z};
di.pos.resize(4); di.pos.resize(4);
di.uv = { { 0.0f, 0.0f}, {0.0f, 1.0f}, {1.0f, 1.0f}, {1.0f, 0.0f} }; di.uv = { { 0.0f, 0.0f}, {0.0f, 1.0f}, {1.0f, 1.0f}, {1.0f, 0.0f} };
olc::vf2d center; olc::vf2d center;
@ -3348,7 +3362,7 @@ namespace olc
di.mode = nDecalMode; di.mode = nDecalMode;
di.structure = nDecalStructure; di.structure = nDecalStructure;
di.transform=transform; di.transform=transform;
vLayers[nTargetLayer].vecDecalInstance.push_back(di); vLayers[nTargetLayer].vecDecalInstance.emplace_back(di);
} }
} }
@ -3601,7 +3615,9 @@ namespace olc
funcPixelMode = pixelMode; funcPixelMode = pixelMode;
nPixelMode = Pixel::Mode::CUSTOM; nPixelMode = Pixel::Mode::CUSTOM;
} }
void PixelGameEngine::SetZ(const float z){
this->z=z;
}
void PixelGameEngine::SetPixelBlend(float fBlend) void PixelGameEngine::SetPixelBlend(float fBlend)
{ {
fBlendFactor = fBlend; fBlendFactor = fBlend;
@ -4565,10 +4581,6 @@ namespace olc
else else
glBindTexture(GL_TEXTURE_2D, decal.decal->id); glBindTexture(GL_TEXTURE_2D, decal.decal->id);
if (decal.depth)
{
glEnable(GL_DEPTH_TEST);
}
if (nDecalMode == DecalMode::WIREFRAME) if (nDecalMode == DecalMode::WIREFRAME)
glBegin(GL_LINE_LOOP); glBegin(GL_LINE_LOOP);
@ -4606,11 +4618,6 @@ namespace olc
glEnd(); glEnd();
if (decal.depth)
{
glDisable(GL_DEPTH_TEST);
}
} }
uint32_t CreateTexture(const uint32_t width, const uint32_t height, const bool filtered, const bool clamp) override uint32_t CreateTexture(const uint32_t width, const uint32_t height, const bool filtered, const bool clamp) override

Loading…
Cancel
Save