123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- #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)
- {
- // front
- front.setAngles(interpolate(lag, oldLengthAngle, lengthAngle), interpolate(lag, oldWidthAngle, widthAngle));
- // back
- back.setInverse(front);
- // left
- left = front;
- left.cross(0.0f, 1.0f, 0.0f);
- left.normalize();
- // right
- right.setInverse(left);
- // up
- up = front;
- up.cross(right);
- up.normalize();
- // down
- down.setInverse(up);
- // interpolated position
- interPosition = oldPosition;
- interPosition.addMul(position, lag);
- interPosition.addMul(oldPosition, -lag);
- // flat front
- flatFront = front;
- flatFront.setY(0.0f);
- flatFront.normalize();
- // flat back
- flatBack.setInverse(flatFront);
- // flat left
- flatLeft = flatFront;
- flatLeft.cross(0.0f, 1.0f, 0.0f);
- flatLeft.normalize();
- // flat right
- flatRight.setInverse(flatLeft);
- // flat up
- flatUp.set(0.0f, 1.0f, 0.0f);
- // flat down
- flatDown.setInverse(flatUp);
- }
|