OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "remoting/client/view_matrix.h" |
| 6 |
| 7 namespace remoting { |
| 8 |
| 9 ViewMatrix::ViewMatrix() : ViewMatrix(0.f, {0.f, 0.f}) {} |
| 10 |
| 11 ViewMatrix::ViewMatrix(float scale, const Vector2D& offset) |
| 12 : scale_(scale), offset_(offset) {} |
| 13 |
| 14 ViewMatrix::~ViewMatrix() {} |
| 15 |
| 16 ViewMatrix::Point ViewMatrix::MapPoint(const Point& point) const { |
| 17 float x = scale_ * point.x + offset_.x; |
| 18 float y = scale_ * point.y + offset_.y; |
| 19 return {x, y}; |
| 20 } |
| 21 |
| 22 ViewMatrix::Vector2D ViewMatrix::MapVector(const Vector2D& vector) const { |
| 23 float x = scale_ * vector.x; |
| 24 float y = scale_ * vector.y; |
| 25 return {x, y}; |
| 26 } |
| 27 |
| 28 void ViewMatrix::SetScale(float scale) { |
| 29 scale_ = scale; |
| 30 } |
| 31 |
| 32 float ViewMatrix::GetScale() const { |
| 33 return scale_; |
| 34 } |
| 35 |
| 36 void ViewMatrix::PostScale(const Point& pivot, float scale) { |
| 37 scale_ *= scale; |
| 38 offset_.x += (1.f - scale) * pivot.x; |
| 39 offset_.y += (1.f - scale) * pivot.y; |
| 40 } |
| 41 |
| 42 void ViewMatrix::PostTranslate(const Vector2D& delta) { |
| 43 offset_.x += delta.x; |
| 44 offset_.y += delta.y; |
| 45 } |
| 46 |
| 47 ViewMatrix ViewMatrix::Invert() const { |
| 48 return ViewMatrix(1.f / scale_, {-offset_.x / scale_, -offset_.y / scale_}); |
| 49 } |
| 50 |
| 51 std::array<float, 9> ViewMatrix::ToMatrixArray() const { |
| 52 return {{scale_, 0, offset_.x, // Row 1 |
| 53 0, scale_, offset_.y, // Row 2 |
| 54 0, 0, 1}}; |
| 55 } |
| 56 |
| 57 bool ViewMatrix::IsEmpty() const { |
| 58 return scale_ == 0.f && offset_.x == 0.f && offset_.y == 0.f; |
| 59 } |
| 60 |
| 61 } // namespace remoting |
OLD | NEW |