00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include <srs_ui_but/but_display/camera_control_pane.h>
00029 #include <rviz/window_manager_interface.h>
00030 #include <rviz/visualization_manager.h>
00031
00032 #include <OgreCamera.h>
00033
00034 #define MAX_RANGE 500
00035
00036
00037 const int ID_NEAR_PLANE_SPIN(201);
00038 const int ID_FAR_PLANE_SPIN(202);
00039 const int ID_NEAR_PLANE_TEXT(203);
00040 const int ID_FAR_PLANE_TEXT(204);
00041 const int ID_UPDATE_CLIPPING_LIMITS(205);
00042 const int ID_FAR_MAX_SPIN(206);
00043
00047 srs_ui_but::CCameraControlPane::CCameraControlPane(wxWindow *parent, const wxString& title, rviz::WindowManagerInterface * wmi )
00048 : wxPanel( parent, wxID_ANY, wxDefaultPosition, wxSize(280, 180), wxCLOSE_BOX|wxTAB_TRAVERSAL | wxVSCROLL, title)
00049 , m_wmi( wmi )
00050 , m_camera( 0 )
00051 {
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063 wxStaticText * stNearPlane = new wxStaticText(this, ID_NEAR_PLANE_TEXT, _T("Near plane"));
00064 m_sliderNearClipPlane = new wxSlider(this, ID_NEAR_PLANE_SPIN, 50, 0, 100, wxDefaultPosition, wxSize(150, 0), wxBU_EXACTFIT);
00065 wxStaticText * stFarPlane = new wxStaticText(this, ID_FAR_PLANE_TEXT, _T("Far plane"));
00066 m_sliderFarClipPlane = new wxSlider(this, ID_FAR_PLANE_SPIN, 50, 0, 100, wxDefaultPosition, wxSize(150, 0), wxBU_EXACTFIT);
00067 m_spinFarPlane = new wxSpinCtrl(this, ID_FAR_MAX_SPIN, _T("100"), wxDefaultPosition, wxSize(150, 0), wxBU_EXACTFIT);
00068
00069
00070 m_sliderNearClipPlane->SetRange( 0, MAX_RANGE );
00071 m_sliderNearClipPlane->SetValue( 0 );
00072
00073 m_sliderFarClipPlane->SetRange(0, MAX_RANGE);
00074 m_sliderFarClipPlane->SetValue( 100 );
00075
00076 m_spinFarPlane->SetRange(1, 10000);
00077 m_spinFarPlane->SetValue(100);
00078
00079
00080 wxSizer *vsizer = new wxBoxSizer(wxVERTICAL);
00081 this->SetSizer(vsizer);
00082
00083
00084 wxStaticBoxSizer *hsizerPlanesControls = new wxStaticBoxSizer(wxVERTICAL, this, wxT("Clipping planes"));
00085 hsizerPlanesControls->Add( stNearPlane, ID_NEAR_PLANE_TEXT, wxALIGN_LEFT );
00086 hsizerPlanesControls->Add( m_sliderNearClipPlane, ID_NEAR_PLANE_SPIN, wxALIGN_LEFT );
00087 hsizerPlanesControls->Add( stFarPlane, ID_FAR_PLANE_TEXT, wxALIGN_LEFT );
00088 hsizerPlanesControls->Add( m_sliderFarClipPlane, ID_FAR_PLANE_SPIN, wxALIGN_LEFT );
00089 hsizerPlanesControls->Add( m_spinFarPlane, ID_FAR_MAX_SPIN, wxALIGN_LEFT);
00090
00091
00092 vsizer->Add(hsizerPlanesControls, 0, wxALIGN_LEFT);
00093 vsizer->SetSizeHints(this);
00094 }
00095
00099 void srs_ui_but::CCameraControlPane::setCamera( Ogre::Camera * camera )
00100 {
00101 m_camera = camera;
00102
00103 if( camera == 0 )
00104 {
00105 return;
00106 }
00107 m_nearDistanceMin = m_farDistanceMin = camera->getNearClipDistance();
00108
00109 m_near = m_nearDistanceMin;
00110 m_far = camera->getFarClipDistance();
00111
00112 updateClippingDistancesInfo();
00113 }
00114
00118 void srs_ui_but::CCameraControlPane::OnNearPlane(wxScrollEvent& event)
00119 {
00120 if( m_camera != 0 && m_nearDistanceMax > 0.0 )
00121 {
00122 m_near = m_nearDistanceMin + Ogre::Real( m_sliderNearClipPlane->GetValue()) / Ogre::Real(MAX_RANGE) * m_nearDistanceMax;
00123
00124 m_camera->setNearClipDistance(m_near);
00125 }
00126 }
00127
00131 void srs_ui_but::CCameraControlPane::OnFarPlane(wxScrollEvent& event)
00132 {
00133 if( m_camera != 0 && m_farDistanceMax > 0.0 )
00134 {
00135 m_far = m_farDistanceMin + Ogre::Real( m_sliderFarClipPlane->GetValue()) / Ogre::Real(MAX_RANGE) * m_farDistanceMax;
00136
00137 m_camera->setFarClipDistance(m_far);
00138 }
00139 }
00140
00144 void srs_ui_but::CCameraControlPane::updateClippingDistancesInfo()
00145 {
00146 if( m_camera == 0 )
00147 return;
00148
00149 m_nearDistanceMax = m_farDistanceMax = m_spinFarPlane->GetValue();
00150 m_nearDistanceMin = m_farDistanceMin = 0.03;
00151
00152
00153
00154
00155
00156
00157
00158 if( m_near > m_nearDistanceMax )
00159 {
00160 m_camera->setNearClipDistance( m_nearDistanceMax );
00161 m_near = m_nearDistanceMax;
00162 m_camera->setNearClipDistance(m_near);
00163 }
00164
00165 if( m_far > m_farDistanceMax )
00166 {
00167 m_camera->setFarClipDistance( m_farDistanceMax );
00168 m_far = m_farDistanceMax;
00169 m_camera->setFarClipDistance(m_far);
00170 }
00171
00172
00173 float n((Ogre::Real(MAX_RANGE) - 0.4 ) * m_near / m_nearDistanceMax);
00174 float f((Ogre::Real(MAX_RANGE) - 0.4 ) * m_far / m_farDistanceMax);
00175
00176
00177
00178 m_sliderNearClipPlane->SetValue( int( n ) );
00179 m_sliderFarClipPlane->SetValue( int( f ) );
00180 }
00181
00185 void srs_ui_but::CCameraControlPane::OnMaxSpin(wxSpinEvent & event)
00186 {
00187 updateClippingDistancesInfo();
00188 }
00189
00191
00192 BEGIN_EVENT_TABLE(srs_ui_but::CCameraControlPane, wxPanel)
00193 EVT_COMMAND_SCROLL(ID_NEAR_PLANE_SPIN, srs_ui_but::CCameraControlPane::OnNearPlane)
00194 EVT_COMMAND_SCROLL(ID_FAR_PLANE_SPIN, srs_ui_but::CCameraControlPane::OnFarPlane)
00195 EVT_SPINCTRL(ID_FAR_MAX_SPIN, srs_ui_but::CCameraControlPane::OnMaxSpin)
00196 END_EVENT_TABLE()