GteTrackball.h
Go to the documentation of this file.
1 // David Eberly, Geometric Tools, Redmond WA 98052
2 // Copyright (c) 1998-2017
3 // Distributed under the Boost Software License, Version 1.0.
4 // http://www.boost.org/LICENSE_1_0.txt
5 // http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
6 // File Version: 3.0.0 (2016/06/19)
7 
8 #pragma once
9 
10 #include <Graphics/GteCamera.h>
11 #include <Graphics/GteNode.h>
12 
13 namespace gte
14 {
15 
17 {
18 public:
19  // Construction. The trackball is the largest circle centered in the
20  // rectangle of dimensions xSize-by-ySize. The rectangle is assumed to
21  // be defined in right-handed coordinates, so if you use a window client
22  // rectangle for the trackball and this rectangle is in left-handed
23  // coordinates, you must reflect the y-values in SetInitialPoint and
24  // SetFinalPoint by (ySize - 1 - y). A root node is used to represent
25  // the trackball orientation. Objects may be attached and detached as
26  // desired.
27  Trackball();
28  Trackball(int xSize, int ySize, std::shared_ptr<Camera> const& camera);
29 
30  // Member access. The Set function is for deferred construction after
31  // a default construction of a trackball.
32  void Set(int xSize, int ySize, std::shared_ptr<Camera> const& camera);
33  inline int GetXSize() const;
34  inline int GetYSize() const;
35  inline std::shared_ptr<Camera> const& GetCamera() const;
36  inline std::shared_ptr<Node> const& GetRoot() const;
37  inline Matrix4x4<float> const& GetOrientation() const;
38 
39  // The root node is the top-level node of a hierarchy whose local
40  // transformation is the trackball orientation relative to the specified
41  // camera. The camera directions {D,U,R} act as the world coordinate
42  // system.
43  void Attach(std::shared_ptr<Spatial> const& object);
44  void Detach(std::shared_ptr<Spatial> const& object);
45  void DetachAll();
46  inline void Update(double applicationTime = 0.0);
47 
48  // Set the arc on the sphere along which the trackball rotates. The
49  // standard use is to set the initial point via a mouse button click on a
50  // window rectangle. Mark the trackball as active and set final points
51  // based on the locations of the dragged mouse. Once the mouse button is
52  // released, mark the trackball as inactive.
53  inline void SetActive(bool active);
54  inline bool GetActive() const;
55 
56  // Set the initial point of the arc. The current trackball orientation is
57  // recorded. On construction, the initial point is set to the rectangle
58  // center.
59  void SetInitialPoint(int x, int y);
60 
61  // Set the final point of the arc. The trackball orientation is updated
62  // by the incremental rotation implied by the arc endpoints.
63  void SetFinalPoint(int x, int y);
64 
65 protected:
66  void UpdateOrientation();
67 
68  int mXSize, mYSize;
69  std::shared_ptr<Camera> mCamera;
70  std::shared_ptr<Node> mRoot;
72  float mMultiplier, mX0, mY0, mX1, mY1;
73  bool mActive, mValidTrackball;
74 };
75 
76 
77 inline int Trackball::GetXSize() const
78 {
79  return mXSize;
80 }
81 
82 inline int Trackball::GetYSize() const
83 {
84  return mYSize;
85 }
86 
87 inline std::shared_ptr<Camera> const& Trackball::GetCamera() const
88 {
89  return mCamera;
90 }
91 
92 inline std::shared_ptr<Node> const& Trackball::GetRoot() const
93 {
94  return mRoot;
95 }
96 
98 {
99  return mRoot->worldTransform.GetRotation();
100 }
101 
102 inline void Trackball::Update(double applicationTime)
103 {
104  mRoot->Update(applicationTime);
105 }
106 
107 inline void Trackball::SetActive(bool active)
108 {
109  mActive = active;
110 }
111 
112 inline bool Trackball::GetActive() const
113 {
114  return mActive;
115 }
116 
117 
118 }
Matrix4x4< float > const & GetOrientation() const
Definition: GteTrackball.h:97
std::shared_ptr< Camera > const & GetCamera() const
Definition: GteTrackball.h:87
Matrix4x4< float > mInitialOrientation
Definition: GteTrackball.h:71
GLint GLenum GLint x
Definition: glcorearb.h:404
void SetActive(bool active)
Definition: GteTrackball.h:107
std::shared_ptr< Node > mRoot
Definition: GteTrackball.h:70
bool GetActive() const
Definition: GteTrackball.h:112
std::shared_ptr< Node > const & GetRoot() const
Definition: GteTrackball.h:92
void Update(double applicationTime=0.0)
Definition: GteTrackball.h:102
int GetYSize() const
Definition: GteTrackball.h:82
bool mValidTrackball
Definition: GteTrackball.h:73
std::shared_ptr< Camera > mCamera
Definition: GteTrackball.h:69
int GetXSize() const
Definition: GteTrackball.h:77
GLint y
Definition: glcorearb.h:98
#define GTE_IMPEXP
Definition: GTEngineDEF.h:63


geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 04:00:01