OpenGLVisualizerControl.cpp
Go to the documentation of this file.
00001 // ****************************************************************************
00002 // This file is part of the Integrating Vision Toolkit (IVT).
00003 //
00004 // The IVT is maintained by the Karlsruhe Institute of Technology (KIT)
00005 // (www.kit.edu) in cooperation with the company Keyetech (www.keyetech.de).
00006 //
00007 // Copyright (C) 2014 Karlsruhe Institute of Technology (KIT).
00008 // All rights reserved.
00009 //
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are met:
00012 //
00013 // 1. Redistributions of source code must retain the above copyright
00014 //    notice, this list of conditions and the following disclaimer.
00015 //
00016 // 2. Redistributions in binary form must reproduce the above copyright
00017 //    notice, this list of conditions and the following disclaimer in the
00018 //    documentation and/or other materials provided with the distribution.
00019 //
00020 // 3. Neither the name of the KIT nor the names of its contributors may be
00021 //    used to endorse or promote products derived from this software
00022 //    without specific prior written permission.
00023 //
00024 // THIS SOFTWARE IS PROVIDED BY THE KIT AND CONTRIBUTORS “AS IS” AND ANY
00025 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00026 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00027 // DISCLAIMED. IN NO EVENT SHALL THE KIT OR CONTRIBUTORS BE LIABLE FOR ANY
00028 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00029 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00030 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00031 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00032 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00033 // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00034 // ****************************************************************************
00035 // ****************************************************************************
00036 // Filename:  OpenGLVisualizerControl.cpp
00037 // Author:    Florian Hecht
00038 // Date:      2009
00039 // ****************************************************************************
00040 
00041 
00042 // ****************************************************************************
00043 // Includes
00044 // ****************************************************************************
00045 
00046 #include "OpenGLVisualizerControl.h"
00047 
00048 #include "Interfaces/MainWindowInterface.h"
00049 #include "OpenGLVisualizer.h"
00050 
00051 
00052 
00053 // ****************************************************************************
00054 // Constructor
00055 // ****************************************************************************
00056 
00057 COpenGLVisualizerControl::COpenGLVisualizerControl(WIDGET_HANDLE widget, int width, int height, COpenGLVisualizer *visualizer, CMainWindowInterface *main_window, CMainWindowEventInterface *event_callback)
00058 : 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)
00059 {
00060         ResetViewMatrix();
00061 }
00062 
00063 
00064 // ****************************************************************************
00065 // Methods
00066 // ****************************************************************************
00067 
00068 void COpenGLVisualizerControl::SetViewMatrix(const Transformation3d &transformation)
00069 {
00070         m_ViewMatrix = transformation;
00071         
00072         if (m_visualizer)
00073                 m_visualizer->SetViewMatrix(m_ViewMatrix);
00074 }
00075 
00076 const Transformation3d &COpenGLVisualizerControl::GetViewMatrix()
00077 {
00078         return m_ViewMatrix;
00079 }
00080 
00081 void COpenGLVisualizerControl::ResetViewMatrix()
00082 {
00083         m_ViewMatrix.rotation = Math3d::unit_mat;
00084         m_ViewMatrix.translation = Math3d::zero_vec;
00085         
00086         if (m_visualizer)
00087                 m_visualizer->SetViewMatrix(m_ViewMatrix);
00088 }
00089         
00090 // this two events are specific for the image widget
00091 void COpenGLVisualizerControl::RectSelected(WIDGET_HANDLE widget, int x0, int y0, int x1, int y1)
00092 {
00093         if (m_event_callback)
00094                 m_event_callback->RectSelected(widget, x0, y0, x1, y1);
00095 }
00096 
00097 void COpenGLVisualizerControl::PointClicked(WIDGET_HANDLE widget, int x, int y)
00098 {
00099         if (m_event_callback)
00100                 m_event_callback->PointClicked(widget, x, y);
00101 }
00102 
00103 // the following events are only generated for image and GL widgets
00104 void COpenGLVisualizerControl::MouseDown(WIDGET_HANDLE widget, int button, int x, int y)
00105 {
00106         if (widget == m_widget)
00107         {
00108                 int mod = 0;
00109                 if (m_main_window)
00110                         mod = m_main_window->GetModifierKeyState();
00111                 
00112                 if (button == IVT_LEFT_BUTTON)
00113                 {
00114                         if (mod == 0)
00115                                 m_mouse_mode = 1;
00116                         else if (mod & IVT_SHIFT_KEY)
00117                                 m_mouse_mode = 3;
00118                         else if (mod & IVT_CONTROL_KEY || mod & IVT_ALT_KEY)
00119                                 m_mouse_mode = 4;
00120                 }
00121                 else if (button == IVT_RIGHT_BUTTON)
00122                 {
00123                         m_mouse_mode = 2;
00124                 }
00125                 else if (button == IVT_MIDDLE_BUTTON)
00126                 {
00127                         m_mouse_mode = 3;
00128                 }
00129                 
00130                 m_mouse_old_x = x;
00131                 m_mouse_old_y = y;
00132                 
00133                 return;
00134         }
00135         
00136         if (m_event_callback)
00137                 m_event_callback->MouseDown(widget, button, x, y);
00138 }
00139 
00140 void COpenGLVisualizerControl::MouseUp(WIDGET_HANDLE widget, int button, int x, int y)
00141 {
00142         if (widget == m_widget)
00143         {
00144                 m_mouse_mode = 0;
00145                 
00146                 m_mouse_old_x = x;
00147                 m_mouse_old_y = y;
00148                 
00149                 return;
00150         }
00151         
00152         if (m_event_callback)
00153                 m_event_callback->MouseUp(widget, button, x, y);
00154 }
00155 
00156 void COpenGLVisualizerControl::MouseMove(WIDGET_HANDLE widget, int x, int y)
00157 {
00158         if (widget == m_widget && m_mouse_mode != 0)
00159         {
00160                 m_mouse_old_x = x;
00161                 m_mouse_old_y = y;
00162                 
00163                 return;
00164         }
00165         
00166         if (m_event_callback)
00167                 m_event_callback->MouseMove(widget, x, y);
00168 }
00169 
00170 void COpenGLVisualizerControl::KeyDown(WIDGET_HANDLE widget, int key)
00171 {
00172         if (m_event_callback)
00173                 m_event_callback->KeyDown(widget, key);
00174 }
00175 
00176 void COpenGLVisualizerControl::KeyUp(WIDGET_HANDLE widget, int key)
00177 {
00178         if (m_event_callback)
00179                 m_event_callback->KeyUp(widget, key);
00180 }
00181 
00182 // this event is only emitted for buttons
00183 void COpenGLVisualizerControl::ButtonPushed(WIDGET_HANDLE widget)
00184 {
00185         if (m_event_callback)
00186                 m_event_callback->ButtonPushed(widget);
00187 }
00188 
00189 // this event is generated by check boxes, sliders, text edits (value = -1)
00190 // and combo boxes
00191 void COpenGLVisualizerControl::ValueChanged(WIDGET_HANDLE widget, int value)
00192 {
00193         if (m_event_callback)
00194                 m_event_callback->ValueChanged(widget, value);
00195 }
00196 
00197 #define ROT_SPEED 0.1f
00198 #define TRANS_SPEED 100.0f
00199 
00200 void COpenGLVisualizerControl::Update()
00201 {
00202         float fx = (float)(m_mouse_old_x - (m_width / 2)) / (float)(m_width / 2);
00203         float fy = (float)(m_mouse_old_y - (m_height / 2)) / (float)(m_height / 2);
00204         
00205         if (m_mouse_mode == 1)
00206         {
00207                 Mat3d m1, m2;
00208                 
00209                 Math3d::SetRotationMatX(m1, ROT_SPEED * fy);
00210                 Math3d::SetRotationMatY(m2, ROT_SPEED * -fx);
00211                 
00212                 Math3d::MulMatMat(m1, m2, m1);
00213                 Math3d::MulMatMat(m1, m_ViewMatrix.rotation, m_ViewMatrix.rotation);
00214                 
00215                 if (m_visualizer)
00216                         m_visualizer->SetViewMatrix(m_ViewMatrix);
00217         }
00218         else if (m_mouse_mode == 2)
00219         {
00220                 m_ViewMatrix.translation.z += TRANS_SPEED * fy;
00221                 
00222                 if (m_visualizer)
00223                         m_visualizer->SetViewMatrix(m_ViewMatrix);
00224         }
00225         else if (m_mouse_mode == 3)
00226         {
00227                 m_ViewMatrix.translation.x += TRANS_SPEED * fx;
00228                 m_ViewMatrix.translation.y += TRANS_SPEED * fy;
00229                 
00230                 if (m_visualizer)
00231                         m_visualizer->SetViewMatrix(m_ViewMatrix);
00232         }
00233         else if (m_mouse_mode == 4)
00234         {
00235                 Mat3d m1;
00236                 
00237                 Math3d::SetRotationMatZ(m1, ROT_SPEED * fy);
00238                 
00239                 Math3d::MulMatMat(m1, m_ViewMatrix.rotation, m_ViewMatrix.rotation);
00240                 
00241                 if (m_visualizer)
00242                         m_visualizer->SetViewMatrix(m_ViewMatrix);
00243         }
00244 }
00245 
00246 #undef ROT_SPEED
00247 #undef TRANS_SPEED


asr_ivt
Author(s): Allgeyer Tobias, Hutmacher Robin, Kleinert Daniel, Meißner Pascal, Scholz Jonas, Stöckle Patrick
autogenerated on Thu Jun 6 2019 21:46:57