| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "remoting/client/view_matrix.h" | 5 #include "remoting/client/view_matrix.h" |
| 6 | 6 |
| 7 namespace remoting { | 7 namespace remoting { |
| 8 | 8 |
| 9 ViewMatrix::ViewMatrix() : ViewMatrix(0.f, {0.f, 0.f}) {} | 9 ViewMatrix::ViewMatrix() : ViewMatrix(0.f, {0.f, 0.f}) {} |
| 10 | 10 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 } | 26 } |
| 27 | 27 |
| 28 void ViewMatrix::SetScale(float scale) { | 28 void ViewMatrix::SetScale(float scale) { |
| 29 scale_ = scale; | 29 scale_ = scale; |
| 30 } | 30 } |
| 31 | 31 |
| 32 float ViewMatrix::GetScale() const { | 32 float ViewMatrix::GetScale() const { |
| 33 return scale_; | 33 return scale_; |
| 34 } | 34 } |
| 35 | 35 |
| 36 void ViewMatrix::SetOffset(const Point& offset) { |
| 37 offset_ = offset; |
| 38 } |
| 39 |
| 36 void ViewMatrix::PostScale(const Point& pivot, float scale) { | 40 void ViewMatrix::PostScale(const Point& pivot, float scale) { |
| 37 scale_ *= scale; | 41 scale_ *= scale; |
| 38 offset_.x *= scale; | 42 offset_.x *= scale; |
| 39 offset_.x += (1.f - scale) * pivot.x; | 43 offset_.x += (1.f - scale) * pivot.x; |
| 40 offset_.y *= scale; | 44 offset_.y *= scale; |
| 41 offset_.y += (1.f - scale) * pivot.y; | 45 offset_.y += (1.f - scale) * pivot.y; |
| 42 } | 46 } |
| 43 | 47 |
| 44 void ViewMatrix::PostTranslate(const Vector2D& delta) { | 48 void ViewMatrix::PostTranslate(const Vector2D& delta) { |
| 45 offset_.x += delta.x; | 49 offset_.x += delta.x; |
| 46 offset_.y += delta.y; | 50 offset_.y += delta.y; |
| 47 } | 51 } |
| 48 | 52 |
| 49 ViewMatrix ViewMatrix::Invert() const { | 53 ViewMatrix ViewMatrix::Invert() const { |
| 50 return ViewMatrix(1.f / scale_, {-offset_.x / scale_, -offset_.y / scale_}); | 54 return ViewMatrix(1.f / scale_, {-offset_.x / scale_, -offset_.y / scale_}); |
| 51 } | 55 } |
| 52 | 56 |
| 53 std::array<float, 9> ViewMatrix::ToMatrixArray() const { | 57 std::array<float, 9> ViewMatrix::ToMatrixArray() const { |
| 54 return {{scale_, 0, offset_.x, // Row 1 | 58 return {{scale_, 0, offset_.x, // Row 1 |
| 55 0, scale_, offset_.y, // Row 2 | 59 0, scale_, offset_.y, // Row 2 |
| 56 0, 0, 1}}; | 60 0, 0, 1}}; |
| 57 } | 61 } |
| 58 | 62 |
| 59 bool ViewMatrix::IsEmpty() const { | 63 bool ViewMatrix::IsEmpty() const { |
| 60 return scale_ == 0.f && offset_.x == 0.f && offset_.y == 0.f; | 64 return scale_ == 0.f && offset_.x == 0.f && offset_.y == 0.f; |
| 61 } | 65 } |
| 62 | 66 |
| 63 } // namespace remoting | 67 } // namespace remoting |
| OLD | NEW |