diff --git a/Environment.cpp b/Environment.cpp index 342edc6..bf53c8f 100644 --- a/Environment.cpp +++ b/Environment.cpp @@ -8,7 +8,7 @@ namespace ZL { int Environment::windowHeaderHeight = 0; int Environment::width = 0; int Environment::height = 0; -float Environment::zoom = 6.f; +float Environment::zoom = 20.f; bool Environment::leftPressed = false; bool Environment::rightPressed = false; diff --git a/Game.cpp b/Game.cpp index 75e9130..ca20430 100755 --- a/Game.cpp +++ b/Game.cpp @@ -17,6 +17,8 @@ namespace ZL const char* CONST_ZIP_FILE = ""; #endif + Matrix3f rotateShipMat = Matrix3f::Identity(); + Vector4f generateRandomQuaternion(std::mt19937& gen) { // Распределение для генерации случайных координат кватерниона @@ -310,6 +312,9 @@ void Game::drawShip() renderer.LoadIdentity(); renderer.TranslateMatrix({ 0,0, -1.0f * Environment::zoom }); + renderer.RotateMatrix(Environment::inverseShipMatrix); + + renderer.RotateMatrix(rotateShipMat); glBindTexture(GL_TEXTURE_2D, spaceshipTexture->getTexID()); @@ -364,6 +369,7 @@ void Game::drawBoxes() renderer.shaderManager.PopShader(); CheckGlError(); } + void Game::UpdateVolumeKnob() { float musicVolumeBarButtonButtonCenterY = volumeBarMinY + musicVolume * (volumeBarMaxY - volumeBarMinY); @@ -454,7 +460,7 @@ void Game::drawScene() { drawShip(); drawBoxes(); - drawUI(); + //drawUI(); CheckGlError(); } @@ -482,6 +488,32 @@ void Game::processTickCount() { if (abs(diffy) > 5.0 || abs(diffx) > 5.0) //threshold { + float velocity = sqrtf(diffx * diffx + diffy * diffy); + + Environment::shipVelocity = velocity * delta / 100; + + Vector3f direction = { diffx, 0, -diffy }; + + Vector3f origin = { 0,0, -1 }; + + float dir_module = sqrtf(diffx * diffx + diffy * diffy); + + float scalar = direction.v[0] * origin.v[0] + direction.v[1] * origin.v[1]+ direction.v[2] * origin.v[2]; + + float angle = acos(scalar / dir_module); + + Vector4f quat = { + 0, + 1 * sin(angle / 2), + 0, + cos(angle / 2) + + }; + + rotateShipMat = QuatToMatrix(quat); + + + /* float rotationPower = sqrtf(diffx * diffx + diffy * diffy); //std::cout << rotationPower << std::endl; @@ -502,14 +534,20 @@ void Game::processTickCount() { Environment::shipMatrix = MultMatrixMatrix(Environment::shipMatrix, rotateMat); Environment::inverseShipMatrix = InverseMatrix(Environment::shipMatrix); - + */ + } + else + { + Environment::shipVelocity = 0; } } if (fabs(Environment::shipVelocity) > 0.01f) { Vector3f velocityDirection = { 0,0, -Environment::shipVelocity*delta / 1000.f }; - Vector3f velocityDirectionAdjusted = MultMatrixVector(Environment::shipMatrix, velocityDirection); + + + Vector3f velocityDirectionAdjusted = MultMatrixVector(rotateShipMat, velocityDirection); Environment::shipPosition = Environment::shipPosition + velocityDirectionAdjusted; } @@ -546,12 +584,12 @@ void Game::update() { std::cout << mx << " " << my << '\n'; int uiX = mx; int uiY = Environment::height - my; - if (uiX >= volumeBarMinX && uiX <= volumeBarMaxX && - uiY >= volumeBarMinY && uiY <= volumeBarMaxY) { - isDraggingVolume = true; - UpdateVolumeFromMouse(mx, my); + + if (false) + { } - else { + else + { Environment::tapDownHold = true; // Координаты начального нажатия Environment::tapDownStartPos.v[0] = event.button.x; @@ -561,21 +599,19 @@ void Game::update() { Environment::tapDownCurrentPos.v[1] = event.button.y; } + } else if (event.type == SDL_MOUSEBUTTONUP) { // 2. Обработка отпускания кнопки мыши isDraggingVolume = false; Environment::tapDownHold = false; + Environment::shipVelocity = 0; } else if (event.type == SDL_MOUSEMOTION) { // 3. Обработка перемещения мыши int mx = event.motion.x; int my = event.motion.y; - if (isDraggingVolume) { - // Двигаем мышь по слайдеру — меняем громкость и позицию кружка - UpdateVolumeFromMouse(mx, my); - } if (Environment::tapDownHold) { // Обновление текущей позиции, если кнопка удерживается Environment::tapDownCurrentPos.v[0] = event.motion.x; @@ -596,6 +632,7 @@ void Game::update() { } else if (event.type == SDL_KEYUP) { + if (event.key.keysym.sym == SDLK_i) { Environment::shipVelocity += 1.f;