added to main new featherc
This commit is contained in:
commit
b7f5f43777
97
src/Game.cpp
97
src/Game.cpp
@ -315,7 +315,9 @@ namespace ZL
|
|||||||
|
|
||||||
|
|
||||||
//spaceshipBase.Move(Vector3f{ -0.52998, -13, 0 });
|
//spaceshipBase.Move(Vector3f{ -0.52998, -13, 0 });
|
||||||
//spaceshipBase.Move(Vector3f{ -0.52998, -10, 10 });
|
spaceshipBase.Move(Vector3f{ -0.52998, 0, 10 });
|
||||||
|
|
||||||
|
//spaceshipBase.RotateByMatrix(Eigen::Quaternionf(Eigen::AngleAxisf(M_PI / 2.0, Eigen::Vector3f::UnitY())).toRotationMatrix());
|
||||||
|
|
||||||
spaceship.AssignFrom(spaceshipBase);
|
spaceship.AssignFrom(spaceshipBase);
|
||||||
spaceship.RefreshVBO();
|
spaceship.RefreshVBO();
|
||||||
@ -449,11 +451,11 @@ namespace ZL
|
|||||||
static_cast<float>(Environment::width) / static_cast<float>(Environment::height),
|
static_cast<float>(Environment::width) / static_cast<float>(Environment::height),
|
||||||
Environment::CONST_Z_NEAR, Environment::CONST_Z_FAR);
|
Environment::CONST_Z_NEAR, Environment::CONST_Z_FAR);
|
||||||
renderer.PushMatrix();
|
renderer.PushMatrix();
|
||||||
|
|
||||||
renderer.LoadIdentity();
|
renderer.LoadIdentity();
|
||||||
renderer.TranslateMatrix({ 0,0, -1.0f * Environment::zoom });
|
renderer.TranslateMatrix({ 0,0, -1.0f * Environment::zoom });
|
||||||
|
|
||||||
renderer.TranslateMatrix({ 0, -Environment::zoom * 0.03f, 0 });
|
renderer.TranslateMatrix({ 0, -Environment::zoom * 0.03f, 0 });
|
||||||
|
renderer.RotateMatrix(rotateShipMat);
|
||||||
glBindTexture(GL_TEXTURE_2D, spaceshipTexture->getTexID());
|
glBindTexture(GL_TEXTURE_2D, spaceshipTexture->getTexID());
|
||||||
renderer.DrawVertexRenderStruct(spaceship);
|
renderer.DrawVertexRenderStruct(spaceship);
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
@ -602,37 +604,62 @@ namespace ZL
|
|||||||
sparkEmitter.update(static_cast<float>(delta));
|
sparkEmitter.update(static_cast<float>(delta));
|
||||||
planetObject.update(static_cast<float>(delta));
|
planetObject.update(static_cast<float>(delta));
|
||||||
|
|
||||||
if (Environment::tapDownHold) {
|
if (Environment::tapDownHold && !uiManager.isUiInteraction())
|
||||||
|
{
|
||||||
float diffx = Environment::tapDownCurrentPos(0) - Environment::tapDownStartPos(0);
|
float diffx = Environment::tapDownCurrentPos(0) - Environment::tapDownStartPos(0);
|
||||||
float diffy = Environment::tapDownCurrentPos(1) - Environment::tapDownStartPos(1);
|
float diffy = Environment::tapDownCurrentPos(1) - Environment::tapDownStartPos(1);
|
||||||
|
|
||||||
if (abs(diffy) > 5.0 || abs(diffx) > 5.0) //threshold
|
if (isDraggingShip) {
|
||||||
{
|
if (std::abs(diffy) > 5.0f || std::abs(diffx) > 5.0f)
|
||||||
|
{
|
||||||
|
float velocity = std::sqrt(diffx * diffx + diffy * diffy);
|
||||||
|
Environment::shipVelocity = velocity * static_cast<float>(delta) / 100.0f;
|
||||||
|
|
||||||
float rotationPower = sqrtf(diffx * diffx + diffy * diffy);
|
float angleY = std::atan2(-diffx, -diffy);
|
||||||
float deltaAlpha = rotationPower * delta * static_cast<float>(M_PI) / 500000.f;
|
|
||||||
|
|
||||||
Eigen::Vector3f rotationDirection(diffy, diffx, 0.0f);
|
Eigen::Quaternionf q(Eigen::AngleAxisf(angleY, Eigen::Vector3f::UnitY()));
|
||||||
rotationDirection.normalize(); // Eigen-way нормализация
|
rotateShipMat = q.toRotationMatrix();
|
||||||
|
|
||||||
// Создаем кватернион через AngleAxis
|
if (!shipMoveLockActive) {
|
||||||
// Конструктор принимает (угол_в_радианах, ось_вращения)
|
lockedCameraMat = Environment::shipMatrix;
|
||||||
Eigen::Quaternionf rotateQuat(Eigen::AngleAxisf(deltaAlpha, rotationDirection));
|
shipMoveLockActive = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Environment::shipVelocity = 0.0f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (isDraggingCamera) {
|
||||||
|
if (std::abs(diffy) > 5.0f || std::abs(diffx) > 5.0f)
|
||||||
|
{
|
||||||
|
float rotationPower = std::sqrt(diffx * diffx + diffy * diffy);
|
||||||
|
float deltaAlpha = rotationPower * static_cast<float>(delta) * static_cast<float>(M_PI) / 500000.f;
|
||||||
|
|
||||||
Matrix3f rotateMat = rotateQuat.toRotationMatrix();
|
Eigen::Vector3f rotationDirection(diffy, diffx, 0.0f);
|
||||||
|
rotationDirection.normalize();
|
||||||
|
|
||||||
Environment::shipMatrix = Environment::shipMatrix * rotateMat;
|
Eigen::Quaternionf rotateQuat(Eigen::AngleAxisf(deltaAlpha, rotationDirection));
|
||||||
Environment::inverseShipMatrix = Environment::shipMatrix.inverse();
|
Matrix3f rotateMat = rotateQuat.toRotationMatrix();
|
||||||
|
|
||||||
|
Environment::shipMatrix = Environment::shipMatrix * rotateMat;
|
||||||
|
Environment::inverseShipMatrix = Environment::shipMatrix.inverse();
|
||||||
|
|
||||||
|
// плавное вращение (ВАЖНО!)
|
||||||
|
Environment::tapDownStartPos = Environment::tapDownCurrentPos;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fabs(Environment::shipVelocity) > 0.01f)
|
|
||||||
|
if (std::fabs(Environment::shipVelocity) > 0.01f)
|
||||||
{
|
{
|
||||||
Vector3f velocityDirection = { 0,0, -Environment::shipVelocity * delta / 1000.f };
|
Vector3f localMove = rotateShipMat * Vector3f{ 0, 0, -Environment::shipVelocity * static_cast<float>(delta) / 1000.f };
|
||||||
Vector3f velocityDirectionAdjusted = Environment::shipMatrix * velocityDirection;
|
|
||||||
Environment::shipPosition = Environment::shipPosition + velocityDirectionAdjusted;
|
Matrix3f camMat = shipMoveLockActive ? lockedCameraMat : Environment::shipMatrix;
|
||||||
|
|
||||||
|
Vector3f worldMove = camMat * localMove;
|
||||||
|
|
||||||
|
Environment::shipPosition = Environment::shipPosition + worldMove;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto& p : projectiles) {
|
for (auto& p : projectiles) {
|
||||||
@ -687,7 +714,10 @@ namespace ZL
|
|||||||
const float size = 0.5f;
|
const float size = 0.5f;
|
||||||
|
|
||||||
Vector3f localForward = { 0,0,-1 };
|
Vector3f localForward = { 0,0,-1 };
|
||||||
Vector3f worldForward = (Environment::shipMatrix * localForward).normalized();
|
Matrix3f camMat1 = shipMoveLockActive ? lockedCameraMat : Environment::shipMatrix;
|
||||||
|
|
||||||
|
Vector3f localForward1 = { 0,0,-1 };
|
||||||
|
Vector3f worldForward = (camMat1 * (rotateShipMat * localForward1)).normalized();
|
||||||
|
|
||||||
for (const auto& lo : localOffsets) {
|
for (const auto& lo : localOffsets) {
|
||||||
Vector3f worldPos = Environment::shipPosition + Environment::shipMatrix * lo;
|
Vector3f worldPos = Environment::shipPosition + Environment::shipMatrix * lo;
|
||||||
@ -847,13 +877,16 @@ namespace ZL
|
|||||||
}();
|
}();
|
||||||
|
|
||||||
if (!uiManager.isUiInteraction()) {
|
if (!uiManager.isUiInteraction()) {
|
||||||
Environment::tapDownHold = true;
|
if (mx < 400 && my > 400) {
|
||||||
|
isDraggingShip = true;
|
||||||
|
isDraggingCamera = false;
|
||||||
|
|
||||||
Environment::tapDownStartPos(0) = mx;
|
shipMoveLockActive = false; // новый drag -> новый lock
|
||||||
Environment::tapDownStartPos(1) = my;
|
}
|
||||||
|
else {
|
||||||
Environment::tapDownCurrentPos(0) = mx;
|
isDraggingShip = false;
|
||||||
Environment::tapDownCurrentPos(1) = my;
|
isDraggingCamera = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void Game::handleUp(int mx, int my)
|
void Game::handleUp(int mx, int my)
|
||||||
@ -865,6 +898,16 @@ namespace ZL
|
|||||||
|
|
||||||
if (!uiManager.isUiInteraction()) {
|
if (!uiManager.isUiInteraction()) {
|
||||||
Environment::tapDownHold = false;
|
Environment::tapDownHold = false;
|
||||||
|
Environment::shipVelocity = 0.0f;
|
||||||
|
|
||||||
|
shipMoveLockActive = false;
|
||||||
|
|
||||||
|
if (isDraggingCamera) {
|
||||||
|
rotateShipMat = Matrix3f::Identity();
|
||||||
|
}
|
||||||
|
|
||||||
|
isDraggingShip = false;
|
||||||
|
isDraggingCamera = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -112,6 +112,11 @@ namespace ZL {
|
|||||||
|
|
||||||
TaskManager taskManager;
|
TaskManager taskManager;
|
||||||
|
|
||||||
|
bool isDraggingShip = false;
|
||||||
|
bool isDraggingCamera = false;
|
||||||
|
Matrix3f rotateShipMat = Matrix3f::Identity();
|
||||||
|
bool shipMoveLockActive = false;
|
||||||
|
Matrix3f lockedCameraMat = Matrix3f::Identity();
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user