00001 /* 00002 Sheep - A Rigid Body Dynamics Engine 00003 Copyright (C) 2001-2004 Francois Beaune 00004 Contact: http://toxicengine.sourceforge.net/ 00005 00006 This file is part of Sheep. 00007 00008 Sheep is free software; you can redistribute it and/or modify 00009 it under the terms of the GNU General Public License as published by 00010 the Free Software Foundation; either version 2 of the License, or 00011 (at your option) any later version. 00012 00013 Sheep is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 GNU General Public License for more details. 00017 00018 You should have received a copy of the GNU General Public License 00019 along with Sheep; if not, write to the Free Software 00020 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00021 */ 00022 00023 inline 00024 Arcball::Arcball() { 00025 m_q = Quaternion::Identity(); 00026 m_is_dragging = false; 00027 } 00028 00029 inline 00030 void Arcball::BeginDrag(const Vector2 &p) { 00031 assert(!m_is_dragging); 00032 00033 m_start_q = m_q; 00034 m_from = point_on_sphere(p); 00035 00036 m_is_dragging = true; 00037 } 00038 00039 inline 00040 void Arcball::UpdateDrag(const Vector2 &p) { 00041 assert(m_is_dragging); 00042 00043 const Vector3 to = point_on_sphere(p); 00044 00045 m_q = Quaternion::Rotation(m_from, to) * m_start_q; 00046 m_q = m_q.Normalized(); 00047 } 00048 00049 inline 00050 void Arcball::EndDrag() { 00051 assert(m_is_dragging); 00052 m_is_dragging = false; 00053 } 00054 00055 inline 00056 void Arcball::CancelDrag() { 00057 assert(m_is_dragging); 00058 m_q = m_start_q; 00059 m_is_dragging = false; 00060 } 00061 00062 inline 00063 bool Arcball::IsDragging() const { 00064 return m_is_dragging; 00065 } 00066 00067 inline 00068 void Arcball::SetOrientation(const Quaternion &q) { 00069 assert(!m_is_dragging); 00070 m_q = q; 00071 } 00072 00073 inline 00074 const Quaternion &Arcball::GetOrientation() const { 00075 return m_q; 00076 }
1.3.6