|
| 1 | +#include "CameraDialog.hpp" |
| 2 | +#include "Geometry.hpp" |
| 3 | + |
| 4 | +static const wxSize nameMinSize (100, -1); |
| 5 | +static const wxSize smallControlMinSize (100, -1); |
| 6 | +static const wxSize controlMinSize (300, -1); |
| 7 | +static const double MinCameraValue = -10000.0; |
| 8 | +static const double MaxCameraValue = 10000.0; |
| 9 | + |
| 10 | +CameraDialog::CameraDialog (wxWindow* parent, const Modeler::Camera& camera) : |
| 11 | + wxDialog (parent, wxID_ANY, L"Camera Settings", wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE), |
| 12 | + origCamera (camera), |
| 13 | + saveButton (new wxButton (this, DialogIds::SaveButtonId, L"Save")), |
| 14 | + boxSizer (new wxBoxSizer (wxVERTICAL)), |
| 15 | + eyeXSpin (new wxSpinCtrlDouble (this, DialogIds::EyeXSpinId, L"", wxDefaultPosition, smallControlMinSize, wxSP_ARROW_KEYS, MinCameraValue, MaxCameraValue, 0.0, 0.1)), |
| 16 | + eyeYSpin (new wxSpinCtrlDouble (this, DialogIds::EyeYSpinId, L"", wxDefaultPosition, smallControlMinSize, wxSP_ARROW_KEYS, MinCameraValue, MaxCameraValue, 0.0, 0.1)), |
| 17 | + eyeZSpin (new wxSpinCtrlDouble (this, DialogIds::EyeZSpinId, L"", wxDefaultPosition, smallControlMinSize, wxSP_ARROW_KEYS, MinCameraValue, MaxCameraValue, 0.0, 0.1)), |
| 18 | + centerXSpin (new wxSpinCtrlDouble (this, DialogIds::CenterXSpinId, L"", wxDefaultPosition, smallControlMinSize, wxSP_ARROW_KEYS, MinCameraValue, MaxCameraValue, 0.0, 0.1)), |
| 19 | + centerYSpin (new wxSpinCtrlDouble (this, DialogIds::CenterYSpinId, L"", wxDefaultPosition, smallControlMinSize, wxSP_ARROW_KEYS, MinCameraValue, MaxCameraValue, 0.0, 0.1)), |
| 20 | + centerZSpin (new wxSpinCtrlDouble (this, DialogIds::CenterZSpinId, L"", wxDefaultPosition, smallControlMinSize, wxSP_ARROW_KEYS, MinCameraValue, MaxCameraValue, 0.0, 0.1)), |
| 21 | + upXSpin (new wxSpinCtrlDouble (this, DialogIds::UpXSpinId, L"", wxDefaultPosition, smallControlMinSize, wxSP_ARROW_KEYS, MinCameraValue, MaxCameraValue, 0.0, 0.1)), |
| 22 | + upYSpin (new wxSpinCtrlDouble (this, DialogIds::UpYSpinId, L"", wxDefaultPosition, smallControlMinSize, wxSP_ARROW_KEYS, MinCameraValue, MaxCameraValue, 0.0, 0.1)), |
| 23 | + upZSpin (new wxSpinCtrlDouble (this, DialogIds::UpZSpinId, L"", wxDefaultPosition, smallControlMinSize, wxSP_ARROW_KEYS, MinCameraValue, MaxCameraValue, 0.0, 0.1)) |
| 24 | +{ |
| 25 | + { |
| 26 | + wxBoxSizer* horizontalSizer = new wxBoxSizer (wxHORIZONTAL); |
| 27 | + horizontalSizer->Add (new wxStaticText (this, wxID_ANY, L"Eye Position", wxDefaultPosition, nameMinSize), 0, wxALIGN_CENTER_VERTICAL | wxALL, 5); |
| 28 | + wxBoxSizer* vectorHorizontalSizer = new wxBoxSizer (wxHORIZONTAL); |
| 29 | + vectorHorizontalSizer->Add (eyeXSpin, 1, wxEXPAND | wxALL, 5); |
| 30 | + vectorHorizontalSizer->Add (eyeYSpin, 1, wxEXPAND | wxALL, 5); |
| 31 | + vectorHorizontalSizer->Add (eyeZSpin, 1, wxEXPAND | wxALL, 5); |
| 32 | + horizontalSizer->Add (vectorHorizontalSizer, 1, wxEXPAND | wxALL, 0); |
| 33 | + boxSizer->Add (horizontalSizer, 0, wxEXPAND); |
| 34 | + } |
| 35 | + |
| 36 | + { |
| 37 | + wxBoxSizer* horizontalSizer = new wxBoxSizer (wxHORIZONTAL); |
| 38 | + horizontalSizer->Add (new wxStaticText (this, wxID_ANY, L"Center Position", wxDefaultPosition, nameMinSize), 0, wxALIGN_CENTER_VERTICAL | wxALL, 5); |
| 39 | + wxBoxSizer* vectorHorizontalSizer = new wxBoxSizer (wxHORIZONTAL); |
| 40 | + vectorHorizontalSizer->Add (centerXSpin, 1, wxEXPAND | wxALL, 5); |
| 41 | + vectorHorizontalSizer->Add (centerYSpin, 1, wxEXPAND | wxALL, 5); |
| 42 | + vectorHorizontalSizer->Add (centerZSpin, 1, wxEXPAND | wxALL, 5); |
| 43 | + horizontalSizer->Add (vectorHorizontalSizer, 1, wxEXPAND | wxALL, 0); |
| 44 | + boxSizer->Add (horizontalSizer, 0, wxEXPAND); |
| 45 | + } |
| 46 | + |
| 47 | + { |
| 48 | + wxBoxSizer* horizontalSizer = new wxBoxSizer (wxHORIZONTAL); |
| 49 | + horizontalSizer->Add (new wxStaticText (this, wxID_ANY, L"Up Vector", wxDefaultPosition, nameMinSize), 0, wxALIGN_CENTER_VERTICAL | wxALL, 5); |
| 50 | + wxBoxSizer* vectorHorizontalSizer = new wxBoxSizer (wxHORIZONTAL); |
| 51 | + vectorHorizontalSizer->Add (upXSpin, 1, wxEXPAND | wxALL, 5); |
| 52 | + vectorHorizontalSizer->Add (upYSpin, 1, wxEXPAND | wxALL, 5); |
| 53 | + vectorHorizontalSizer->Add (upZSpin, 1, wxEXPAND | wxALL, 5); |
| 54 | + horizontalSizer->Add (vectorHorizontalSizer, 1, wxEXPAND | wxALL, 0); |
| 55 | + boxSizer->Add (horizontalSizer, 0, wxEXPAND); |
| 56 | + } |
| 57 | + |
| 58 | + eyeXSpin->SetValue (camera.GetEye ().x); |
| 59 | + eyeYSpin->SetValue (camera.GetEye ().y); |
| 60 | + eyeZSpin->SetValue (camera.GetEye ().z); |
| 61 | + |
| 62 | + centerXSpin->SetValue (camera.GetCenter ().x); |
| 63 | + centerYSpin->SetValue (camera.GetCenter ().y); |
| 64 | + centerZSpin->SetValue (camera.GetCenter ().z); |
| 65 | + |
| 66 | + upXSpin->SetValue (camera.GetUp ().x); |
| 67 | + upYSpin->SetValue (camera.GetUp ().y); |
| 68 | + upZSpin->SetValue (camera.GetUp ().z); |
| 69 | + |
| 70 | + boxSizer->Add (saveButton, 0, wxEXPAND | wxDOWN | wxRIGHT | wxLEFT, 5); |
| 71 | + SetSizerAndFit (boxSizer); |
| 72 | + SetEscapeId (wxID_CANCEL); |
| 73 | +} |
| 74 | + |
| 75 | +Modeler::Camera CameraDialog::GetCamera () const |
| 76 | +{ |
| 77 | + glm::dvec3 eye (eyeXSpin->GetValue (), eyeYSpin->GetValue (), eyeZSpin->GetValue ()); |
| 78 | + glm::dvec3 center (centerXSpin->GetValue (), centerYSpin->GetValue (), centerZSpin->GetValue ()); |
| 79 | + glm::dvec3 up (upXSpin->GetValue (), upYSpin->GetValue (), upZSpin->GetValue ()); |
| 80 | + Modeler::Camera camera (eye, center, glm::normalize (up), origCamera.GetFieldOfViewY (), origCamera.GetNearPlane (), origCamera.GetFarPlane ()); |
| 81 | + return camera; |
| 82 | +} |
| 83 | + |
| 84 | +void CameraDialog::OnButtonClick (wxCommandEvent& evt) |
| 85 | +{ |
| 86 | + if (evt.GetId () == DialogIds::SaveButtonId) { |
| 87 | + glm::dvec3 eye (eyeXSpin->GetValue (), eyeYSpin->GetValue (), eyeZSpin->GetValue ()); |
| 88 | + glm::dvec3 center (centerXSpin->GetValue (), centerYSpin->GetValue (), centerZSpin->GetValue ()); |
| 89 | + glm::dvec3 up (upXSpin->GetValue (), upYSpin->GetValue (), upZSpin->GetValue ()); |
| 90 | + if (Modeler::IsValidCamera (eye, center, up, origCamera.GetFieldOfViewY (), origCamera.GetNearPlane (), origCamera.GetFarPlane ())) { |
| 91 | + EndModal (wxID_OK); |
| 92 | + } |
| 93 | + } |
| 94 | +} |
| 95 | + |
| 96 | +BEGIN_EVENT_TABLE (CameraDialog, wxDialog) |
| 97 | +EVT_BUTTON (wxID_ANY, CameraDialog::OnButtonClick) |
| 98 | +END_EVENT_TABLE () |
0 commit comments