GteWindow3.cpp
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 #include <GTEnginePCH.h>
10 using namespace gte;
11 
13  :
14  Window(parameters),
15  mUpdater([this](std::shared_ptr<Buffer> const& buffer){ mEngine->Update(buffer); }),
16 #if defined(GTE_DEV_OPENGL)
17  mCamera(std::make_shared<Camera>(true, false)),
18 #else
19  mCamera(std::make_shared<Camera>(true, true)),
20 #endif
21  mCameraRig(mCamera, 0.0f, 0.0f),
24 {
35 }
36 
37 void Window3::InitializeCamera(float upFovDegrees, float aspectRatio, float dmin, float dmax,
38  float translationSpeed, float rotationSpeed, std::array<float, 3> const& pos,
39  std::array<float, 3> const& dir, std::array<float, 3> const& up)
40 {
41  mCamera->SetFrustum(upFovDegrees, aspectRatio, dmin, dmax);
42  Vector4<float> camPosition{ pos[0], pos[1], pos[2], 1.0f };
43  Vector4<float> camDVector{ dir[0], dir[1], dir[2], 0.0f };
44  Vector4<float> camUVector{ up[0], up[1], up[2], 0.0f };
45  Vector4<float> camRVector = Cross(camDVector, camUVector);
46  mCamera->SetFrame(camPosition, camDVector, camUVector, camRVector);
47 
49  mCameraRig.SetTranslationSpeed(translationSpeed);
50  mCameraRig.SetRotationSpeed(rotationSpeed);
51 }
52 
53 bool Window3::OnResize(int xSize, int ySize)
54 {
55  if (Window::OnResize(xSize, ySize))
56  {
57  float upFovDegrees, aspectRatio, dMin, dMax;
58  mCamera->GetFrustum(upFovDegrees, aspectRatio, dMin, dMax);
59  mCamera->SetFrustum(upFovDegrees, GetAspectRatio(), dMin, dMax);
61  return true;
62  }
63  return false;
64 }
65 
66 bool Window3::OnCharPress(unsigned char key, int x, int y)
67 {
68  switch (key)
69  {
70  case 't': // Slower camera translation.
72  return true;
73 
74  case 'T': // Faster camera translation.
76  return true;
77 
78  case 'r': // Slower camera rotation.
80  return true;
81 
82  case 'R': // Faster camera rotation.
84  return true;
85  }
86 
87  return Window::OnCharPress(key, x, y);
88 }
89 
90 bool Window3::OnKeyDown(int key, int, int)
91 {
92  return mCameraRig.PushMotion(key);
93 }
94 
95 bool Window3::OnKeyUp(int key, int, int)
96 {
97  return mCameraRig.PopMotion(key);
98 }
99 
100 bool Window3::OnMouseClick(MouseButton button, MouseState state, int x, int y,
101  unsigned int)
102 {
103  if (button == MOUSE_LEFT)
104  {
105  if (state == MOUSE_DOWN)
106  {
107  mTrackball.SetActive(true);
108  mTrackball.SetInitialPoint(x, mYSize - 1 - y);
109  }
110  else
111  {
112  mTrackball.SetActive(false);
113  }
114 
115  return true;
116  }
117 
118  return false;
119 }
120 
121 bool Window3::OnMouseMotion(MouseButton button, int x, int y, unsigned int)
122 {
123  if (button == MOUSE_LEFT && mTrackball.GetActive())
124  {
125  mTrackball.SetFinalPoint(x, mYSize - 1 - y);
127  return true;
128  }
129 
130  return false;
131 }
static int const KEY_LEFT
Definition: GteWindowBase.h:90
PVWUpdater mPVWMatrices
Definition: GteWindow3.h:64
void SetFinalPoint(int x, int y)
void RegisterMoveBackward(int trigger)
Definition: GteCameraRig.h:214
void RegisterMoveUp(int trigger)
Definition: GteCameraRig.h:219
Trackball mTrackball
Definition: GteWindow3.h:65
void RegisterTurnRight(int trigger)
Definition: GteCameraRig.h:239
void RegisterMoveLeft(int trigger)
Definition: GteCameraRig.h:234
bool PopMotion(int trigger)
virtual bool OnResize(int xSize, int ySize) override
Definition: GteWindow3.cpp:53
void ComputeWorldAxes()
static int const KEY_PAGE_UP
Definition: GteWindowBase.h:96
void RegisterLookDown(int trigger)
Definition: GteCameraRig.h:254
virtual bool OnKeyDown(int key, int x, int y) override
Definition: GteWindow3.cpp:90
static int const KEY_HOME
Definition: GteWindowBase.h:94
bool PushMotion(int trigger)
void RegisterLookUp(int trigger)
Definition: GteCameraRig.h:249
float GetTranslationSpeed() const
Definition: GteCameraRig.h:134
float GetAspectRatio() const
void RegisterTurnLeft(int trigger)
Definition: GteCameraRig.h:244
GLint GLenum GLint x
Definition: glcorearb.h:404
void SetActive(bool active)
Definition: GteTrackball.h:107
void InitializeCamera(float upFovDegrees, float aspectRatio, float dmin, float dmax, float translationSpeed, float rotationSpeed, std::array< float, 3 > const &pos, std::array< float, 3 > const &dir, std::array< float, 3 > const &up)
Definition: GteWindow3.cpp:37
bool GetActive() const
Definition: GteTrackball.h:112
static int const MOUSE_DOWN
static int const KEY_DELETE
Definition: GteWindowBase.h:99
void SetInitialPoint(int x, int y)
virtual bool OnCharPress(unsigned char key, int x, int y) override
Definition: GteWindow3.cpp:66
void RegisterMoveForward(int trigger)
Definition: GteCameraRig.h:209
static int const KEY_INSERT
Definition: GteWindowBase.h:98
static int const KEY_PAGE_DOWN
Definition: GteWindowBase.h:97
virtual bool OnMouseClick(MouseButton button, MouseState state, int x, int y, unsigned int modifiers) override
Definition: GteWindow3.cpp:100
DualQuaternion< Real > Cross(DualQuaternion< Real > const &d0, DualQuaternion< Real > const &d1)
static int const MOUSE_LEFT
static int const KEY_RIGHT
Definition: GteWindowBase.h:91
void RegisterMoveRight(int trigger)
Definition: GteCameraRig.h:229
std::shared_ptr< GraphicsEngine > mEngine
Definition: GLX/GteWindow.h:69
void RegisterMoveDown(int trigger)
Definition: GteCameraRig.h:224
virtual bool OnResize(int xSize, int ySize)
static int const KEY_END
Definition: GteWindowBase.h:95
void SetTranslationSpeed(float translationSpeed)
Definition: GteCameraRig.h:129
float GetRotationSpeed() const
Definition: GteCameraRig.h:144
std::shared_ptr< Camera > mCamera
Definition: GteWindow3.h:62
virtual bool OnMouseMotion(MouseButton button, int x, int y, unsigned int modifiers) override
Definition: GteWindow3.cpp:121
static int const KEY_UP
Definition: GteWindowBase.h:92
GLfloat f
Definition: glcorearb.h:1921
static int const KEY_DOWN
Definition: GteWindowBase.h:93
void SetRotationSpeed(float rotationSpeed)
Definition: GteCameraRig.h:139
GLuint buffer
Definition: glcorearb.h:655
GLint y
Definition: glcorearb.h:98
Window3(Parameters &parameters)
Definition: GteWindow3.cpp:12
virtual bool OnCharPress(unsigned char key, int x, int y)
BufferUpdater mUpdater
Definition: GteWindow3.h:61
virtual bool OnKeyUp(int key, int x, int y) override
Definition: GteWindow3.cpp:95
CameraRig mCameraRig
Definition: GteWindow3.h:63


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