diff --git a/SQCSim-common/player.cpp b/SQCSim-common/player.cpp index dae069e..4227abe 100644 --- a/SQCSim-common/player.cpp +++ b/SQCSim-common/player.cpp @@ -204,11 +204,11 @@ Player::Sound Player::ApplyPhysics(Vector3f input, World* world, float elapsedTi void Player::ApplyTransformation(Transformation& transformation, bool rel, bool rot) const { transformation.ApplyRotation(-m_rotX, 1, 0, 0); transformation.ApplyRotation(-m_rotY, 0, 1, 0); + + if (rel) transformation.ApplyTranslation(-GetPOV()); - if (!rot) { - transformation.ApplyRotation(-m_rotX, 1, 0, 0); - transformation.ApplyRotation(-m_rotY, 0, 1, 0); - } + + } void Player::GetBooster(Booster boosttype) diff --git a/SQCSim2021/engine.cpp b/SQCSim2021/engine.cpp index d623682..48515e5 100644 --- a/SQCSim2021/engine.cpp +++ b/SQCSim2021/engine.cpp @@ -103,7 +103,7 @@ void Engine::Init() { m_world.SetSeed(seed); m_startTime = std::chrono::high_resolution_clock::now(); - + m_remotePlayer.SetPosition(Vector3f(.5, CHUNK_SIZE_Y + 10., .5)); // Gestion de souris. CenterMouse(); HideCursor(); @@ -188,70 +188,70 @@ void Engine::LoadResource() { //AJOUTER LES TEXTURES DANS L'ORDRE DE L'ÉNUM //STILL//STANDING - TextureAtlas::TextureIndex StillFront = m_animeAtlas.AddTexture(ANIME_PATH_STILL "BlueFrontRight.png"); - //TextureAtlas::TextureIndex StillQuarterFrontLeft = m_animeAtlas.AddTexture(ANIME_PATH_STILL "BlueLeft.png"); - //TextureAtlas::TextureIndex StillQuarterFrontRight = m_animeAtlas.AddTexture(ANIME_PATH_STILL "BlueRight.png"); - //TextureAtlas::TextureIndex StillProfiltLeft = m_animeAtlas.AddTexture(ANIME_PATH_STILL "BlueProfilLeft.png"); - //TextureAtlas::TextureIndex StillProfiltRight = m_animeAtlas.AddTexture(ANIME_PATH_STILL "BlueProfilRight.png"); - //TextureAtlas::TextureIndex StillQuarterBackLeft = m_animeAtlas.AddTexture(ANIME_PATH_STILL "BlueLeftBack.png"); - //TextureAtlas::TextureIndex StillQuarterBackRight = m_animeAtlas.AddTexture(ANIME_PATH_STILL "BlueRightBack.png"); - //TextureAtlas::TextureIndex StillBack = m_animeAtlas.AddTexture(ANIME_PATH_STILL "BlueBackRight.png"); + TextureAtlas::TextureIndex StillFront = m_animeAtlas.AddTexture(ANIME_PATH_STILL "BlueFrontRight.png"); //0 + TextureAtlas::TextureIndex StillQuarterFrontLeft = m_animeAtlas.AddTexture(ANIME_PATH_STILL "BlueLeft.png"); //1 + TextureAtlas::TextureIndex StillQuarterFrontRight = m_animeAtlas.AddTexture(ANIME_PATH_STILL "BlueRight.png"); //2 + TextureAtlas::TextureIndex StillProfiltLeft = m_animeAtlas.AddTexture(ANIME_PATH_STILL "BlueProfilLeft.png"); //3 + TextureAtlas::TextureIndex StillProfiltRight = m_animeAtlas.AddTexture(ANIME_PATH_STILL "BlueProfilRight.png"); //4 + TextureAtlas::TextureIndex StillQuarterBackLeft = m_animeAtlas.AddTexture(ANIME_PATH_STILL "BlueLeftBack.png"); //5 + TextureAtlas::TextureIndex StillQuarterBackRight = m_animeAtlas.AddTexture(ANIME_PATH_STILL "BlueRightBack.png"); //6 + TextureAtlas::TextureIndex StillBack = m_animeAtlas.AddTexture(ANIME_PATH_STILL "BlueBackRight.png"); //7 //SHOOTINGSTILL SANS TIRER - //TextureAtlas::TextureIndex StillFrontShoot = m_animeAtlas.AddTexture(ANIM_PATH_SSHOOT1 "BlueFrontRightShootingRight.png"); - //TextureAtlas::TextureIndex StillQuarterFrontLeftShoot = m_animeAtlas.AddTexture(ANIM_PATH_SSHOOT1 "BlueFrontRightShootingRight.png"); - //TextureAtlas::TextureIndex StillQuarterFrontRightShoot = m_animeAtlas.AddTexture(ANIM_PATH_SSHOOT1 "BlueRightShootingRight.png"); - //TextureAtlas::TextureIndex StillProfiltLeftShoot = m_animeAtlas.AddTexture(ANIM_PATH_SSHOOT1 "BlueProfilShootingLeft.png"); - //TextureAtlas::TextureIndex StillProfiltRightShoot = m_animeAtlas.AddTexture(ANIM_PATH_SSHOOT1 "BlueProfilShootingRight.png"); - //TextureAtlas::TextureIndex StillQuarterBackLeftShoot = m_animeAtlas.AddTexture(ANIM_PATH_SSHOOT1 "BlueBackLeftShootingLeft.png"); - //TextureAtlas::TextureIndex StillQuarterBackRightShoot = m_animeAtlas.AddTexture(ANIM_PATH_SSHOOT1 "BlueBackRightShootingRight.png"); - //TextureAtlas::TextureIndex StillBackShoot = m_animeAtlas.AddTexture(ANIM_PATH_SSHOOT1 "BlueShootingBackRight.png"); + //TextureAtlas::TextureIndex StillFrontShoot = m_animeAtlas.AddTexture(ANIM_PATH_SSHOOT1 "BlueFrontRightShootingRight.png"); ////9 + //TextureAtlas::TextureIndex StillQuarterFrontLeftShoot = m_animeAtlas.AddTexture(ANIM_PATH_SSHOOT1 "BlueFrontRightShootingRight.png"); ////10 + //TextureAtlas::TextureIndex StillQuarterFrontRightShoot = m_animeAtlas.AddTexture(ANIM_PATH_SSHOOT1 "BlueRightShootingRight.png"); ////11 + //TextureAtlas::TextureIndex StillProfiltLeftShoot = m_animeAtlas.AddTexture(ANIM_PATH_SSHOOT1 "BlueProfilShootingLeft.png"); ////12 + //TextureAtlas::TextureIndex StillProfiltRightShoot = m_animeAtlas.AddTexture(ANIM_PATH_SSHOOT1 "BlueProfilShootingRight.png"); ////13 + //TextureAtlas::TextureIndex StillQuarterBackLeftShoot = m_animeAtlas.AddTexture(ANIM_PATH_SSHOOT1 "BlueBackLeftShootingLeft.png"); ////14 + //TextureAtlas::TextureIndex StillQuarterBackRightShoot = m_animeAtlas.AddTexture(ANIM_PATH_SSHOOT1 "BlueBackRightShootingRight.png"); ////15 + //TextureAtlas::TextureIndex StillBackShoot = m_animeAtlas.AddTexture(ANIM_PATH_SSHOOT1 "BlueShootingBackRight.png"); ////16 //SHOOTINGSTILL TIRER - //TextureAtlas::TextureIndex StillFrontShootFire = m_animeAtlas.AddTexture(ANIM_PATH_SSHOOT2 "BlueFrontRightShootingRightShoot1.png"); - //TextureAtlas::TextureIndex StillQuarterFrontLeftFire = m_animeAtlas.AddTexture(ANIM_PATH_SSHOOT2 "BlueLeftShootingLeftShoot1.png"); - //TextureAtlas::TextureIndex StillQuarterFrontRightShootFire = m_animeAtlas.AddTexture(ANIM_PATH_SSHOOT2 "BlueRightShootingRightShoot1.png"); - //TextureAtlas::TextureIndex StillProfiltLeftShootFire = m_animeAtlas.AddTexture(ANIM_PATH_SSHOOT2 "BlueProfilShootingLeftShoot1.png"); - //TextureAtlas::TextureIndex StillProfiltRightShootFire = m_animeAtlas.AddTexture(ANIM_PATH_SSHOOT2 "BlueProfilShootingRightShoot1.png"); - //TextureAtlas::TextureIndex StillQuarterBackLeftShootFire = m_animeAtlas.AddTexture(ANIM_PATH_SSHOOT2 "BlueBackLeftShootingLeftShoot1.png"); - //TextureAtlas::TextureIndex StillQuarterBackRightShootFire = m_animeAtlas.AddTexture(ANIM_PATH_SSHOOT2 "BlueBackRightShootingRightShoot1.png"); - //TextureAtlas::TextureIndex StillBackShootFire = m_animeAtlas.AddTexture(ANIM_PATH_SSHOOT2 "BlueShootingBackRightShoot1.png"); + //TextureAtlas::TextureIndex StillFrontShootFire = m_animeAtlas.AddTexture(ANIM_PATH_SSHOOT2 "BlueFrontRightShootingRightShoot1.png"); ////17 + //TextureAtlas::TextureIndex StillQuarterFrontLeftFire = m_animeAtlas.AddTexture(ANIM_PATH_SSHOOT2 "BlueLeftShootingLeftShoot1.png"); ////18 + //TextureAtlas::TextureIndex StillQuarterFrontRightShootFire = m_animeAtlas.AddTexture(ANIM_PATH_SSHOOT2 "BlueRightShootingRightShoot1.png"); ////19 + //TextureAtlas::TextureIndex StillProfiltLeftShootFire = m_animeAtlas.AddTexture(ANIM_PATH_SSHOOT2 "BlueProfilShootingLeftShoot1.png"); ////20 + //TextureAtlas::TextureIndex StillProfiltRightShootFire = m_animeAtlas.AddTexture(ANIM_PATH_SSHOOT2 "BlueProfilShootingRightShoot1.png"); ////21 + //TextureAtlas::TextureIndex StillQuarterBackLeftShootFire = m_animeAtlas.AddTexture(ANIM_PATH_SSHOOT2 "BlueBackLeftShootingLeftShoot1.png"); ////22 + //TextureAtlas::TextureIndex StillQuarterBackRightShootFire = m_animeAtlas.AddTexture(ANIM_PATH_SSHOOT2 "BlueBackRightShootingRightShoot1.png"); ////23 + //TextureAtlas::TextureIndex StillBackShootFire = m_animeAtlas.AddTexture(ANIM_PATH_SSHOOT2 "BlueShootingBackRightShoot1.png"); ////24 //JUMP - //TextureAtlas::TextureIndex JumpFront = m_animeAtlas.AddTexture(ANIME_PATH_JUMP "BlueFrontJumpRight.png"); - //TextureAtlas::TextureIndex JumpQuarterFrontLeft = m_animeAtlas.AddTexture(ANIME_PATH_JUMP "BlueLeftFrontJumpLeft.png"); - //TextureAtlas::TextureIndex JumpQuarterFrontRight = m_animeAtlas.AddTexture(ANIME_PATH_JUMP "BlueRightFrontJumpRight.png"); - //TextureAtlas::TextureIndex JumpProfiltLeft = m_animeAtlas.AddTexture(ANIME_PATH_JUMP "BlueProfilJumpLeft.png"); - //TextureAtlas::TextureIndex JumpProfiltRight = m_animeAtlas.AddTexture(ANIME_PATH_JUMP "BlueProfilJumpRight.png"); - //TextureAtlas::TextureIndex JumpQuarterBackLeft = m_animeAtlas.AddTexture(ANIME_PATH_JUMP "BlueLeftBackJumpLeft.png"); - //TextureAtlas::TextureIndex JumpQuarterBackRight = m_animeAtlas.AddTexture(ANIME_PATH_JUMP "BlueRightBackJumpRight.png"); - //TextureAtlas::TextureIndex JumpBack = m_animeAtlas.AddTexture(ANIME_PATH_JUMP "BlueBackJumpRight.png"); + //TextureAtlas::TextureIndex JumpFront = m_animeAtlas.AddTexture(ANIME_PATH_JUMP "BlueFrontJumpRight.png"); ////25 + //TextureAtlas::TextureIndex JumpQuarterFrontLeft = m_animeAtlas.AddTexture(ANIME_PATH_JUMP "BlueLeftFrontJumpLeft.png"); ////26 + //TextureAtlas::TextureIndex JumpQuarterFrontRight = m_animeAtlas.AddTexture(ANIME_PATH_JUMP "BlueRightFrontJumpRight.png"); ////27 + //TextureAtlas::TextureIndex JumpProfiltLeft = m_animeAtlas.AddTexture(ANIME_PATH_JUMP "BlueProfilJumpLeft.png"); ////28 + //TextureAtlas::TextureIndex JumpProfiltRight = m_animeAtlas.AddTexture(ANIME_PATH_JUMP "BlueProfilJumpRight.png"); ////29 + //TextureAtlas::TextureIndex JumpQuarterBackLeft = m_animeAtlas.AddTexture(ANIME_PATH_JUMP "BlueLeftBackJumpLeft.png"); ////30 + //TextureAtlas::TextureIndex JumpQuarterBackRight = m_animeAtlas.AddTexture(ANIME_PATH_JUMP "BlueRightBackJumpRight.png"); ////31 + //TextureAtlas::TextureIndex JumpBack = m_animeAtlas.AddTexture(ANIME_PATH_JUMP "BlueBackJumpRight.png"); ////32 - //SHOOTINGJUMP SANS TIRER - //TextureAtlas::TextureIndex JumpFrontShoot = m_animeAtlas.AddTexture(ANIM_PATH_JSHOOT1 "BlueFrontJumpRightShootingRight.png"); - //TextureAtlas::TextureIndex JumpQuarterFrontLeftShoot = m_animeAtlas.AddTexture(ANIM_PATH_JSHOOT1 "BlueFrontLeftJumpLeftShootingLeft.png"); - //TextureAtlas::TextureIndex JumpQuarterFrontRightShoot = m_animeAtlas.AddTexture(ANIM_PATH_JSHOOT1 "BlueFrontRightJumpRightShootingRight.png"); - //TextureAtlas::TextureIndex JumpProfiltLeftShoot = m_animeAtlas.AddTexture(ANIM_PATH_JSHOOT1 "BlueProfilLeftJumpLeftShootingLeft.png"); - //TextureAtlas::TextureIndex JumpProfiltRightShoot = m_animeAtlas.AddTexture(ANIM_PATH_JSHOOT1 "BluerProfilRightJumprightShootingRight.png"); - //TextureAtlas::TextureIndex JumpQuarterBackLeftShoot = m_animeAtlas.AddTexture(ANIM_PATH_JSHOOT1 "BlueBackLeftJumpLeftShootingLeft.png"); - //TextureAtlas::TextureIndex JumpQuarterBackRightShoot = m_animeAtlas.AddTexture(ANIM_PATH_JSHOOT1 "BlueBackRightJumpRightShootingRight.png"); - //TextureAtlas::TextureIndex JumpBackShoot = m_animeAtlas.AddTexture(ANIM_PATH_JSHOOT1 "BlueBackJumpRightShootingRight.png"); - + //SHOOTINGJUMP SANS TIRER + //TextureAtlas::TextureIndex JumpFrontShoot = m_animeAtlas.AddTexture(ANIM_PATH_JSHOOT1 "BlueFrontJumpRightShootingRight.png"); ////33 + //TextureAtlas::TextureIndex JumpQuarterFrontLeftShoot = m_animeAtlas.AddTexture(ANIM_PATH_JSHOOT1 "BlueFrontLeftJumpLeftShootingLeft.png"); ////34 + //TextureAtlas::TextureIndex JumpQuarterFrontRightShoot = m_animeAtlas.AddTexture(ANIM_PATH_JSHOOT1 "BlueFrontRightJumpRightShootingRight.png"); ////35 + //TextureAtlas::TextureIndex JumpProfiltLeftShoot = m_animeAtlas.AddTexture(ANIM_PATH_JSHOOT1 "BlueProfilLeftJumpLeftShootingLeft.png"); ////36 + //TextureAtlas::TextureIndex JumpProfiltRightShoot = m_animeAtlas.AddTexture(ANIM_PATH_JSHOOT1 "BluerProfilRightJumprightShootingRight.png"); ////37 + //TextureAtlas::TextureIndex JumpQuarterBackLeftShoot = m_animeAtlas.AddTexture(ANIM_PATH_JSHOOT1 "BlueBackLeftJumpLeftShootingLeft.png"); ////38 + //TextureAtlas::TextureIndex JumpQuarterBackRightShoot = m_animeAtlas.AddTexture(ANIM_PATH_JSHOOT1 "BlueBackRightJumpRightShootingRight.png"); ////39 + //TextureAtlas::TextureIndex JumpBackShoot = m_animeAtlas.AddTexture(ANIM_PATH_JSHOOT1 "BlueBackJumpRightShootingRight.png"); ////40 + //SHOOTINGJUMP TIRER - //TextureAtlas::TextureIndex JumpFrontShootFire = m_animeAtlas.AddTexture(ANIM_PATH_JSHOOT2 "BlueFrontJumpRightShootingRightShoot1.png"); - //TextureAtlas::TextureIndex JumpQuarterFrontLeftShootFire = m_animeAtlas.AddTexture(ANIM_PATH_JSHOOT2 "BlueFrontLeftJumpLeftShootingLeftShoot1.png"); - //TextureAtlas::TextureIndex JumpQuarterFrontRightShootFire = m_animeAtlas.AddTexture(ANIM_PATH_JSHOOT2 "BlueFrontRightJumpRightShootingRightShoot1.png"); - //TextureAtlas::TextureIndex JumpProfiltLeftShootFire = m_animeAtlas.AddTexture(ANIM_PATH_JSHOOT2 "BlueProfilLeftJumpLeftShootingLeftShoot1.png"); - //TextureAtlas::TextureIndex JumpProfiltRightShootFire = m_animeAtlas.AddTexture(ANIM_PATH_JSHOOT2 "BluerProfilRightJumprightShootingRightShoot1.png"); - //TextureAtlas::TextureIndex JumpQuarterBackLeftShootFire = m_animeAtlas.AddTexture(ANIM_PATH_JSHOOT2 "BlueBackLeftJumpLeftShootingLeftShoot1.png"); - //TextureAtlas::TextureIndex JumpQuarterBackRightShootFire = m_animeAtlas.AddTexture(ANIM_PATH_JSHOOT2 "BlueBackRightJumpRightShootingRightShoot1.png"); - //TextureAtlas::TextureIndex JumpBackShootFire = m_animeAtlas.AddTexture(ANIM_PATH_JSHOOT2 "BlueBackJumpRightShootingRightShoot1.png"); - - - + //TextureAtlas::TextureIndex JumpFrontShootFire = m_animeAtlas.AddTexture(ANIM_PATH_JSHOOT2 "BlueFrontJumpRightShootingRightShoot1.png"); ////41 + //TextureAtlas::TextureIndex JumpQuarterFrontLeftShootFire = m_animeAtlas.AddTexture(ANIM_PATH_JSHOOT2 "BlueFrontLeftJumpLeftShootingLeftShoot1.png"); ////42 + //TextureAtlas::TextureIndex JumpQuarterFrontRightShootFire = m_animeAtlas.AddTexture(ANIM_PATH_JSHOOT2 "BlueFrontRightJumpRightShootingRightShoot1.png"); ////43 + //TextureAtlas::TextureIndex JumpProfiltLeftShootFire = m_animeAtlas.AddTexture(ANIM_PATH_JSHOOT2 "BlueProfilLeftJumpLeftShootingLeftShoot1.png"); ////44 + //TextureAtlas::TextureIndex JumpProfiltRightShootFire = m_animeAtlas.AddTexture(ANIM_PATH_JSHOOT2 "BluerProfilRightJumprightShootingRightShoot1.png"); ////45 + //TextureAtlas::TextureIndex JumpQuarterBackLeftShootFire = m_animeAtlas.AddTexture(ANIM_PATH_JSHOOT2 "BlueBackLeftJumpLeftShootingLeftShoot1.png"); ////46 + //TextureAtlas::TextureIndex JumpQuarterBackRightShootFire = m_animeAtlas.AddTexture(ANIM_PATH_JSHOOT2 "BlueBackRightJumpRightShootingRightShoot1.png"); ////47 + //TextureAtlas::TextureIndex JumpBackShootFire = m_animeAtlas.AddTexture(ANIM_PATH_JSHOOT2 "BlueBackJumpRightShootingRightShoot1.png"); ////48 + + + if (!m_animeAtlas.Generate(TEXTURE_SIZE, false)) { std::cout << " Unable to generate texture atlas ..." << std::endl; abort(); @@ -1331,6 +1331,8 @@ void Engine::Render(float elapsedTime) { m_renderer.UpdateMesh(&m_world, m_player.GetPosition(), m_blockinfo); //m_booster.RenderBillboard({ 195,16,195 }, m_textureAtlas, m_shader01, all); + /* m_remotePlayer.ApplyPhysics(Vector3f(0, 0, 0), &m_world, elapsedTime); + m_remotePlayer.Render(m_animeAtlas, m_shader01, all ,elapsedTime , m_player);*/ m_renderer.RenderWorld(&m_world, m_renderCount, m_player.GetPosition(), m_player.GetDirection(), all, m_shader01, m_textureAtlas); @@ -1510,7 +1512,7 @@ void Engine::Render(float elapsedTime) { for (auto& [key, player] : m_players) { RemotePlayer* rt = static_cast(player); glClear(GL_STENCIL_BUFFER_BIT); - rt->Render(m_animeAtlas, m_shader01, all, elapsedTime); + rt->Render(m_animeAtlas, m_shader01, all, elapsedTime, m_player); m_otherplayerpos = player->GetPosition(); // Aller chercher GetPosition des deux façon, voir si ça chie. } glEnable(GL_CULL_FACE); diff --git a/SQCSim2021/remoteplayer.cpp b/SQCSim2021/remoteplayer.cpp index d203fb0..fb30c3e 100644 --- a/SQCSim2021/remoteplayer.cpp +++ b/SQCSim2021/remoteplayer.cpp @@ -10,13 +10,13 @@ RemotePlayer::RemotePlayer(netprot::PlayerInfo pinfo) : m_pinfo(pinfo), m_aminacc(0.0f), m_animstate(Anim::STILL), m_team_id(0), current(), previous(), m_texture_front(), Player(Vector3f(0, 0, 0)){ - LoadTexture(m_texture_front, TEXTURE_PATH "AssetOtherPlayer/FinalPNGStanding/BlueFrontRight.png", false, false); + } RemotePlayer::RemotePlayer(netprot::PlayerInfo pinfo, const Vector3f& pos) : m_pinfo(pinfo), m_aminacc(0.0f), m_animstate(Anim::STILL), m_team_id(0), current(), previous(), m_texture_front(), Player(pos) { - LoadTexture(m_texture_front, TEXTURE_PATH "AssetOtherPlayer/FinalPNGStanding/BlueFrontRight.png", false, false); + } @@ -81,31 +81,67 @@ void RemotePlayer::Feed(const netprot::Output out) { //m_position = current.position; } -void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tran, float elapsedTime) + + + +void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tran, float elapsedTime, Player& camera) { - float x = GetPosition().x; - float y = GetPosition().y; - float z = GetPosition().z; + float width = 1.f; float height = 1.7f; + + Vector3f DiffCam = GetPosition() - camera.GetPosition(); + Vector3f UpCam = Vector3f(0.f, 1.f, 0.f); + Vector3f CrossA = DiffCam.Cross(UpCam); + Vector3f CrossB = DiffCam.Cross(CrossA); + CrossA.Normalize(); + CrossB.Normalize(); + Vector3f playerPosition = GetPosition() + Vector3f(0.f, -.75f, 0.f); + Vector3f v2 = (playerPosition + CrossA * 0.5 * width + CrossB * 0.5 * height); + Vector3f v1 = (playerPosition - CrossA * 0.5 * width + CrossB * 0.5 * height); + Vector3f v3 = (playerPosition + CrossA * 0.5 * width - CrossB * 0.5 * height); + Vector3f v4 = (playerPosition - CrossA * 0.5 * width - CrossB * 0.5 * height); + + Vector3f angleRemote = GetDirection(); + Vector3f angleCam = (v1 - v2).Cross(v3 - v2); + angleCam.y = 0; + angleRemote.y = 0; + angleCam.Normalize(); + angleRemote.Normalize(); + + float angle = angleRemote.Dot(angleCam); + int index = 0; - //Matrix4 mat4 = tran.GetMatrix(); - //mat4 VP = pMatrix * vMatrix; - //Vector3f CameraRight = Vector3f(mat4.Get11(), mat4.Get21(), mat4.Get31()); - //Vector3f CameraUp = Vector3f(mat4.Get12(), mat4.Get22(), mat4.Get32()); + Vector3f side = angleRemote.Cross(angleCam); - //Vector3f v1 = (m_position + CameraRight * 0.5 * width + CameraUp * -0.5 * width); - //Vector3f v2 = (m_position + CameraRight * 0.5 * width + CameraUp * 0.5 * width); - //Vector3f v4 = (m_position + CameraRight * -0.5 * width + CameraUp * -0.5 * width); - //Vector3f v3 = (m_position + CameraRight * -0.5 * width + CameraUp * 0.5 * width); - //tran.ApplyTranslation(m_position); + bool isLeft = side.y > 0; + if (angle >= 0.75 ) //Face //side positif + index = 0; + else if (angle >= 0.25 && isLeft) //Frontleft + index = 1; + else if (angle >= -0.25 && isLeft) //ProfileLeft + index = 3; + else if (angle >= -0.75 && isLeft) //BackLeft + index = 5; + else if (angle < -0.75) //Dos //side négatif + index = 7; + else if (angle >= 0.25 && !isLeft) //FrontRight + index = 2; + else if (angle >= -0.25 && !isLeft) //ProfileRight + index = 4; + else if (angle >= -0.75 && !isLeft) //BackRight + index = 6; + + std::cout << index << std::endl; + + std::cout << "angle: " << angle << std::endl; + float u, v, w, h; - //glDisable(GL_DEPTH_TEST); + shader.Use(); atlas.Bind(); - atlas.TextureIndexToCoord(0, u, v, w, h); - //glLoadIdentity(); + atlas.TextureIndexToCoord(index, u, v, w, h); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); @@ -113,20 +149,19 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr glLoadMatrixf(tran.GetMatrix().GetInternalValues()); glBegin(GL_QUADS); - glTexCoord2f(u, v); glVertex3f(x - width/2., y - height, z); //glVertex3f(v4.x, v4.y, v4.z);//glVertex3f(0, 50, 0); - glTexCoord2f(u + w, v); glVertex3f(x+width/2., y - height, z); //glVertex3f(v3.x, v3.y, v3.z); //glVertex3f(50,50, 0); - glTexCoord2f(u + w, v + h); glVertex3f(x+width/2., y, z); //glVertex3f(v2.x, v2.y, v2.z); //glVertex3f(50, 0, 0); - glTexCoord2f(u, v + h); glVertex3f(x-width/2., y, z); //glVertex3f(v1.x, v1.y, v1.z);// glVertex3f(0, 0, 0); - glEnd(); + glTexCoord2f(u, v); glVertex3f(v1.x, v1.y, v1.z); + glTexCoord2f(u + w, v); glVertex3f(v2.x, v2.y, v2.z); + glTexCoord2f(u + w, v + h); glVertex3f(v3.x, v3.y, v3.z); + glTexCoord2f(u, v + h); glVertex3f(v4.x, v4.y, v4.z); + glEnd(); glBlendFunc(GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR); glBlendEquation(GL_FUNC_SUBTRACT); glDisable(GL_BLEND); shader.Disable(); - //tran.ApplyTranslation(-m_position); - //glEnable(GL_DEPTH_TEST); + } bool RemotePlayer::LoadTexture(Texture& texture, const std::string& filename, bool useMipmaps, bool stopOnError) diff --git a/SQCSim2021/remoteplayer.h b/SQCSim2021/remoteplayer.h index e782000..fcd5626 100644 --- a/SQCSim2021/remoteplayer.h +++ b/SQCSim2021/remoteplayer.h @@ -21,7 +21,7 @@ public: void Init(); void Feed(const netprot::Output out); - void Render(TextureAtlas& atlas, Shader& shader, Transformation tran, float elapsedTime); + void Render(TextureAtlas& atlas, Shader& shader, Transformation tran, float elapsedTime, Player& camera); bool LoadTexture(Texture& texture, const std::string& filename, bool useMipmaps, bool stopOnError); void SetPosition(Vector3f pos) { m_position = pos; }