generated from sigonasr2/CPlusPlusProjectTemplate
Render in O3 optimized mode.
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
050616b0b6
commit
6862923a50
Binary file not shown.
105
main.cpp
105
main.cpp
@ -368,7 +368,7 @@ private:
|
|||||||
// the plane, the triangle simply becomes a smaller triangle
|
// the plane, the triangle simply becomes a smaller triangle
|
||||||
|
|
||||||
// Copy appearance info to new triangle
|
// Copy appearance info to new triangle
|
||||||
out_tri1.col = in_tri.col;
|
out_tri1.col = {in_tri.col.r,in_tri.col.g,255}; //in_tri.col;
|
||||||
|
|
||||||
// The inside point is valid, so keep that...
|
// The inside point is valid, so keep that...
|
||||||
out_tri1.p[0] = *inside_points[0];
|
out_tri1.p[0] = *inside_points[0];
|
||||||
@ -388,8 +388,8 @@ private:
|
|||||||
// represent a quad with two new triangles
|
// represent a quad with two new triangles
|
||||||
|
|
||||||
// Copy appearance info to new triangles
|
// Copy appearance info to new triangles
|
||||||
out_tri1.col = in_tri.col;
|
out_tri1.col = {in_tri.col.r,255,in_tri.col.b}; //in_tri.col;
|
||||||
out_tri2.col = in_tri.col;
|
out_tri2.col = {255,in_tri.col.g,in_tri.col.b};//in_tri.col;
|
||||||
|
|
||||||
// The first triangle consists of the two inside points and a new
|
// The first triangle consists of the two inside points and a new
|
||||||
// point determined by the location where one side of the triangle
|
// point determined by the location where one side of the triangle
|
||||||
@ -434,7 +434,7 @@ public:
|
|||||||
if (GetKey(olc::LEFT).bHeld) {
|
if (GetKey(olc::LEFT).bHeld) {
|
||||||
vCamera.x-=8*fElapsedTime;
|
vCamera.x-=8*fElapsedTime;
|
||||||
}
|
}
|
||||||
vec3d vForward=Vector_Mul(vLookDir,8*fElapsedTime);
|
vec3d vForward=Vector_Mul(vLookDir,1*fElapsedTime);
|
||||||
if (GetKey(olc::W).bHeld) {
|
if (GetKey(olc::W).bHeld) {
|
||||||
vCamera=Vector_Add(vCamera,vForward);
|
vCamera=Vector_Add(vCamera,vForward);
|
||||||
}
|
}
|
||||||
@ -493,12 +493,12 @@ public:
|
|||||||
|
|
||||||
float dp = std::max(0.1f,Vector_DotProduct(light_dir,normal));
|
float dp = std::max(0.1f,Vector_DotProduct(light_dir,normal));
|
||||||
|
|
||||||
triTransformed.col=Pixel(255*dp*dp,255*dp*dp,255*dp*dp);
|
|
||||||
|
|
||||||
triViewed.p[0]=Matrix_MultiplyVector(matView,triTransformed.p[0]);
|
triViewed.p[0]=Matrix_MultiplyVector(matView,triTransformed.p[0]);
|
||||||
triViewed.p[1]=Matrix_MultiplyVector(matView,triTransformed.p[1]);
|
triViewed.p[1]=Matrix_MultiplyVector(matView,triTransformed.p[1]);
|
||||||
triViewed.p[2]=Matrix_MultiplyVector(matView,triTransformed.p[2]);
|
triViewed.p[2]=Matrix_MultiplyVector(matView,triTransformed.p[2]);
|
||||||
|
|
||||||
|
triViewed.col=Pixel(255*dp*dp,255*dp*dp,255*dp*dp);
|
||||||
|
|
||||||
int nClippedTriangles = 0;
|
int nClippedTriangles = 0;
|
||||||
triangle clipped[2];
|
triangle clipped[2];
|
||||||
nClippedTriangles = Triangle_ClipAgainstPlane({ 0.0f, 0.0f, 0.1f }, { 0.0f, 0.0f, 1.0f }, triViewed, clipped[0], clipped[1]);
|
nClippedTriangles = Triangle_ClipAgainstPlane({ 0.0f, 0.0f, 0.1f }, { 0.0f, 0.0f, 1.0f }, triViewed, clipped[0], clipped[1]);
|
||||||
@ -508,7 +508,7 @@ public:
|
|||||||
triProjected.p[0]=Matrix_MultiplyVector(matProj,clipped[n].p[0]);
|
triProjected.p[0]=Matrix_MultiplyVector(matProj,clipped[n].p[0]);
|
||||||
triProjected.p[1]=Matrix_MultiplyVector(matProj,clipped[n].p[1]);
|
triProjected.p[1]=Matrix_MultiplyVector(matProj,clipped[n].p[1]);
|
||||||
triProjected.p[2]=Matrix_MultiplyVector(matProj,clipped[n].p[2]);
|
triProjected.p[2]=Matrix_MultiplyVector(matProj,clipped[n].p[2]);
|
||||||
triProjected.col=triTransformed.col;
|
triProjected.col=clipped[n].col;
|
||||||
|
|
||||||
triProjected.p[0]=Vector_Div(triProjected.p[0],triProjected.p[0].w);
|
triProjected.p[0]=Vector_Div(triProjected.p[0],triProjected.p[0].w);
|
||||||
triProjected.p[1]=Vector_Div(triProjected.p[1],triProjected.p[1].w);
|
triProjected.p[1]=Vector_Div(triProjected.p[1],triProjected.p[1].w);
|
||||||
@ -540,35 +540,76 @@ public:
|
|||||||
|
|
||||||
std::sort(vecTrianglesToRaster.begin(),vecTrianglesToRaster.end(),[](triangle&t1,triangle&t2){return (t1.p[0].z+t1.p[1].z+t1.p[2].z)/3.0f>(t2.p[0].z+t2.p[1].z+t2.p[2].z)/3.0f;});
|
std::sort(vecTrianglesToRaster.begin(),vecTrianglesToRaster.end(),[](triangle&t1,triangle&t2){return (t1.p[0].z+t1.p[1].z+t1.p[2].z)/3.0f>(t2.p[0].z+t2.p[1].z+t2.p[2].z)/3.0f;});
|
||||||
|
|
||||||
for (auto&triProjected:vecTrianglesToRaster) {
|
int triRenderCount=0;
|
||||||
|
for (auto&triToRaster:vecTrianglesToRaster) {
|
||||||
|
|
||||||
// Rasterize triangle
|
triangle clipped[2];
|
||||||
SetDecalStructure(DecalStructure::LIST);
|
std::list<triangle>listTriangles;
|
||||||
SetDecalMode(DecalMode::NORMAL);
|
listTriangles.push_back(triToRaster);
|
||||||
DrawPolygonDecal(nullptr,{
|
int nNewTriangles=1;
|
||||||
{triProjected.p[0].x, triProjected.p[0].y},
|
|
||||||
{triProjected.p[1].x, triProjected.p[1].y},
|
for (int p = 0; p < 4; p++)
|
||||||
{triProjected.p[2].x, triProjected.p[2].y}
|
{
|
||||||
},{
|
int nTrisToAdd = 0;
|
||||||
{triProjected.uv[0].u,triProjected.uv[0].v},
|
while (nNewTriangles > 0)
|
||||||
{triProjected.uv[1].u,triProjected.uv[1].v},
|
{
|
||||||
{triProjected.uv[2].u,triProjected.uv[2].v},
|
// Take triangle from front of queue
|
||||||
},triProjected.col);
|
triangle test = listTriangles.front();
|
||||||
SetDecalMode(DecalMode::WIREFRAME);
|
listTriangles.pop_front();
|
||||||
DrawPolygonDecal(nullptr,{
|
nNewTriangles--;
|
||||||
{triProjected.p[0].x, triProjected.p[0].y},
|
|
||||||
{triProjected.p[1].x, triProjected.p[1].y},
|
// Clip it against a plane. We only need to test each
|
||||||
{triProjected.p[2].x, triProjected.p[2].y}
|
// subsequent plane, against subsequent new triangles
|
||||||
},{
|
// as all triangles after a plane clip are guaranteed
|
||||||
{0,0},
|
// to lie on the inside of the plane. I like how this
|
||||||
{0,0},
|
// comment is almost completely and utterly justified
|
||||||
{0,0},
|
switch (p)
|
||||||
},BLACK);
|
{
|
||||||
SetDecalStructure(DecalStructure::FAN);
|
case 0: nTrisToAdd = Triangle_ClipAgainstPlane({ 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, test, clipped[0], clipped[1]); break;
|
||||||
|
case 1: nTrisToAdd = Triangle_ClipAgainstPlane({ 0.0f, (float)ScreenHeight() - 1, 0.0f }, { 0.0f, -1.0f, 0.0f }, test, clipped[0], clipped[1]); break;
|
||||||
|
case 2: nTrisToAdd = Triangle_ClipAgainstPlane({ 0.0f, 0.0f, 0.0f }, { 1.0f, 0.0f, 0.0f }, test, clipped[0], clipped[1]); break;
|
||||||
|
case 3: nTrisToAdd = Triangle_ClipAgainstPlane({ (float)ScreenWidth() - 1, 0.0f, 0.0f }, { -1.0f, 0.0f, 0.0f }, test, clipped[0], clipped[1]); break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clipping may yield a variable number of triangles, so
|
||||||
|
// add these new ones to the back of the queue for subsequent
|
||||||
|
// clipping against next planes
|
||||||
|
for (int w = 0; w < nTrisToAdd; w++)
|
||||||
|
listTriangles.push_back(clipped[w]);
|
||||||
|
}
|
||||||
|
nNewTriangles = listTriangles.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto&t:listTriangles) {
|
||||||
|
// Rasterize triangle
|
||||||
|
SetDecalStructure(DecalStructure::LIST);
|
||||||
|
SetDecalMode(DecalMode::NORMAL);
|
||||||
|
DrawPolygonDecal(nullptr,{
|
||||||
|
{t.p[0].x, t.p[0].y},
|
||||||
|
{t.p[1].x, t.p[1].y},
|
||||||
|
{t.p[2].x, t.p[2].y}
|
||||||
|
},{
|
||||||
|
{t.uv[0].u,t.uv[0].v},
|
||||||
|
{t.uv[1].u,t.uv[1].v},
|
||||||
|
{t.uv[2].u,t.uv[2].v},
|
||||||
|
},t.col);
|
||||||
|
/*SetDecalMode(DecalMode::WIREFRAME);
|
||||||
|
DrawPolygonDecal(nullptr,{
|
||||||
|
{t.p[0].x, t.p[0].y},
|
||||||
|
{t.p[1].x, t.p[1].y},
|
||||||
|
{t.p[2].x, t.p[2].y}
|
||||||
|
},{
|
||||||
|
{0,0},
|
||||||
|
{0,0},
|
||||||
|
{0,0},
|
||||||
|
},BLACK);*/
|
||||||
|
SetDecalStructure(DecalStructure::FAN);
|
||||||
|
triRenderCount++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SetDecalMode(DecalMode::NORMAL);
|
SetDecalMode(DecalMode::NORMAL);
|
||||||
DrawStringDecal({0,0},"Triangles: "+std::to_string(vecTrianglesToRaster.size()));
|
DrawStringDecal({0,0},"Triangles: "+std::to_string(triRenderCount));
|
||||||
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
2
sig
2
sig
@ -3,7 +3,7 @@ export AUTO_UPDATE=true
|
|||||||
source utils/define.sh
|
source utils/define.sh
|
||||||
|
|
||||||
define PROJECT_NAME "C++ProjectTemplate"
|
define PROJECT_NAME "C++ProjectTemplate"
|
||||||
define CUSTOM_PARAMS "-std=c++17 -lX11 -lGL -lpthread -lpng -lstdc++fs -lpulse -lpulse-simple"
|
define CUSTOM_PARAMS "-std=c++17 -lX11 -lGL -lpthread -lpng -lstdc++fs -lpulse -lpulse-simple -O3 -s -DNDEBUG"
|
||||||
define LANGUAGE "C++"
|
define LANGUAGE "C++"
|
||||||
|
|
||||||
source utils/main.sh
|
source utils/main.sh
|
||||||
|
Loading…
x
Reference in New Issue
Block a user