Why does my camera rotate around a point using this math?

My camera rotates around a point when I try to change orientation. If I rotate the camera, say, 30 degrees along the Y axis, instead of the camera 30 degrees to the right, the camera rotates around the point it was looking at.

o is the camera, A and B are 3D models. The lines show line-of-sight.
This is what I expect:
     A    B
     | > /
     |  /
     | /
     |/
     o

This is what actually happens:
     A    B
     |\
     | \
     |  \
     | > \
          o

Now, from my point of view, in order to move the camera, I have to move the world due to the inverse of this amount. Therefore, if I want to move +1 along the Z axis, I translate the world -1 along the Z axis. Since I use quaternions to represent the orientation, I use the inverse of the quaternion camera (since orientations are always single quaternions, I optimize by pairing instead of computing the opposite) to rotate the world by the desired amount.

, q - :

[1 - 2 * (q.y * q.y + q.z * q.z)   2 * (q.x * q.y - q.w * q.z)       2 * (q.x * q.z + q.w * q.y)         0]
|2 * (q.x * q.y + q.w * q.z)       1 - 2 * (q.x * q.x + q.z * q.z)   2 * (q.y * q.z - q.w * q.x)         0|
|2 * (q.x * q.z - q.w * q.y)       2 * (q.y * q.z + q.w * q.z)       1 - 2 * (q.x * q.x + q.y * q.y)     0|
[0                                 0                                 0                                   1]

:

[...   ...   ...  -x]
|...   ...   ...  -y|
|...   ...   ...  -z|
[0     0     0     1]

, , , . , , . , , - , . .

EDIT: . , , , (, ya za ). :

[...  ...  ...  -xa.dotProduct(cameraPos)]
|...  ...  ...  -ya.dotProduct(cameraPos)|
|...  ...  ...  -za.dotProduct(cameraPos)|
[...  ...  ...  ...                      ]

, .

+5
2

EDIT: . , , (, ya za ). :

[...  ...  ...  -xa.dotProduct(cameraPos)]
|...  ...  ...  -ya.dotProduct(cameraPos)|
|...  ...  ...  -za.dotProduct(cameraPos)|
[...  ...  ...  ...                      ]

, .

, , , . , OpenGL , , .

. . - , - ( ). , ​​ OpenGL, :

R t
0 1

3 × 3 , - . , .

+1

, . . , 90 , . : , , , ? , 0,0001 ? , -.

, - . :

  • :
    • / . sin/cos . (0, 1, 0)
    • - .
  • :
    • , , .
    • , right = target x up, x * right + y * up
    • . .

gluLookAt.

0

All Articles