Index: chrome/browser/android/vr_shell/ui_elements.cc |
diff --git a/chrome/browser/android/vr_shell/ui_elements.cc b/chrome/browser/android/vr_shell/ui_elements.cc |
index c779d37ded8248002585e81569dc21c2bb76d446..6902709631f6c58f6b7195624264844b713832ca 100644 |
--- a/chrome/browser/android/vr_shell/ui_elements.cc |
+++ b/chrome/browser/android/vr_shell/ui_elements.cc |
@@ -9,25 +9,23 @@ |
#include "base/logging.h" |
#include "chrome/browser/android/vr_shell/animation.h" |
#include "chrome/browser/android/vr_shell/easing.h" |
+#include "device/vr/vr_math.h" |
namespace vr_shell { |
namespace { |
-bool GetRayPlaneDistance(const gvr::Vec3f& ray_origin, |
- const gvr::Vec3f& ray_vector, |
- const gvr::Vec3f& plane_origin, |
- const gvr::Vec3f& plane_normal, |
+bool GetRayPlaneDistance(const gfx::Point3F& ray_origin, |
+ const gfx::Vector3dF& ray_vector, |
+ const gfx::Point3F& plane_origin, |
+ const gfx::Vector3dF& plane_normal, |
float* distance) { |
- float denom = vr_shell::VectorDot(ray_vector, plane_normal); |
+ float denom = gfx::DotProduct(ray_vector, plane_normal); |
if (denom == 0) { |
return false; |
} |
- gvr::Vec3f rel; |
- rel.x = ray_origin.x - plane_origin.x; |
- rel.y = ray_origin.y - plane_origin.y; |
- rel.z = ray_origin.z - plane_origin.z; |
- *distance = -vr_shell::VectorDot(plane_normal, rel) / denom; |
+ gfx::Vector3dF rel = ray_origin - plane_origin; |
+ *distance = -gfx::DotProduct(plane_normal, rel) / denom; |
return true; |
} |
@@ -38,59 +36,66 @@ Transform::Transform() { |
} |
void Transform::MakeIdentity() { |
- SetIdentityM(to_world); |
+ vr::SetIdentityM(&to_world); |
} |
-void Transform::Rotate(gvr::Quatf quat) { |
+void Transform::Rotate(const vr::Quatf& quat) { |
// TODO(klausw): use specialized rotation code? Constructing the matrix |
// via axis-angle quaternion is inefficient. |
- gvr::Mat4f forward = QuatToMatrix(quat); |
- to_world = MatrixMul(forward, to_world); |
+ vr::Matf forward; |
+ vr::QuatToMatrix(quat, &forward); |
+ vr::Matf to_world_copy = to_world; |
+ vr::MatrixMul(forward, to_world_copy, &to_world); |
} |
-void Transform::Rotate(float ax, float ay, float az, float rad) { |
- Rotate(QuatFromAxisAngle({ax, ay, az}, rad)); |
+void Transform::Rotate(const vr::RotationAxisAngle& axis_angle) { |
+ Rotate(vr::QuatFromAxisAngle(axis_angle)); |
} |
-void Transform::Translate(float tx, float ty, float tz) { |
- TranslateM(to_world, to_world, tx, ty, tz); |
+void Transform::Translate(const gfx::Vector3dF& translation) { |
+ vr::TranslateM(to_world, translation, &to_world); |
} |
-void Transform::Scale(float sx, float sy, float sz) { |
- ScaleM(to_world, to_world, sx, sy, sz); |
+void Transform::Scale(const gfx::Vector3dF& scale) { |
+ vr::ScaleM(to_world, scale, &to_world); |
} |
-const gvr::Mat4f& WorldRectangle::TransformMatrix() const { |
+const vr::Matf& WorldRectangle::TransformMatrix() const { |
return transform_.to_world; |
} |
-gvr::Vec3f WorldRectangle::GetCenter() const { |
- const gvr::Vec3f kOrigin = {0.0f, 0.0f, 0.0f}; |
- return MatrixVectorMul(transform_.to_world, kOrigin); |
+gfx::Point3F WorldRectangle::GetCenter() const { |
+ const gfx::Point3F kOrigin(0.0f, 0.0f, 0.0f); |
+ const gfx::Vector3dF& translation = vr::GetTranslation(transform_.to_world); |
acondor_
2017/04/11 15:00:00
Why not return translation directly?
mthiesse
2017/04/11 19:21:06
Translation's a vector, and we want to return a po
|
+ return kOrigin + translation; |
} |
-gvr::Vec2f WorldRectangle::GetUnitRectangleCoordinates( |
- const gvr::Vec3f& world_point) { |
- const gvr::Mat4f& transform = transform_.to_world; |
- gvr::Vec3f origin = MatrixVectorMul(transform, gvr::Vec3f({0, 0, 0})); |
- gvr::Vec3f xAxis = MatrixVectorMul(transform, gvr::Vec3f({1, 0, 0})); |
- gvr::Vec3f yAxis = MatrixVectorMul(transform, gvr::Vec3f({0, 1, 0})); |
- xAxis = VectorSubtract(xAxis, origin); |
- yAxis = VectorSubtract(yAxis, origin); |
- gvr::Vec3f point = VectorSubtract(world_point, origin); |
- |
- float x = VectorDot(point, xAxis) / VectorDot(xAxis, xAxis); |
- float y = VectorDot(point, yAxis) / VectorDot(yAxis, yAxis); |
- return {x, y}; |
+gfx::PointF WorldRectangle::GetUnitRectangleCoordinates( |
+ const gfx::Point3F& world_point) { |
+ const vr::Matf& transform = transform_.to_world; |
+ gfx::Vector3dF origin = |
+ vr::MatrixVectorMul(transform, gfx::Vector3dF(0, 0, 0)); |
acondor_
2017/04/11 15:00:00
vr::GetTranslation should be faster
mthiesse
2017/04/11 19:21:06
Added a TODO to do this in a followup.
|
+ gfx::Vector3dF x_axis = |
+ vr::MatrixVectorMul(transform, gfx::Vector3dF(1, 0, 0)); |
acondor_
2017/04/11 15:00:00
vr::MatrixVectorRotate should be faster
mthiesse
2017/04/11 19:21:06
Acknowledged.
|
+ gfx::Vector3dF y_axis = |
+ vr::MatrixVectorMul(transform, gfx::Vector3dF(0, 1, 0)); |
+ x_axis.Subtract(origin); |
+ y_axis.Subtract(origin); |
+ gfx::Point3F point = world_point - origin; |
+ gfx::Vector3dF v_point(point.x(), point.y(), point.z()); |
+ |
+ float x = gfx::DotProduct(v_point, x_axis) / gfx::DotProduct(x_axis, x_axis); |
+ float y = gfx::DotProduct(v_point, y_axis) / gfx::DotProduct(y_axis, y_axis); |
+ return gfx::PointF(x, y); |
} |
-gvr::Vec3f WorldRectangle::GetNormal() const { |
- const gvr::Vec3f kNormalOrig = {0.0f, 0.0f, -1.0f}; |
- return MatrixVectorRotate(transform_.to_world, kNormalOrig); |
+gfx::Vector3dF WorldRectangle::GetNormal() const { |
+ const gfx::Vector3dF kNormalOrig = {0.0f, 0.0f, -1.0f}; |
+ return vr::MatrixVectorRotate(transform_.to_world, kNormalOrig); |
} |
-bool WorldRectangle::GetRayDistance(const gvr::Vec3f& ray_origin, |
- const gvr::Vec3f& ray_vector, |
+bool WorldRectangle::GetRayDistance(const gfx::Point3F& ray_origin, |
+ const gfx::Vector3dF& ray_vector, |
float* distance) const { |
return GetRayPlaneDistance(ray_origin, ray_vector, GetCenter(), GetNormal(), |
distance); |
@@ -110,19 +115,19 @@ void ContentRectangle::Animate(int64_t time) { |
if (animation.from.size() == 0) { |
switch (animation.property) { |
case Animation::COPYRECT: |
- animation.from.push_back(copy_rect.x); |
- animation.from.push_back(copy_rect.y); |
- animation.from.push_back(copy_rect.width); |
- animation.from.push_back(copy_rect.height); |
+ animation.from.push_back(copy_rect.x()); |
+ animation.from.push_back(copy_rect.y()); |
+ animation.from.push_back(copy_rect.width()); |
+ animation.from.push_back(copy_rect.height()); |
break; |
case Animation::SIZE: |
- animation.from.push_back(size.x); |
- animation.from.push_back(size.y); |
+ animation.from.push_back(size.x()); |
+ animation.from.push_back(size.y()); |
break; |
case Animation::SCALE: |
- animation.from.push_back(scale.x); |
- animation.from.push_back(scale.y); |
- animation.from.push_back(scale.z); |
+ animation.from.push_back(scale.x()); |
+ animation.from.push_back(scale.y()); |
+ animation.from.push_back(scale.z()); |
break; |
case Animation::ROTATION: |
animation.from.push_back(rotation.x); |
@@ -131,9 +136,9 @@ void ContentRectangle::Animate(int64_t time) { |
animation.from.push_back(rotation.angle); |
break; |
case Animation::TRANSLATION: |
- animation.from.push_back(translation.x); |
- animation.from.push_back(translation.y); |
- animation.from.push_back(translation.z); |
+ animation.from.push_back(translation.x()); |
+ animation.from.push_back(translation.y()); |
+ animation.from.push_back(translation.z()); |
break; |
case Animation::OPACITY: |
animation.from.push_back(opacity); |
@@ -157,21 +162,16 @@ void ContentRectangle::Animate(int64_t time) { |
switch (animation.property) { |
case Animation::COPYRECT: |
CHECK_EQ(animation.from.size(), 4u); |
- copy_rect.x = values[0]; |
- copy_rect.y = values[1]; |
- copy_rect.width = values[2]; |
- copy_rect.height = values[3]; |
+ copy_rect.SetRect(values[0], values[1], values[2], values[3]); |
break; |
case Animation::SIZE: |
CHECK_EQ(animation.from.size(), 2u); |
- size.x = values[0]; |
- size.y = values[1]; |
+ size.set_x(values[0]); |
+ size.set_y(values[1]); |
break; |
case Animation::SCALE: |
CHECK_EQ(animation.from.size(), 3u); |
- scale.x = values[0]; |
- scale.y = values[1]; |
- scale.z = values[2]; |
+ scale = {values[0], values[1], values[2]}; |
break; |
case Animation::ROTATION: |
CHECK_EQ(animation.from.size(), 4u); |
@@ -182,9 +182,7 @@ void ContentRectangle::Animate(int64_t time) { |
break; |
case Animation::TRANSLATION: |
CHECK_EQ(animation.from.size(), 3u); |
- translation.x = values[0]; |
- translation.y = values[1]; |
- translation.z = values[2]; |
+ translation = {values[0], values[1], values[2]}; |
break; |
case Animation::OPACITY: |
CHECK_EQ(animation.from.size(), 1u); |