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