| 622 | //---------------------------------------------------------------------------- |
| 623 | |
| 624 | void Vehicle::getCameraTransform(F32* pos, MatrixF* mat) |
| 625 | { |
| 626 | // Returns camera to world space transform |
| 627 | // Handles first person / third person camera position |
| 628 | if (isServerObject() && mShapeInstance) |
| 629 | mShapeInstance->animateNodeSubtrees(true); |
| 630 | |
| 631 | if (*pos == 0) |
| 632 | { |
| 633 | getRenderEyeTransform(mat); |
| 634 | } |
| 635 | else |
| 636 | { |
| 637 | // Get the shape's camera parameters. |
| 638 | F32 min, max; |
| 639 | MatrixF rot; |
| 640 | Point3F offset; |
| 641 | getCameraParameters(&min, &max, &offset, &rot); |
| 642 | |
| 643 | // Start with the current eye position |
| 644 | MatrixF eye; |
| 645 | getRenderEyeTransform(&eye); |
| 646 | |
| 647 | // Build a transform that points along the eye axis |
| 648 | // but where the Z axis is always up. |
| 649 | if (mDataBlock->cameraRoll) |
| 650 | mat->mul(eye, rot); |
| 651 | else |
| 652 | { |
| 653 | MatrixF cam(1); |
| 654 | VectorF x, y, z(0, 0, 1); |
| 655 | eye.getColumn(1, &y); |
| 656 | mCross(y, z, &x); |
| 657 | x.normalize(); |
| 658 | mCross(x, y, &z); |
| 659 | z.normalize(); |
| 660 | cam.setColumn(0, x); |
| 661 | cam.setColumn(1, y); |
| 662 | cam.setColumn(2, z); |
| 663 | mat->mul(cam, rot); |
| 664 | } |
| 665 | |
| 666 | // Camera is positioned straight back along the eye's -Y axis. |
| 667 | // A ray is cast to make sure the camera doesn't go through |
| 668 | // anything solid. |
| 669 | VectorF vp, vec; |
| 670 | vp.x = vp.z = 0; |
| 671 | vp.y = -(max - min) * *pos; |
| 672 | eye.mulV(vp, &vec); |
| 673 | |
| 674 | // Use the camera node as the starting position if it exists. |
| 675 | Point3F osp, sp; |
| 676 | if (mDataBlock->cameraNode != -1) |
| 677 | { |
| 678 | mShapeInstance->mNodeTransforms[mDataBlock->cameraNode].getColumn(3, &osp); |
| 679 | getRenderTransform().mulP(osp, &sp); |
| 680 | } |
| 681 | else |
no test coverage detected