Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

sceneorbiter.h

Go to the documentation of this file.
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 #ifndef SHEEP_FRAMEWORK_SCENEORBITER_H
00024 #define SHEEP_FRAMEWORK_SCENEORBITER_H
00025 
00026 #include "common/math/point3.h"
00027 #include "common/math/real.h"
00028 #include "common/math/vector2.h"
00029 
00030 #include <cassert>
00031 #include <cmath>
00032 
00033 //#define REVERSE_AZIMUTH
00034 
00035 namespace sheep {
00036 
00037     class SceneOrbiter {
00038     public:
00039         enum Movement {
00040             TUMBLE, TRACK, DOLLY
00041         };
00042 
00043         // Assuming we have a right-hand coordinate system,
00044         // azimuth zero is on positive part of the x axis
00045         // and is increasing in the direction of the positive
00046         // part of the z axis.
00047 
00048         // Elevation is measured from the x-z plan and is
00049         // increasing in the direction of the positive part
00050         // of the y axis.
00051 
00052         SceneOrbiter(
00053             const Point3 &center = 0,
00054             Real azimuth = PI / 4.0,
00055             Real elevation = PI / 4.0,
00056             Real distance = 1.0
00057         );
00058 
00059         void Configure(
00060             const Point3 &center,
00061             Real azimuth,
00062             Real elevation,
00063             Real distance
00064         );
00065 
00066         // (x, y) is a point on the screen. By convention, it is
00067         // assumed that the point (-1, -1) is at the lower left
00068         // corner of the screen whereas the point (1, 1) is at the
00069         // upper right corner.
00070 
00071         // By convention, azimuth and elevation increase or decrease
00072         // by PI / 2 for a one unit (mouse) drag, that is, we have:
00073         // d(azimuth) = PI / 2 * d(x) and d(elevation) = PI / 2 * d(y).
00074 
00075         void BeginDrag(Movement m, const Vector2 &p);
00076         void UpdateDrag(const Vector2 &p);
00077         void EndDrag();
00078         void CancelDrag();
00079 
00080         bool IsTumbling() const;
00081         bool IsTracking() const;
00082         bool IsDollying() const;
00083         bool IsDragging() const;
00084 
00085         void SetCenter(const Point3 &center);
00086         const Point3 &GetCenter() const;
00087 
00088         Point3 GetEyePosition() const;
00089 
00090         Real GetAzimuth() const;
00091         Real GetElevation() const;
00092         Real GetDistance() const;
00093 
00094     private:
00095         Point3 m_center, m_old_center;
00096         Real m_azimuth, m_old_azimuth;
00097         Real m_elevation, m_old_elevation;
00098         Real m_distance, m_old_distance;
00099 
00100         Movement m_movement;
00101         Vector2 m_old_point;
00102 
00103         bool m_is_dragging;
00104 
00105 #ifdef REVERSE_AZIMUTH
00106         bool m_reverse_azimuth;
00107 #endif  // REVERSE_AZIMUTH
00108 
00109         void tumble(const Vector2 &delta);
00110         void track(const Vector2 &delta);
00111         void dolly(const Vector2 &delta);
00112     };
00113 
00114 #include "sceneorbiter.inl"
00115 
00116 }
00117 
00118 #endif  // !SHEEP_FRAMEWORK_SCENEORBITER_H

Generated on Tue May 11 01:31:52 2004 for toxic by doxygen 1.3.6