! Computes the modelView matrix associated with the Camera's position() and orientation(). This matrix converts from the world coordinates system to the Camera coordinates system, so that coordinates can then be projected on screen using the projection matrix (see computeProjectionMatrix()). Use getModelViewMatrix() to retrieve this matrix. \note You must call this method if your Camera is
| 398 | offscreen computations (using (un)projectedCoordinatesOf() for instance). loadModelViewMatrix() |
| 399 | does it otherwise. */ |
| 400 | void Camera::computeModelViewMatrix() const |
| 401 | { |
| 402 | if (modelViewMatrixIsUpToDate_) return; |
| 403 | |
| 404 | const Quaternion q = frame()->orientation(); |
| 405 | |
| 406 | const qreal q00 = 2.0 * q[0] * q[0]; |
| 407 | const qreal q11 = 2.0 * q[1] * q[1]; |
| 408 | const qreal q22 = 2.0 * q[2] * q[2]; |
| 409 | |
| 410 | const qreal q01 = 2.0 * q[0] * q[1]; |
| 411 | const qreal q02 = 2.0 * q[0] * q[2]; |
| 412 | const qreal q03 = 2.0 * q[0] * q[3]; |
| 413 | |
| 414 | const qreal q12 = 2.0 * q[1] * q[2]; |
| 415 | const qreal q13 = 2.0 * q[1] * q[3]; |
| 416 | |
| 417 | const qreal q23 = 2.0 * q[2] * q[3]; |
| 418 | |
| 419 | modelViewMatrix_[0] = 1.0 - q11 - q22; |
| 420 | modelViewMatrix_[1] = q01 - q23; |
| 421 | modelViewMatrix_[2] = q02 + q13; |
| 422 | modelViewMatrix_[3] = 0.0; |
| 423 | |
| 424 | modelViewMatrix_[4] = q01 + q23; |
| 425 | modelViewMatrix_[5] = 1.0 - q22 - q00; |
| 426 | modelViewMatrix_[6] = q12 - q03; |
| 427 | modelViewMatrix_[7] = 0.0; |
| 428 | |
| 429 | modelViewMatrix_[8] = q02 - q13; |
| 430 | modelViewMatrix_[9] = q12 + q03; |
| 431 | modelViewMatrix_[10] = 1.0 - q11 - q00; |
| 432 | modelViewMatrix_[11] = 0.0; |
| 433 | |
| 434 | const Vec t = q.inverseRotate(frame()->position()); |
| 435 | |
| 436 | modelViewMatrix_[12] = -t.x; |
| 437 | modelViewMatrix_[13] = -t.y; |
| 438 | modelViewMatrix_[14] = -t.z; |
| 439 | modelViewMatrix_[15] = 1.0; |
| 440 | |
| 441 | modelViewMatrixIsUpToDate_ = true; |
| 442 | } |
| 443 | |
| 444 | |
| 445 | /*! Loads the OpenGL \c GL_PROJECTION matrix with the Camera projection matrix. |
nothing calls this directly
no test coverage detected