diff options
author | Narayan Kamath <narayan@google.com> | 2012-11-02 10:59:05 +0000 |
---|---|---|
committer | Xiaotao Duan <xiaotao@google.com> | 2012-11-07 14:17:48 -0800 |
commit | c981c48f5bc9aefeffc0bcb0cc3934c2fae179dd (patch) | |
tree | 54d1c7d66098154c1d7c5bd414394ef4cf255810 /demos/opengl/trackball.cpp | |
parent | 63f67d748682b46d58be31235a0a2d64d81b998c (diff) | |
download | eigen-c981c48f5bc9aefeffc0bcb0cc3934c2fae179dd.tar.gz |
Initial import of eigen 3.1.1android-cts-4.4_r4android-cts-4.2_r2android-4.4_r1.2.0.1android-4.4_r1.2android-4.4_r1.1.0.1android-4.4_r1.1android-4.4_r1.0.1android-4.4_r1android-4.4_r0.9android-4.4_r0.8android-4.3_r2.3android-4.3_r2.2android-4.3_r2.1android-4.3_r2android-4.3_r1.1android-4.3_r1android-4.3_r0.9.1android-4.3_r0.9android-4.2.2_r1.2android-4.2.2_r1.1android-4.2.2_r1kitkat-releasekitkat-cts-releasejb-mr2.0-releasejb-mr2-releasejb-mr1.1-releasejb-mr1.1-dev
Added a README.android and a MODULE_LICENSE_MPL2 file.
Added empty Android.mk and CleanSpec.mk to optimize Android build.
Non MPL2 license code is disabled in ./Eigen/src/Core/util/NonMPL2.h.
Trying to include such files will lead to an error.
Change-Id: I0e148b7c3e83999bcc4dfaa5809d33bfac2aac32
Diffstat (limited to 'demos/opengl/trackball.cpp')
-rw-r--r-- | demos/opengl/trackball.cpp | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/demos/opengl/trackball.cpp b/demos/opengl/trackball.cpp new file mode 100644 index 000000000..77ac790c8 --- /dev/null +++ b/demos/opengl/trackball.cpp @@ -0,0 +1,59 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr> +// +// This Source Code Form is subject to the terms of the Mozilla +// Public License v. 2.0. If a copy of the MPL was not distributed +// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#include "trackball.h" +#include "camera.h" + +using namespace Eigen; + +void Trackball::track(const Vector2i& point2D) +{ + if (mpCamera==0) + return; + Vector3f newPoint3D; + bool newPointOk = mapToSphere(point2D, newPoint3D); + + if (mLastPointOk && newPointOk) + { + Vector3f axis = mLastPoint3D.cross(newPoint3D).normalized(); + float cos_angle = mLastPoint3D.dot(newPoint3D); + if ( internal::abs(cos_angle) < 1.0 ) + { + float angle = 2. * acos(cos_angle); + if (mMode==Around) + mpCamera->rotateAroundTarget(Quaternionf(AngleAxisf(angle, axis))); + else + mpCamera->localRotate(Quaternionf(AngleAxisf(-angle, axis))); + } + } + + mLastPoint3D = newPoint3D; + mLastPointOk = newPointOk; +} + +bool Trackball::mapToSphere(const Vector2i& p2, Vector3f& v3) +{ + if ((p2.x() >= 0) && (p2.x() <= int(mpCamera->vpWidth())) && + (p2.y() >= 0) && (p2.y() <= int(mpCamera->vpHeight())) ) + { + double x = (double)(p2.x() - 0.5*mpCamera->vpWidth()) / (double)mpCamera->vpWidth(); + double y = (double)(0.5*mpCamera->vpHeight() - p2.y()) / (double)mpCamera->vpHeight(); + double sinx = sin(M_PI * x * 0.5); + double siny = sin(M_PI * y * 0.5); + double sinx2siny2 = sinx * sinx + siny * siny; + + v3.x() = sinx; + v3.y() = siny; + v3.z() = sinx2siny2 < 1.0 ? sqrt(1.0 - sinx2siny2) : 0.0; + + return true; + } + else + return false; +} |