Working on adding Eigen
This commit is contained in:
1 parent
c553780b6e
commit
9bfe2bef89
16 files changed
+402
-503
No files matched your search
+21
-30
@@ -19,12 +19,12 @@ namespace ZL
|
||||
|
||||
|
||||
|
||||
Vector4f generateRandomQuaternion(std::mt19937& gen)
|
||||
Eigen::Quaternionf generateRandomQuaternion(std::mt19937& gen)
|
||||
{
|
||||
|
||||
std::normal_distribution<> distrib(0.0, 1.0);
|
||||
|
||||
Vector4f randomQuat = {
|
||||
Eigen::Quaternionf randomQuat = {
|
||||
(float)distrib(gen),
|
||||
(float)distrib(gen),
|
||||
(float)distrib(gen),
|
||||
@@ -81,7 +81,7 @@ namespace ZL
|
||||
|
||||
if (accepted)
|
||||
{
|
||||
Vector4f randomQuat = generateRandomQuaternion(gen);
|
||||
Eigen::Quaternionf randomQuat = generateRandomQuaternion(gen);
|
||||
|
||||
Matrix3f randomMatrix = QuatToMatrix(randomQuat);
|
||||
|
||||
@@ -92,7 +92,6 @@ namespace ZL
|
||||
}
|
||||
|
||||
if (!accepted) {
|
||||
std::cerr << "Ïðåäóïðåæäåíèå: Íå óäàëîñü ñãåíåðèðîâàòü " << N << " îáúåêòîâ. Ñãåíåðèðîâàíî: " << generatedCount << std::endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -556,27 +555,21 @@ namespace ZL
|
||||
|
||||
if (Environment::tapDownHold) {
|
||||
|
||||
float diffx = Environment::tapDownCurrentPos.v[0] - Environment::tapDownStartPos.v[0];
|
||||
float diffy = Environment::tapDownCurrentPos.v[1] - Environment::tapDownStartPos.v[1];
|
||||
float diffx = Environment::tapDownCurrentPos(0) - Environment::tapDownStartPos(0);
|
||||
float diffy = Environment::tapDownCurrentPos(1) - Environment::tapDownStartPos(1);
|
||||
|
||||
if (abs(diffy) > 5.0 || abs(diffx) > 5.0) //threshold
|
||||
{
|
||||
|
||||
float rotationPower = sqrtf(diffx * diffx + diffy * diffy);
|
||||
float deltaAlpha = rotationPower * delta * static_cast<float>(M_PI) / 500000.f;
|
||||
|
||||
//std::cout << rotationPower << std::endl;
|
||||
Eigen::Vector3f rotationDirection(diffy, diffx, 0.0f);
|
||||
rotationDirection.normalize(); // Eigen-way нормализация
|
||||
|
||||
float deltaAlpha = rotationPower * delta * M_PI / 500000.f;
|
||||
|
||||
Vector3f rotationDirection = { diffy, diffx, 0 };
|
||||
|
||||
rotationDirection = rotationDirection.normalized();
|
||||
|
||||
Vector4f rotateQuat = {
|
||||
rotationDirection.v[0] * sin(deltaAlpha * 0.5f),
|
||||
rotationDirection.v[1] * sin(deltaAlpha * 0.5f),
|
||||
rotationDirection.v[2] * sin(deltaAlpha * 0.5f),
|
||||
cos(deltaAlpha * 0.5f) };
|
||||
// Создаем кватернион через AngleAxis
|
||||
// Конструктор принимает (угол_в_радианах, ось_вращения)
|
||||
Eigen::Quaternionf rotateQuat(Eigen::AngleAxisf(deltaAlpha, rotationDirection));
|
||||
|
||||
Matrix3f rotateMat = QuatToMatrix(rotateQuat);
|
||||
|
||||
@@ -677,8 +670,6 @@ namespace ZL
|
||||
Environment::exitGameLoop = true;
|
||||
}
|
||||
else if (event.type == SDL_MOUSEBUTTONDOWN) {
|
||||
// 1. Îáðàáîòêà íàæàòèÿ êíîïêè ìûøè
|
||||
|
||||
int mx = event.button.x;
|
||||
int my = event.button.y;
|
||||
int uiX = mx;
|
||||
@@ -709,16 +700,16 @@ namespace ZL
|
||||
|
||||
if (!uiManager.isUiInteraction()) {
|
||||
Environment::tapDownHold = true;
|
||||
// Êîîðäèíàòû íà÷àëüíîãî íàæàòèÿ
|
||||
Environment::tapDownStartPos.v[0] = mx;
|
||||
Environment::tapDownStartPos.v[1] = my;
|
||||
// Íà÷àëüíàÿ ïîçèöèÿ òàêæå ñòàíîâèòñÿ òåêóùåé
|
||||
Environment::tapDownCurrentPos.v[0] = mx;
|
||||
Environment::tapDownCurrentPos.v[1] = my;
|
||||
|
||||
Environment::tapDownStartPos(0) = mx;
|
||||
Environment::tapDownStartPos(1) = my;
|
||||
|
||||
Environment::tapDownCurrentPos(0) = mx;
|
||||
Environment::tapDownCurrentPos(1) = my;
|
||||
}
|
||||
}
|
||||
else if (event.type == SDL_MOUSEBUTTONUP) {
|
||||
// 2. Îáðàáîòêà îòïóñêàíèÿ êíîïêè ìûøè
|
||||
|
||||
int mx = event.button.x;
|
||||
int my = event.button.y;
|
||||
int uiX = mx;
|
||||
@@ -731,7 +722,7 @@ namespace ZL
|
||||
}
|
||||
}
|
||||
else if (event.type == SDL_MOUSEMOTION) {
|
||||
// 3. Îáðàáîòêà ïåðåìåùåíèÿ ìûøè
|
||||
|
||||
int mx = event.motion.x;
|
||||
int my = event.motion.y;
|
||||
int uiX = mx;
|
||||
@@ -740,8 +731,8 @@ namespace ZL
|
||||
uiManager.onMouseMove(uiX, uiY);
|
||||
|
||||
if (Environment::tapDownHold && !uiManager.isUiInteraction()) {
|
||||
Environment::tapDownCurrentPos.v[0] = mx;
|
||||
Environment::tapDownCurrentPos.v[1] = my;
|
||||
Environment::tapDownCurrentPos(0) = mx;
|
||||
Environment::tapDownCurrentPos(1) = my;
|
||||
}
|
||||
}
|
||||
else if (event.type == SDL_MOUSEWHEEL) {
|
||||
|
||||
Reference in new issue
Block a user