From 1c4439eb4a8373fec9b30c60cc4e2eb3d6d98736 Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Fri, 26 May 2023 11:08:40 -0700 Subject: [PATCH] Added scaling factor to in-game object models. --- Faceball2030/assets/worldSkyBox.mtl | 20 +++ Faceball2030/assets/worldSkyBox.obj | 207 ++++++++++++++++++++++++++++ Faceball2030/assets/worldSkyBox.png | Bin 0 -> 2237 bytes Faceball2030/main.cpp | 72 ++++++---- Faceball2030/main.h | 5 +- 5 files changed, 279 insertions(+), 25 deletions(-) create mode 100644 Faceball2030/assets/worldSkyBox.mtl create mode 100644 Faceball2030/assets/worldSkyBox.obj create mode 100644 Faceball2030/assets/worldSkyBox.png diff --git a/Faceball2030/assets/worldSkyBox.mtl b/Faceball2030/assets/worldSkyBox.mtl new file mode 100644 index 0000000..6df1add --- /dev/null +++ b/Faceball2030/assets/worldSkyBox.mtl @@ -0,0 +1,20 @@ +# Exported from Wings 3D 2.2.9 +newmtl Cylinder1_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 Cylinder1_auv.png + +newmtl default +Ns 19.999999999999996 +d 1.0 +illum 2 +Kd 0.7898538076923077 0.8133333333333334 0.6940444444444445 +Ka 0.0 0.0 0.0 +Ks 0.1689853807692308 0.17133333333333334 0.15940444444444446 +Ke 0.0 0.0 0.0 + diff --git a/Faceball2030/assets/worldSkyBox.obj b/Faceball2030/assets/worldSkyBox.obj new file mode 100644 index 0000000..187fe03 --- /dev/null +++ b/Faceball2030/assets/worldSkyBox.obj @@ -0,0 +1,207 @@ +# Exported from Wings 3D 2.2.9 +mtllib worldSkyBox.mtl +o Cylinder1 +#64 vertices, 64 faces +v 1.00000000 20.00000000 0.0000000e+0 +v 0.98078528 20.00000000 0.19509032 +v 0.92387953 20.00000000 0.38268343 +v 0.83146961 20.00000000 0.55557023 +v 0.70710678 20.00000000 0.70710678 +v 0.55557023 20.00000000 0.83146961 +v 0.38268343 20.00000000 0.92387953 +v 0.19509032 20.00000000 0.98078528 +v 6.1232340e-17 20.00000000 1.00000000 +v -0.19509032 20.00000000 0.98078528 +v -0.38268343 20.00000000 0.92387953 +v -0.55557023 20.00000000 0.83146961 +v -0.70710678 20.00000000 0.70710678 +v -0.83146961 20.00000000 0.55557023 +v -0.92387953 20.00000000 0.38268343 +v -0.98078528 20.00000000 0.19509032 +v -1.00000000 20.00000000 1.2246468e-16 +v -0.98078528 20.00000000 -0.19509032 +v -0.92387953 20.00000000 -0.38268343 +v -0.83146961 20.00000000 -0.55557023 +v -0.70710678 20.00000000 -0.70710678 +v -0.55557023 20.00000000 -0.83146961 +v -0.38268343 20.00000000 -0.92387953 +v -0.19509032 20.00000000 -0.98078528 +v -1.8369702e-16 20.00000000 -1.00000000 +v 0.19509032 20.00000000 -0.98078528 +v 0.38268343 20.00000000 -0.92387953 +v 0.55557023 20.00000000 -0.83146961 +v 0.70710678 20.00000000 -0.70710678 +v 0.83146961 20.00000000 -0.55557023 +v 0.92387953 20.00000000 -0.38268343 +v 0.98078528 20.00000000 -0.19509032 +v 1.00000000 0.0000000e+0 0.0000000e+0 +v 0.98078528 0.0000000e+0 0.19509032 +v 0.92387953 0.0000000e+0 0.38268343 +v 0.83146961 0.0000000e+0 0.55557023 +v 0.70710678 0.0000000e+0 0.70710678 +v 0.55557023 0.0000000e+0 0.83146961 +v 0.38268343 0.0000000e+0 0.92387953 +v 0.19509032 0.0000000e+0 0.98078528 +v 6.1232340e-17 0.0000000e+0 1.00000000 +v -0.19509032 0.0000000e+0 0.98078528 +v -0.38268343 0.0000000e+0 0.92387953 +v -0.55557023 0.0000000e+0 0.83146961 +v -0.70710678 0.0000000e+0 0.70710678 +v -0.83146961 0.0000000e+0 0.55557023 +v -0.92387953 0.0000000e+0 0.38268343 +v -0.98078528 0.0000000e+0 0.19509032 +v -1.00000000 0.0000000e+0 1.2246468e-16 +v -0.98078528 0.0000000e+0 -0.19509032 +v -0.92387953 0.0000000e+0 -0.38268343 +v -0.83146961 0.0000000e+0 -0.55557023 +v -0.70710678 0.0000000e+0 -0.70710678 +v -0.55557023 0.0000000e+0 -0.83146961 +v -0.38268343 0.0000000e+0 -0.92387953 +v -0.19509032 0.0000000e+0 -0.98078528 +v -1.8369702e-16 0.0000000e+0 -1.00000000 +v 0.19509032 0.0000000e+0 -0.98078528 +v 0.38268343 0.0000000e+0 -0.92387953 +v 0.55557023 0.0000000e+0 -0.83146961 +v 0.70710678 0.0000000e+0 -0.70710678 +v 0.83146961 0.0000000e+0 -0.55557023 +v 0.92387953 0.0000000e+0 -0.38268343 +v 0.98078528 0.0000000e+0 -0.19509032 +vt 0.0000000e+0 1.00000000 +vt 2.2648550e-14 1.1657342e-15 +vt 9.8017140e-3 1.00000000 +vt 9.8017140e-3 7.2164497e-16 +vt 1.9603428e-2 1.00000000 +vt 1.9603428e-2 4.4408921e-16 +vt 2.9405142e-2 1.00000000 +vt 2.9405142e-2 2.2204460e-16 +vt 3.9206856e-2 1.00000000 +vt 3.9206856e-2 0.0000000e+0 +vt 4.9008570e-2 1.00000000 +vt 4.9008570e-2 0.0000000e+0 +vt 5.8810284e-2 1.00000000 +vt 5.8810284e-2 0.0000000e+0 +vt 6.8611998e-2 1.00000000 +vt 6.8611998e-2 2.2204460e-16 +vt 7.8413712e-2 1.00000000 +vt 7.8413712e-2 1.00000000 +vt 7.8413712e-2 3.8857806e-16 +vt 7.8413712e-2 2.6645353e-15 +vt 8.8215426e-2 1.00000000 +vt 8.8215426e-2 2.0539126e-15 +vt 9.8017140e-2 1.00000000 +vt 9.8017140e-2 1.5543122e-15 +vt 0.10781885 1.00000000 +vt 0.10781885 9.9920072e-16 +vt 0.11762057 1.00000000 +vt 0.11762057 5.5511151e-16 +vt 0.12742228 1.00000000 +vt 0.12742228 3.8857806e-16 +vt 0.13722400 1.00000000 +vt 0.13722400 2.2204460e-16 +vt 0.14702571 1.00000000 +vt 0.14702571 0.0000000e+0 +vt 0.15682742 1.00000000 +vt 0.15682742 0.0000000e+0 +vt 0.15682742 1.00000000 +vt 0.15682742 1.6653345e-16 +vt 0.16662914 1.00000000 +vt 0.16662914 0.0000000e+0 +vt 0.17643085 1.00000000 +vt 0.17643085 0.0000000e+0 +vt 0.18623257 1.00000000 +vt 0.18623257 0.0000000e+0 +vt 0.19603428 1.00000000 +vt 0.19603428 0.0000000e+0 +vt 0.20583599 1.00000000 +vt 0.20583599 2.7755576e-16 +vt 0.21563771 1.00000000 +vt 0.21563771 5.5511151e-16 +vt 0.22543942 1.00000000 +vt 0.22543942 8.8817842e-16 +vt 0.23524114 1.00000000 +vt 0.23524114 1.4432899e-15 +vt 0.23524114 3.8857806e-16 +vt 0.23524114 1.00000000 +vt 0.24504285 2.2204460e-16 +vt 0.24504285 1.00000000 +vt 0.25484456 0.0000000e+0 +vt 0.25484456 1.00000000 +vt 0.26464628 0.0000000e+0 +vt 0.26464628 1.00000000 +vt 0.27444799 0.0000000e+0 +vt 0.27444799 1.00000000 +vt 0.28424971 2.2204460e-16 +vt 0.28424971 1.00000000 +vt 0.29405142 3.8857806e-16 +vt 0.29405142 1.00000000 +vt 0.30385314 7.2164497e-16 +vt 0.30385314 1.00000000 +vt 0.31365485 3.8857806e-16 +vt 0.31365485 1.00000000 +g Cylinder1_Cylinder1_auv +usemtl Cylinder1_auv +s 1 +f 1/64/ 33/63/ 32/66/ +f 2/62/ 33/63/ 1/64/ +f 2/62/ 35/59/ 34/61/ +f 3/60/ 35/59/ 2/62/ +f 4/58/ 35/59/ 3/60/ +f 4/58/ 37/55/ 36/57/ +f 5/56/ 37/55/ 4/58/ +f 6/33/ 37/36/ 5/35/ +f 6/33/ 39/32/ 38/34/ +f 7/31/ 39/32/ 6/33/ +f 8/29/ 39/32/ 7/31/ +f 8/29/ 41/28/ 40/30/ +f 9/27/ 41/28/ 8/29/ +f 10/25/ 41/28/ 9/27/ +f 10/25/ 43/24/ 42/26/ +f 11/23/ 43/24/ 10/25/ +f 12/21/ 43/24/ 11/23/ +f 12/21/ 45/20/ 44/22/ +f 13/18/ 45/20/ 12/21/ +f 14/51/ 45/54/ 13/53/ +f 14/51/ 47/50/ 46/52/ +f 15/49/ 47/50/ 14/51/ +f 16/47/ 47/50/ 15/49/ +f 16/47/ 49/46/ 48/48/ +f 17/45/ 49/46/ 16/47/ +f 18/43/ 49/46/ 17/45/ +f 18/43/ 51/42/ 50/44/ +f 19/41/ 51/42/ 18/43/ +f 20/39/ 51/42/ 19/41/ +f 20/39/ 53/38/ 52/40/ +f 21/37/ 53/38/ 20/39/ +f 22/15/ 53/19/ 21/17/ +f 22/15/ 55/14/ 54/16/ +f 23/13/ 55/14/ 22/15/ +f 24/11/ 55/14/ 23/13/ +f 24/11/ 57/10/ 56/12/ +f 25/9/ 57/10/ 24/11/ +f 26/7/ 57/10/ 25/9/ +f 26/7/ 59/6/ 58/8/ +f 27/5/ 59/6/ 26/7/ +f 28/3/ 59/6/ 27/5/ +f 28/3/ 61/2/ 60/4/ +f 29/1/ 61/2/ 28/3/ +f 30/70/ 61/71/ 29/72/ +f 30/70/ 63/67/ 62/69/ +f 31/68/ 63/67/ 30/70/ +f 32/66/ 33/63/ 64/65/ +f 32/66/ 63/67/ 31/68/ +f 34/61/ 33/63/ 2/62/ +f 36/57/ 35/59/ 4/58/ +f 38/34/ 37/36/ 6/33/ +f 40/30/ 39/32/ 8/29/ +f 42/26/ 41/28/ 10/25/ +f 44/22/ 43/24/ 12/21/ +f 46/52/ 45/54/ 14/51/ +f 48/48/ 47/50/ 16/47/ +f 50/44/ 49/46/ 18/43/ +f 52/40/ 51/42/ 20/39/ +f 54/16/ 53/19/ 22/15/ +f 56/12/ 55/14/ 24/11/ +f 58/8/ 57/10/ 26/7/ +f 60/4/ 59/6/ 28/3/ +f 62/69/ 61/71/ 30/70/ +f 64/65/ 63/67/ 32/66/ diff --git a/Faceball2030/assets/worldSkyBox.png b/Faceball2030/assets/worldSkyBox.png new file mode 100644 index 0000000000000000000000000000000000000000..195e6855bf897cd110dc5b89b279eb9394ef3a83 GIT binary patch literal 2237 zcmeAS@N?(olHy`uVBq!ia0y~yU;;9k7&zE~)R&4Yzkn1=v6E*A2N2Y7q;xPaaFlqu zIEGZrd3#M!$jOn1^&s!jzw2deTA!|;k@qtsBaC~o`JOhJ`KLdlq1O|o%1x5x2N1$y@EI=zbf#wP^FbJqHFerG8Di{ri(eyBy pFGkCU(QenemyData[GetID()].fireDelay; - game->bullets.push_back({ game->bullet, {pos.x,pos.y+0.15f,pos.z},rot,0.2f,{std::cosf(rot) * game->shotSpd,std::sinf(rot) * game->shotSpd }, YELLOW,false,GetID(),myIndex,blinking}); + game->bullets.push_back({ game->bullet, {pos.x,pos.y+0.15f,pos.z},rot,0.2f,1,{std::cosf(rot) * game->shotSpd,std::sinf(rot) * game->shotSpd }, YELLOW,false,GetID(),myIndex,blinking}); } void Enemy::ReloadBullet(float fElapsedTime) { @@ -436,6 +436,7 @@ void FaceBall::LoadLevel(int level) walls = { mapWalls }; MapWallsObjectIndex = objects.size()-1; objects.push_back({ mapFloor,{0,0,0},0,0 }); + objects.push_back({ worldSkyBox,{0,0,0},0,0 }); //objects.push_back({ game->mapExit,{(float)exitCoords.x+0.5f,0,(float)exitCoords.y+0.5f},0,0.4f }); exit = { game->mapExit,{(float)exitCoords.x + 0.5f,0.02f,(float)exitCoords.y + 0.5f},0,0.4f }; RegenerateMinimap(); @@ -918,23 +919,32 @@ void FaceBall::RenderBulletMesh(mat4x4& matView, std::vector& vecTrian void FaceBall::RenderMesh(mat4x4&matView,std::vector&vecTrianglesToRaster, Object&o,bool translucent) { for (auto& tri : o.mesh.tris) { if (translucent&&tri.tex != exit_wall_tex && tri.tex != bullet_tex ||!translucent&&(tri.tex==exit_wall_tex || tri.tex == bullet_tex)) { continue; } - Triangle triProjected, triTransformed, triViewed; + Triangle triScaled,triProjected, triTransformed, triViewed; mat4x4 localMat = Matrix_MakeIdentity(); mat4x4 rotMat = Matrix_MakeRotationY(o.rot); localMat = Matrix_MultiplyMatrix(localMat, rotMat); mat4x4 matTrans = Matrix_MakeTranslation(o.pos.x, o.pos.y, o.pos.z); localMat = Matrix_MultiplyMatrix(localMat, matTrans); - - triTransformed.p[0] = Matrix_MultiplyVector(localMat, tri.p[0]); - triTransformed.p[1] = Matrix_MultiplyVector(localMat, tri.p[1]); - triTransformed.p[2] = Matrix_MultiplyVector(localMat, tri.p[2]); - triTransformed.uv[0] = tri.uv[0]; - triTransformed.uv[1] = tri.uv[1]; - triTransformed.uv[2] = tri.uv[2]; - triTransformed.col[0] = tri.col[0]; - triTransformed.col[1] = tri.col[1]; - triTransformed.col[2] = tri.col[2]; - triTransformed.tex = tri.tex; + + for (int i = 0; i < 3; i++) { + triScaled.p[i].x = tri.p[i].x*o.scale; + triScaled.p[i].y = tri.p[i].y * o.scale; + triScaled.p[i].z = tri.p[i].z * o.scale; + triScaled.uv[i] = tri.uv[i]; + triScaled.col[i] = tri.col[i]; + } + triScaled.tex = tri.tex; + + triTransformed.p[0] = Matrix_MultiplyVector(localMat, triScaled.p[0]); + triTransformed.p[1] = Matrix_MultiplyVector(localMat, triScaled.p[1]); + triTransformed.p[2] = Matrix_MultiplyVector(localMat, triScaled.p[2]); + triTransformed.uv[0] = triScaled.uv[0]; + triTransformed.uv[1] = triScaled.uv[1]; + triTransformed.uv[2] = triScaled.uv[2]; + triTransformed.col[0] = triScaled.col[0]; + triTransformed.col[1] = triScaled.col[1]; + triTransformed.col[2] = triScaled.col[2]; + triTransformed.tex = triScaled.tex; vec3d normal, line1, line2; line1 = Vector_Sub(triTransformed.p[1], triTransformed.p[0]); @@ -1353,16 +1363,30 @@ void FaceBall::RenderWorld() { RenderMesh(matView, vecTrianglesToRaster, enemy); } } - for (auto& bullet : bullets) { - RenderBulletMesh(matView, vecTrianglesToRasterTranslucent, bullet); - } - for (auto& powerup : powerups) { - RenderPowerupMesh(matView, vecTrianglesToRasterTranslucent, powerup); - } + #ifdef OLC_PLATFORM_EMSCRIPTEN + for (auto& bullet : bullets) { + RenderBulletMesh(matView, vecTrianglesToRaster, bullet); + } + for (auto& powerup : powerups) { + RenderPowerupMesh(matView, vecTrianglesToRaster, powerup); + } + #else + for (auto& bullet : bullets) { + RenderBulletMesh(matView, vecTrianglesToRasterTranslucent, bullet); + } + for (auto& powerup : powerups) { + RenderPowerupMesh(matView, vecTrianglesToRasterTranslucent, powerup); + } + #endif RenderMesh(matView, vecTrianglesToRaster, walls); - RenderMesh(matView, vecTrianglesToRasterTranslucent, walls, true); - - //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;}); + #ifdef OLC_PLATFORM_EMSCRIPTEN + RenderMesh(matView, vecTrianglesToRaster, walls, true); + #else + RenderMesh(matView, vecTrianglesToRasterTranslucent, walls, true); + #endif + #ifdef OLC_PLATFORM_EMSCRIPTEN + 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;}); + #endif ClearBuffer(BLACK, true); triRenderCount = 0; for (auto& triToRaster : vecTrianglesToRaster) { @@ -1522,7 +1546,7 @@ void FaceBall::HandleKeys(float fElapsedTime) { pitch = 0; if (GetMouse(0).bPressed) { if (PlayerActiveShotCount(0) < shotLimit) { - Bullet newBullet={ bullet,{player.GetPos().x,player.GetPos().y - 0.15f, player.GetPos().z},fYaw,0.125f,{shotSpd * std::cosf(fYaw),shotSpd * std::sinf(fYaw)},GREEN,true }; + Bullet newBullet={ bullet,{player.GetPos().x,player.GetPos().y - 0.15f, player.GetPos().z},fYaw,0.125f,1,{shotSpd * std::cosf(fYaw),shotSpd * std::sinf(fYaw)},GREEN,true }; newBullet.playerIndex=0; bullets.push_back(newBullet); } @@ -1766,6 +1790,7 @@ bool FaceBall::OnUserCreate() powerup_tex = new Decal(new Sprite("assets/powerup.png")); powerup2_tex = new Decal(new Sprite("assets/powerup2.png")); powerups_tex = new Decal(new Sprite("assets/powerups.png")); + worldSkyBox_tex = new Decal(new Sprite("assets/worldSkyBox.png")); enemy_ShootMe = { "assets/enemies/ShootMe.obj", enemy_ShootMe_tex }; enemy_ShootMe2 = { "assets/enemies/ShootMe2.obj", enemy_ShootMe2_tex }; @@ -1776,6 +1801,7 @@ bool FaceBall::OnUserCreate() powerup = { "assets/Powerup.obj",powerup_tex}; powerup2 = { "assets/Powerup2.obj",powerup2_tex }; mapExit = { "assets/Exit.obj",dot }; + worldSkyBox = { "assets/worldSkyBox.obj",worldSkyBox_tex }; mapWalls.texture = wall_tex; mapFloor.texture = floor_tex; diff --git a/Faceball2030/main.h b/Faceball2030/main.h index 3bbbe67..0524c6c 100644 --- a/Faceball2030/main.h +++ b/Faceball2030/main.h @@ -144,6 +144,7 @@ struct Object { vec3d pos = { 0,0 }; float rot = 0; float radius = 0.2f; + float scale = 1.f; }; struct Bullet : Object{ @@ -263,7 +264,7 @@ class FaceBall : public PixelGameEngine private: Mesh mapWalls,mapFloor,enemy_ShootMe,undefined, enemy_Sonar, mapExit,enemy_ShootMe2,powerup,powerup2, - enemy_IShoot,enemy_IShoot2; + enemy_IShoot,enemy_IShoot2,worldSkyBox; Sprite*mapSpr; Decal*mapDecal; @@ -273,7 +274,7 @@ class FaceBall : public PixelGameEngine Decal* dot, * enemy_ShootMe_tex,*bullet_tex,*wall_tex,*floor_tex, *enemy_Sonar_tex,*hud,*exit_wall_tex,*enemy_ShootMe2_tex,*enemy_IShoot_tex, *life4,*life3,*life2,*life1,*crosshair,*hudmeter,*powerup_tex,*powerup2_tex, - *powerups_tex,*enemy_IShoot2_tex; + *powerups_tex,*enemy_IShoot2_tex, *worldSkyBox_tex; vi2d exitCoords = { 0,0 }; std::vectorknownGoodPositions; std::vector>map;