|
|
@ -35,6 +35,7 @@ struct triangle |
|
|
|
vec3d p[3]; |
|
|
|
vec3d p[3]; |
|
|
|
vec2d uv[3]; |
|
|
|
vec2d uv[3]; |
|
|
|
Pixel col; |
|
|
|
Pixel col; |
|
|
|
|
|
|
|
Decal* tex; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
struct MapSquare { |
|
|
|
struct MapSquare { |
|
|
@ -77,14 +78,14 @@ struct mesh |
|
|
|
float x, y, z; |
|
|
|
float x, y, z; |
|
|
|
f >> x >> y >> z; |
|
|
|
f >> x >> y >> z; |
|
|
|
verts.push_back({ x,y,z }); |
|
|
|
verts.push_back({ x,y,z }); |
|
|
|
//std::cout<<x<<" "<<y<<" "<<z<<"\n";
|
|
|
|
std::cout<<x<<" "<<y<<" "<<z<<"\n"; |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
if (data == "vt") { |
|
|
|
if (data == "vt") { |
|
|
|
float u, v; |
|
|
|
float u, v; |
|
|
|
f >> u >> v; |
|
|
|
f >> u >> v; |
|
|
|
uvs.push_back({ u,v }); |
|
|
|
uvs.push_back({ u,1-v }); |
|
|
|
//std::cout<<u<<" "<<v<<"\n";
|
|
|
|
std::cout<<u<<" "<<v<<"\n"; |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
if (data == "f") { |
|
|
|
if (data == "f") { |
|
|
@ -96,7 +97,7 @@ struct mesh |
|
|
|
Parse(t2, v2, uv2); |
|
|
|
Parse(t2, v2, uv2); |
|
|
|
Parse(t3, v3, uv3); |
|
|
|
Parse(t3, v3, uv3); |
|
|
|
tris.push_back({ verts[v1 - 1],verts[v2 - 1],verts[v3 - 1], |
|
|
|
tris.push_back({ verts[v1 - 1],verts[v2 - 1],verts[v3 - 1], |
|
|
|
uvs[uv1 - 1],uvs[uv2 - 1],uvs[uv3 - 1] }); |
|
|
|
uvs[uv1 - 1],uvs[uv2 - 1],uvs[uv3 - 1],WHITE }); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
@ -393,6 +394,7 @@ private: |
|
|
|
|
|
|
|
|
|
|
|
// Copy appearance info to new triangle
|
|
|
|
// Copy appearance info to new triangle
|
|
|
|
out_tri1.col = in_tri.col; |
|
|
|
out_tri1.col = in_tri.col; |
|
|
|
|
|
|
|
out_tri1.tex = in_tri.tex; |
|
|
|
|
|
|
|
|
|
|
|
// 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]; |
|
|
@ -423,6 +425,8 @@ private: |
|
|
|
// Copy appearance info to new triangles
|
|
|
|
// Copy appearance info to new triangles
|
|
|
|
out_tri1.col = in_tri.col; |
|
|
|
out_tri1.col = in_tri.col; |
|
|
|
out_tri2.col = in_tri.col; |
|
|
|
out_tri2.col = in_tri.col; |
|
|
|
|
|
|
|
out_tri1.tex = in_tri.tex; |
|
|
|
|
|
|
|
out_tri2.tex = in_tri.tex; |
|
|
|
|
|
|
|
|
|
|
|
// 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
|
|
|
@ -479,9 +483,9 @@ private: |
|
|
|
for (auto& mesh : objects) { |
|
|
|
for (auto& mesh : objects) { |
|
|
|
for (auto& tri : mesh.tris){ |
|
|
|
for (auto& tri : mesh.tris){ |
|
|
|
triangle triProjected, triTransformed, triViewed; |
|
|
|
triangle triProjected, triTransformed, triViewed; |
|
|
|
mat4x4 matTrans = Matrix_MakeTranslation(-MAP_SIZE.x/2, 0, -MAP_SIZE.y/2); |
|
|
|
//mat4x4 matTrans = Matrix_MakeTranslation(-mesh.size.x/2, 0, -mesh.size.x/2);
|
|
|
|
mat4x4 localMat = Matrix_MakeIdentity(); |
|
|
|
mat4x4 localMat = Matrix_MakeIdentity(); |
|
|
|
localMat = Matrix_MultiplyMatrix(localMat, matTrans); |
|
|
|
//localMat = Matrix_MultiplyMatrix(localMat, matTrans);
|
|
|
|
mat4x4 rotMat = Matrix_MakeRotationY(mesh.rot); |
|
|
|
mat4x4 rotMat = Matrix_MakeRotationY(mesh.rot); |
|
|
|
localMat = Matrix_MultiplyMatrix(localMat, rotMat); |
|
|
|
localMat = Matrix_MultiplyMatrix(localMat, rotMat); |
|
|
|
|
|
|
|
|
|
|
@ -564,6 +568,7 @@ private: |
|
|
|
triProjected.p[1].y *= 0.5f * (float)ScreenHeight(); |
|
|
|
triProjected.p[1].y *= 0.5f * (float)ScreenHeight(); |
|
|
|
triProjected.p[2].x *= 0.5f * (float)ScreenWidth(); |
|
|
|
triProjected.p[2].x *= 0.5f * (float)ScreenWidth(); |
|
|
|
triProjected.p[2].y *= 0.5f * (float)ScreenHeight(); |
|
|
|
triProjected.p[2].y *= 0.5f * (float)ScreenHeight(); |
|
|
|
|
|
|
|
triProjected.tex = mesh.texture; |
|
|
|
|
|
|
|
|
|
|
|
vecTrianglesToRaster.push_back(triProjected); |
|
|
|
vecTrianglesToRaster.push_back(triProjected); |
|
|
|
} |
|
|
|
} |
|
|
@ -613,11 +618,13 @@ private: |
|
|
|
nNewTriangles = listTriangles.size(); |
|
|
|
nNewTriangles = listTriangles.size(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::map<vf2d,vf2d>coords; |
|
|
|
|
|
|
|
|
|
|
|
for (auto& t : listTriangles) { |
|
|
|
for (auto& t : listTriangles) { |
|
|
|
// Rasterize triangle
|
|
|
|
// Rasterize triangle
|
|
|
|
SetDecalStructure(DecalStructure::LIST); |
|
|
|
SetDecalStructure(DecalStructure::LIST); |
|
|
|
SetDecalMode(DecalMode::NORMAL); |
|
|
|
SetDecalMode(DecalMode::NORMAL); |
|
|
|
DrawPolygonDecal(mapMesh.texture, { |
|
|
|
DrawPolygonDecal(t.tex, { |
|
|
|
{t.p[0].x, t.p[0].y}, |
|
|
|
{t.p[0].x, t.p[0].y}, |
|
|
|
{t.p[1].x, t.p[1].y}, |
|
|
|
{t.p[1].x, t.p[1].y}, |
|
|
|
{t.p[2].x, t.p[2].y} |
|
|
|
{t.p[2].x, t.p[2].y} |
|
|
@ -626,7 +633,7 @@ private: |
|
|
|
{t.uv[1].u,t.uv[1].v}, |
|
|
|
{t.uv[1].u,t.uv[1].v}, |
|
|
|
{t.uv[2].u,t.uv[2].v}, |
|
|
|
{t.uv[2].u,t.uv[2].v}, |
|
|
|
}, { t.uv[0].w,t.uv[1].w,t.uv[2].w }, { t.p[0].z,t.p[1].z,t.p[2].z }, { t.col,t.col,t.col }); |
|
|
|
}, { t.uv[0].w,t.uv[1].w,t.uv[2].w }, { t.p[0].z,t.p[1].z,t.p[2].z }, { t.col,t.col,t.col }); |
|
|
|
SetDecalMode(DecalMode::WIREFRAME); |
|
|
|
/*SetDecalMode(DecalMode::WIREFRAME);
|
|
|
|
DrawPolygonDecal(nullptr,{ |
|
|
|
DrawPolygonDecal(nullptr,{ |
|
|
|
{t.p[0].x, t.p[0].y}, |
|
|
|
{t.p[0].x, t.p[0].y}, |
|
|
|
{t.p[1].x, t.p[1].y}, |
|
|
|
{t.p[1].x, t.p[1].y}, |
|
|
@ -635,10 +642,16 @@ private: |
|
|
|
{0,0}, |
|
|
|
{0,0}, |
|
|
|
{0,0}, |
|
|
|
{0,0}, |
|
|
|
{0,0}, |
|
|
|
{0,0}, |
|
|
|
}, { t.uv[0].w,t.uv[1].w,t.uv[2].w }, { t.p[0].z,t.p[1].z,t.p[2].z }, { BLACK,BLACK,BLACK }); |
|
|
|
}, { t.uv[0].w,t.uv[1].w,t.uv[2].w }, { t.p[0].z,t.p[1].z,t.p[2].z }, { BLACK,BLACK,BLACK });*/ |
|
|
|
SetDecalStructure(DecalStructure::FAN); |
|
|
|
SetDecalStructure(DecalStructure::FAN); |
|
|
|
triRenderCount++; |
|
|
|
triRenderCount++; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (const auto&key:coords){ |
|
|
|
|
|
|
|
vf2d coord = key.first; |
|
|
|
|
|
|
|
vf2d val = key.second; |
|
|
|
|
|
|
|
DrawStringDecal({ coord.x,coord.y }, val.str()); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
SetDecalMode(DecalMode::NORMAL); |
|
|
|
SetDecalMode(DecalMode::NORMAL); |
|
|
@ -702,7 +715,7 @@ private: |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Decal* dot; |
|
|
|
Decal* dot,*enemy_ShootMe_tex; |
|
|
|
vi2d MAP_SIZE = { 10,10 }; |
|
|
|
vi2d MAP_SIZE = { 10,10 }; |
|
|
|
std::vector<std::vector<MapSquare>>map; |
|
|
|
std::vector<std::vector<MapSquare>>map; |
|
|
|
std::vector<mesh>objects; |
|
|
|
std::vector<mesh>objects; |
|
|
@ -713,9 +726,16 @@ public: |
|
|
|
sAppName = "Faceball 2030"; |
|
|
|
sAppName = "Faceball 2030"; |
|
|
|
matProj = Matrix_MakeProjection(90.0f, (float)ScreenHeight() / (float)ScreenWidth(), 0.1f, 1000.0f); |
|
|
|
matProj = Matrix_MakeProjection(90.0f, (float)ScreenHeight() / (float)ScreenWidth(), 0.1f, 1000.0f); |
|
|
|
dot = new Decal(new Sprite("assets/dot.png")); |
|
|
|
dot = new Decal(new Sprite("assets/dot.png")); |
|
|
|
|
|
|
|
enemy_ShootMe_tex = new Decal(new Sprite("assets/enemies/ShootMe.png")); |
|
|
|
|
|
|
|
|
|
|
|
mapMesh.texture = dot; |
|
|
|
mapMesh.texture = dot; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mesh testEnemy; |
|
|
|
|
|
|
|
testEnemy.LoadFromObjectFile("assets/enemies/ShootMe.obj"); |
|
|
|
|
|
|
|
testEnemy.texture = enemy_ShootMe_tex; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
objects.push_back(testEnemy); |
|
|
|
|
|
|
|
|
|
|
|
for (int y = 0; y < MAP_SIZE.y; y++) { |
|
|
|
for (int y = 0; y < MAP_SIZE.y; y++) { |
|
|
|
std::vector<MapSquare>row; |
|
|
|
std::vector<MapSquare>row; |
|
|
|
for (int x = 0; x < MAP_SIZE.x; x++) { |
|
|
|
for (int x = 0; x < MAP_SIZE.x; x++) { |
|
|
@ -803,13 +823,14 @@ public: |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
objects.push_back(mapMesh); |
|
|
|
//objects.push_back(mapMesh);
|
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool OnUserUpdate(float fElapsedTime) override |
|
|
|
bool OnUserUpdate(float fElapsedTime) override |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
objects[0].rot += PI / 8 * fElapsedTime; |
|
|
|
HandleKeys(fElapsedTime); |
|
|
|
HandleKeys(fElapsedTime); |
|
|
|
RenderWorld(); |
|
|
|
RenderWorld(); |
|
|
|
return true; |
|
|
|
return true; |
|
|
|