Как вращаться о центре экрана с помощью кватернионов в opengl?

Обычно я просто использую командную строку для svn, это - самый быстрый и самый легкий способ сделать это честно говоря, я рекомендовал бы попробовать его.
перед отклонением этого необходимо, вероятно, спросить себя, если существует действительно какая-либо функция, что Вам нужен GUI для, и предпочли ли Вы открывать приложение для GUI и загружать файлы, или просто вводить "svn co svn://site-goes-here.org/trunk",

можно легко добавить, удалить, переместить, фиксировать, скопировать или обновить файлы с простыми командами, данными с "svn справка", таким образом, для большинства пользователей это более чем достаточно.

6
задан tshepang 13 October 2014 в 06:31
поделиться

2 ответа

You should be able to solve this by applying rotation and translation matrices in the correct order. In your code you could translate back to the origin T(-pos_x, -pos_y, -pos_z), apply your rotation, and translate to the object center again T(pos_x, pos_y, pos_z). This should work in general, independent of how your rotation matrix is constructed.

1
ответ дан 17 December 2019 в 22:13
поделиться

Вот код, который я написал некоторое время назад для программы просмотра запуска трехступенчатой ​​ракеты. Я получил большую часть информации из http://www.euclideanspace.com/maths/geometry/rotations

Примечание: рыскание, тангаж и крен могут измениться для вас в зависимости от того, как вы настроили свою систему координат

      // Assuming the angles are in radians.
            double p = curPitch * Math.PI/180.0 / 2.0;
            double y = curYaw * Math.PI/180.0 / 2.0;
            double r = curRoll * Math.PI/180.0 / 2.0;

            double sinp = Math.sin(p);
            double siny = Math.sin(y);
            double sinr = Math.sin(r);
            double cosp = Math.cos(p);
            double cosy = Math.cos(y);
            double cosr = Math.cos(r);

            Vector3 axis = new Vector3();

            //here's the important part: how you get your quaternion vector!
            axis.x = sinr * cosp * cosy - cosr * sinp * siny;
            axis.y = cosr * sinp * cosy + sinr * cosp * siny;
            axis.z = cosr * cosp * siny - sinr * sinp * cosy;

            //now normalize the vector in case we want to use it again later
            axis = Vector3.normalizeVector(axis);

            orientation[1] = axis.x;
            orientation[2] = axis.y;
            orientation[3] = axis.z;

            //w is omega: the angle to rotate about the quaternion
            double w = cosr * cosp * cosy + sinr * sinp * siny;

            w = Math.acos(w) * 2.0;

            orientation[0] = w;

            gl.glPushMatrix();

              //translate object first, then rotate it.
              gl.glTranslated(curDisplacement[0] + saveDisplacement[0], -curDisplacement[1] + saveDisplacement[2], curDisplacement[2] + saveDisplacement[1]);

              //this order might be messed up because I screwed up my coordinate system, but the idea is still there
              gl.glRotated(orientation[0]*180/Math.PI, orientation[2]*180/Math.PI, orientation[3]*180/Math.PI, orientation[1]*180/Math.PI);

             //place your objects
             gl.glPopMatrix();

Надеюсь, это поможет!

0
ответ дан 17 December 2019 в 22:13
поделиться
Другие вопросы по тегам:

Похожие вопросы: