Can someone explain how I can use Quanternions to use the mouse to look around like a FPS?

故事扮演 提交于 2019-12-03 17:19:11

A Simple Quaternion-Based Camera, designed to be used with gluLookAt.

http://www.gamedev.net/reference/articles/article1997.asp

Keep your delta changes low to avoid that (i.e < 45 degrees)

Just calculate a small "delta" matrix with the rotations for each frame, fold this into the camera matrix each frame. (by fold I mean: cam = cam * delta)

If you're running for a long time, you might get some numerical errors, so you need to re-orthogonalize it. (look it up if that seems to happen)

That's the easiest way to avoid gimbal lock when just playing around with things. Once you get more proficient, you'll understand the rest.

As for quaternions, just find a good lib for them that can convert them to rotation matrices, then use the same technique (compute delta quat, multiply into main quat).

I would represent everything in polar coordinates. The wikipedia page should get you started.

You don't really need quaternions for that simple case, what you need is to input your heading and pitch into a 3-dimensional matrix calculation:

  1. Use your heading value with a rotation on Y axis to calculate MY

  2. Use your pitch value with a rotation on X axis to calculate MX

  3. For each point P, calculate R = MX * MY * P

The calculation can be done in 2 ways:

  1. T = MY * P, then R = MX * T

  2. T = MX * MY, then R = T * P

The first way is slower but easier to code at first, the second one is faster but you will need to code a matrix-matrix multiplication function.

ps. See http://en.wikipedia.org/wiki/Rotation_matrix#Dimension_three for the matrices

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!