123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- #include "client/math/Camera.h"
- #include "client/Utils.h"
- Camera::Camera() : oldLengthAngle(0), lengthAngle(0), oldWidthAngle(0), widthAngle(0) {
- }
- const Vector& Camera::getFront() const {
- return front;
- }
- const Vector& Camera::getBack() const {
- return back;
- }
- const Vector& Camera::getRight() const {
- return right;
- }
- const Vector& Camera::getLeft() const {
- return left;
- }
- const Vector& Camera::getUp() const {
- return up;
- }
- const Vector& Camera::getDown() const {
- return down;
- }
- const Vector& Camera::getFlatFront() const {
- return flatFront;
- }
- const Vector& Camera::getFlatBack() const {
- return flatBack;
- }
- const Vector& Camera::getFlatRight() const {
- return flatRight;
- }
- const Vector& Camera::getFlatLeft() const {
- return flatLeft;
- }
- const Vector& Camera::getFlatUp() const {
- return flatUp;
- }
- const Vector& Camera::getFlatDown() const {
- return flatDown;
- }
- const Vector& Camera::getPosition() const {
- return interPosition;
- }
- void Camera::storePosition() {
- oldPosition = position;
- oldLengthAngle = lengthAngle;
- oldWidthAngle = widthAngle;
- }
- void Camera::setPosition(const Vector& pos, float length, float width) {
- position = pos;
- lengthAngle = length;
- widthAngle = width;
- }
- void Camera::update(float lag) {
- // back
- back.setAngles(interpolate(lag, oldLengthAngle, lengthAngle), interpolate(lag, oldWidthAngle, widthAngle));
- // front
- front.setInverse(back);
- // right
- right = front;
- right.cross(0.0f, 1.0f, 0.0f);
- right.normalize();
- // left
- left.setInverse(right);
- // up
- up = front;
- up.cross(left);
- up.normalize();
- // down
- down.setInverse(up);
- // interpolated position
- interPosition = oldPosition;
- interPosition.addMul(position, lag);
- interPosition.addMul(oldPosition, -lag);
- // flat back
- flatBack = back;
- flatBack.setY(0.0f);
- flatBack.normalize();
- // flat back
- flatFront.setInverse(flatBack);
- // flat right
- flatRight = front;
- flatRight.cross(0.0f, 1.0f, 0.0f);
- flatRight.normalize();
- // flat left
- flatLeft.setInverse(flatRight);
- // flat up
- flatUp.set(0.0f, 1.0f, 0.0f);
- // flat down
- flatDown.setInverse(flatUp);
- }
|