OpenGLVisualizerControl.cpp
Go to the documentation of this file.
1 // ****************************************************************************
2 // This file is part of the Integrating Vision Toolkit (IVT).
3 //
4 // The IVT is maintained by the Karlsruhe Institute of Technology (KIT)
5 // (www.kit.edu) in cooperation with the company Keyetech (www.keyetech.de).
6 //
7 // Copyright (C) 2014 Karlsruhe Institute of Technology (KIT).
8 // All rights reserved.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are met:
12 //
13 // 1. Redistributions of source code must retain the above copyright
14 // notice, this list of conditions and the following disclaimer.
15 //
16 // 2. Redistributions in binary form must reproduce the above copyright
17 // notice, this list of conditions and the following disclaimer in the
18 // documentation and/or other materials provided with the distribution.
19 //
20 // 3. Neither the name of the KIT nor the names of its contributors may be
21 // used to endorse or promote products derived from this software
22 // without specific prior written permission.
23 //
24 // THIS SOFTWARE IS PROVIDED BY THE KIT AND CONTRIBUTORS “AS IS” AND ANY
25 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 // DISCLAIMED. IN NO EVENT SHALL THE KIT OR CONTRIBUTORS BE LIABLE FOR ANY
28 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33 // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 // ****************************************************************************
35 // ****************************************************************************
36 // Filename: OpenGLVisualizerControl.cpp
37 // Author: Florian Hecht
38 // Date: 2009
39 // ****************************************************************************
40 
41 
42 // ****************************************************************************
43 // Includes
44 // ****************************************************************************
45 
47 
49 #include "OpenGLVisualizer.h"
50 
51 
52 
53 // ****************************************************************************
54 // Constructor
55 // ****************************************************************************
56 
58 : m_widget(widget), m_visualizer(visualizer), m_main_window(main_window), m_event_callback(event_callback), m_width(width), m_height(height), m_mouse_mode(0)
59 {
61 }
62 
63 
64 // ****************************************************************************
65 // Methods
66 // ****************************************************************************
67 
69 {
70  m_ViewMatrix = transformation;
71 
72  if (m_visualizer)
74 }
75 
77 {
78  return m_ViewMatrix;
79 }
80 
82 {
85 
86  if (m_visualizer)
88 }
89 
90 // this two events are specific for the image widget
91 void COpenGLVisualizerControl::RectSelected(WIDGET_HANDLE widget, int x0, int y0, int x1, int y1)
92 {
93  if (m_event_callback)
94  m_event_callback->RectSelected(widget, x0, y0, x1, y1);
95 }
96 
98 {
99  if (m_event_callback)
100  m_event_callback->PointClicked(widget, x, y);
101 }
102 
103 // the following events are only generated for image and GL widgets
104 void COpenGLVisualizerControl::MouseDown(WIDGET_HANDLE widget, int button, int x, int y)
105 {
106  if (widget == m_widget)
107  {
108  int mod = 0;
109  if (m_main_window)
111 
112  if (button == IVT_LEFT_BUTTON)
113  {
114  if (mod == 0)
115  m_mouse_mode = 1;
116  else if (mod & IVT_SHIFT_KEY)
117  m_mouse_mode = 3;
118  else if (mod & IVT_CONTROL_KEY || mod & IVT_ALT_KEY)
119  m_mouse_mode = 4;
120  }
121  else if (button == IVT_RIGHT_BUTTON)
122  {
123  m_mouse_mode = 2;
124  }
125  else if (button == IVT_MIDDLE_BUTTON)
126  {
127  m_mouse_mode = 3;
128  }
129 
130  m_mouse_old_x = x;
131  m_mouse_old_y = y;
132 
133  return;
134  }
135 
136  if (m_event_callback)
137  m_event_callback->MouseDown(widget, button, x, y);
138 }
139 
140 void COpenGLVisualizerControl::MouseUp(WIDGET_HANDLE widget, int button, int x, int y)
141 {
142  if (widget == m_widget)
143  {
144  m_mouse_mode = 0;
145 
146  m_mouse_old_x = x;
147  m_mouse_old_y = y;
148 
149  return;
150  }
151 
152  if (m_event_callback)
153  m_event_callback->MouseUp(widget, button, x, y);
154 }
155 
157 {
158  if (widget == m_widget && m_mouse_mode != 0)
159  {
160  m_mouse_old_x = x;
161  m_mouse_old_y = y;
162 
163  return;
164  }
165 
166  if (m_event_callback)
167  m_event_callback->MouseMove(widget, x, y);
168 }
169 
171 {
172  if (m_event_callback)
173  m_event_callback->KeyDown(widget, key);
174 }
175 
177 {
178  if (m_event_callback)
179  m_event_callback->KeyUp(widget, key);
180 }
181 
182 // this event is only emitted for buttons
184 {
185  if (m_event_callback)
187 }
188 
189 // this event is generated by check boxes, sliders, text edits (value = -1)
190 // and combo boxes
192 {
193  if (m_event_callback)
194  m_event_callback->ValueChanged(widget, value);
195 }
196 
197 #define ROT_SPEED 0.1f
198 #define TRANS_SPEED 100.0f
199 
201 {
202  float fx = (float)(m_mouse_old_x - (m_width / 2)) / (float)(m_width / 2);
203  float fy = (float)(m_mouse_old_y - (m_height / 2)) / (float)(m_height / 2);
204 
205  if (m_mouse_mode == 1)
206  {
207  Mat3d m1, m2;
208 
211 
212  Math3d::MulMatMat(m1, m2, m1);
214 
215  if (m_visualizer)
217  }
218  else if (m_mouse_mode == 2)
219  {
221 
222  if (m_visualizer)
224  }
225  else if (m_mouse_mode == 3)
226  {
229 
230  if (m_visualizer)
232  }
233  else if (m_mouse_mode == 4)
234  {
235  Mat3d m1;
236 
238 
240 
241  if (m_visualizer)
243  }
244 }
245 
246 #undef ROT_SPEED
247 #undef TRANS_SPEED
void MouseMove(WIDGET_HANDLE widget, int x, int y)
virtual void KeyUp(WIDGET_HANDLE widget, int key)
virtual void ButtonPushed(WIDGET_HANDLE widget)
virtual void ValueChanged(WIDGET_HANDLE widget, int value)
virtual void KeyDown(WIDGET_HANDLE widget, int key)
#define IVT_SHIFT_KEY
CMainWindowInterface * m_main_window
void ButtonPushed(WIDGET_HANDLE widget)
const Transformation3d & GetViewMatrix()
void PointClicked(WIDGET_HANDLE widget, int x, int y)
Vec3d translation
Definition: Math3d.h:108
COpenGLVisualizerControl(WIDGET_HANDLE widget, int width, int height, COpenGLVisualizer *visualizer, CMainWindowInterface *main_window, CMainWindowEventInterface *event_callback)
virtual int GetModifierKeyState()=0
float x
Definition: Math3d.h:75
#define IVT_LEFT_BUTTON
virtual void MouseDown(WIDGET_HANDLE widget, int button, int x, int y)
float z
Definition: Math3d.h:75
Mat3d rotation
Definition: Math3d.h:107
#define IVT_CONTROL_KEY
CMainWindowEventInterface * m_event_callback
GLenum GLint x
Definition: glext.h:3125
void * WIDGET_HANDLE
const Vec3d zero_vec
Definition: Math3d.cpp:59
void KeyDown(WIDGET_HANDLE widget, int key)
void SetRotationMatZ(Mat3d &matrix, float theta)
Definition: Math3d.cpp:358
void RectSelected(WIDGET_HANDLE widget, int x0, int y0, int x1, int y1)
float y
Definition: Math3d.h:75
GLsizei const GLfloat * value
Definition: glext.h:3538
virtual void MouseMove(WIDGET_HANDLE widget, int x, int y)
void MulMatMat(const Mat3d &matrix1, const Mat3d &matrix2, Mat3d &result)
Definition: Math3d.cpp:444
void KeyUp(WIDGET_HANDLE widget, int key)
virtual void PointClicked(WIDGET_HANDLE widget, int x, int y)
void SetViewMatrix(const Transformation3d &transformation)
#define IVT_RIGHT_BUTTON
Interface for the creation of GUIs with the GUI toolkit of the IVT.
void MouseUp(WIDGET_HANDLE widget, int button, int x, int y)
GLenum GLsizei width
Definition: glext.h:3122
GLenum GLsizei GLsizei height
Definition: glext.h:3132
#define IVT_MIDDLE_BUTTON
void SetRotationMatY(Mat3d &matrix, float theta)
Definition: Math3d.cpp:349
const Mat3d unit_mat
Definition: Math3d.cpp:60
GLenum GLint GLint y
Definition: glext.h:3125
void SetViewMatrix(const Transformation3d &transformation)
#define ROT_SPEED
void MouseDown(WIDGET_HANDLE widget, int button, int x, int y)
void ValueChanged(WIDGET_HANDLE widget, int value)
void SetRotationMatX(Mat3d &matrix, float theta)
Definition: Math3d.cpp:340
Data structure for the representation of a 3x3 matrix.
Definition: Math3d.h:93
Interface for the event mechanism of GUIs using the GUI toolkit of the IVT.
virtual void RectSelected(WIDGET_HANDLE widget, int x0, int y0, int x1, int y1)
#define IVT_ALT_KEY
Data structure for the representation of a 3D rigid body transformation.
Definition: Math3d.h:105
virtual void MouseUp(WIDGET_HANDLE widget, int button, int x, int y)
#define TRANS_SPEED


asr_ivt
Author(s): Allgeyer Tobias, Hutmacher Robin, Kleinert Daniel, Meißner Pascal, Scholz Jonas, Stöckle Patrick
autogenerated on Mon Dec 2 2019 03:47:28