ShootMe implemented, fixed flipped UV tex coord bugs.

linux_template
sigonasr2 2 years ago
parent dd293acd38
commit 76b7f41860
  1. BIN
      Faceball2030/assets/dot.png
  2. BIN
      Faceball2030/assets/enemies/Cube2_auv.png
  3. BIN
      Faceball2030/assets/enemies/Cylinder2_auv.png
  4. 4
      Faceball2030/assets/enemies/ShootMe.mtl
  5. BIN
      Faceball2030/assets/enemies/ShootMe.png
  6. BIN
      Faceball2030/assets/enemies/ShootMe.wings
  7. BIN
      Faceball2030/assets/enemies/ShootMe.xcf
  8. BIN
      Faceball2030/assets/enemies/dirt.png
  9. 11
      Faceball2030/assets/enemies/untitled.mtl
  10. 43
      Faceball2030/main.cpp

Binary file not shown.

Before

Width:  |  Height:  |  Size: 546 B

After

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

@ -1,5 +1,5 @@
# Exported from Wings 3D 2.2.9
newmtl Cylinder1_auv
newmtl Cylinder2_auv
Ns 19.999999999999996
d 1.0
illum 2
@ -7,5 +7,5 @@ Kd 1.0 1.0 1.0
Ka 0.0 0.0 0.0
Ks 0.19 0.19 0.19
Ke 0.0 0.0 0.0
map_Kd Cylinder1_auv.png
map_Kd Cylinder2_auv.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 KiB

After

Width:  |  Height:  |  Size: 8.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

@ -0,0 +1,11 @@
# Exported from Wings 3D 2.2.9
newmtl Cube2_auv
Ns 19.999999999999996
d 1.0
illum 2
Kd 1.0 1.0 1.0
Ka 0.0 0.0 0.0
Ks 0.19 0.19 0.19
Ke 0.0 0.0 0.0
map_Kd Cube2_auv.png

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

Loading…
Cancel
Save