Skip to content

Commit ec0b7e0

Browse files
committed
Set field of view of camera on camera settings dialog.
1 parent aa8ba29 commit ec0b7e0

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

Sources/Modeler/Camera.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ bool IsValidCamera (const glm::dvec3& eye,
163163
return false;
164164
}
165165

166-
if (Geometry::IsLowerOrEqual (fieldOfViewY, 0.0) || Geometry::IsGreaterOrEqual (fieldOfViewY, 180.0)) {
166+
if (Geometry::IsLowerOrEqual (fieldOfViewY, 0.0) || Geometry::IsGreater (fieldOfViewY, 90.0)) {
167167
return false;
168168
}
169169

Sources/VisualScriptCAD/Application/CameraDialog.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ CameraDialog::CameraDialog (wxWindow* parent, const Modeler::Camera& camera) :
2020
centerZSpin (new wxSpinCtrlDouble (this, DialogIds::CenterZSpinId, L"", wxDefaultPosition, smallControlMinSize, wxSP_ARROW_KEYS, MinCameraValue, MaxCameraValue, 0.0, 0.1)),
2121
upXSpin (new wxSpinCtrlDouble (this, DialogIds::UpXSpinId, L"", wxDefaultPosition, smallControlMinSize, wxSP_ARROW_KEYS, MinCameraValue, MaxCameraValue, 0.0, 0.1)),
2222
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))
23+
upZSpin (new wxSpinCtrlDouble (this, DialogIds::UpZSpinId, L"", wxDefaultPosition, smallControlMinSize, wxSP_ARROW_KEYS, MinCameraValue, MaxCameraValue, 0.0, 0.1)),
24+
fovYSpin (new wxSpinCtrlDouble (this, DialogIds::FovYSpinId, L"", wxDefaultPosition, smallControlMinSize, wxSP_ARROW_KEYS, 0.1, 90.0, 0.0, 0.1))
2425
{
2526
{
2627
wxBoxSizer* horizontalSizer = new wxBoxSizer (wxHORIZONTAL);
@@ -55,6 +56,13 @@ CameraDialog::CameraDialog (wxWindow* parent, const Modeler::Camera& camera) :
5556
boxSizer->Add (horizontalSizer, 0, wxEXPAND);
5657
}
5758

59+
{
60+
wxBoxSizer* horizontalSizer = new wxBoxSizer (wxHORIZONTAL);
61+
horizontalSizer->Add (new wxStaticText (this, wxID_ANY, L"Field of View", wxDefaultPosition, nameMinSize), 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
62+
horizontalSizer->Add (fovYSpin, 1, wxEXPAND | wxALL, 5);
63+
boxSizer->Add (horizontalSizer, 0, wxEXPAND);
64+
}
65+
5866
eyeXSpin->SetValue (camera.GetEye ().x);
5967
eyeYSpin->SetValue (camera.GetEye ().y);
6068
eyeZSpin->SetValue (camera.GetEye ().z);
@@ -67,6 +75,8 @@ CameraDialog::CameraDialog (wxWindow* parent, const Modeler::Camera& camera) :
6775
upYSpin->SetValue (camera.GetUp ().y);
6876
upZSpin->SetValue (camera.GetUp ().z);
6977

78+
fovYSpin->SetValue (camera.GetFieldOfViewY ());
79+
7080
boxSizer->Add (saveButton, 0, wxEXPAND | wxDOWN | wxRIGHT | wxLEFT, 5);
7181
SetSizerAndFit (boxSizer);
7282
SetEscapeId (wxID_CANCEL);
@@ -77,7 +87,8 @@ Modeler::Camera CameraDialog::GetCamera () const
7787
glm::dvec3 eye (eyeXSpin->GetValue (), eyeYSpin->GetValue (), eyeZSpin->GetValue ());
7888
glm::dvec3 center (centerXSpin->GetValue (), centerYSpin->GetValue (), centerZSpin->GetValue ());
7989
glm::dvec3 up (upXSpin->GetValue (), upYSpin->GetValue (), upZSpin->GetValue ());
80-
Modeler::Camera camera (eye, center, glm::normalize (up), origCamera.GetFieldOfViewY (), origCamera.GetNearPlane (), origCamera.GetFarPlane ());
90+
double fovY = fovYSpin->GetValue ();
91+
Modeler::Camera camera (eye, center, glm::normalize (up), fovY, origCamera.GetNearPlane (), origCamera.GetFarPlane ());
8192
return camera;
8293
}
8394

@@ -87,7 +98,8 @@ void CameraDialog::OnButtonClick (wxCommandEvent& evt)
8798
glm::dvec3 eye (eyeXSpin->GetValue (), eyeYSpin->GetValue (), eyeZSpin->GetValue ());
8899
glm::dvec3 center (centerXSpin->GetValue (), centerYSpin->GetValue (), centerZSpin->GetValue ());
89100
glm::dvec3 up (upXSpin->GetValue (), upYSpin->GetValue (), upZSpin->GetValue ());
90-
if (Modeler::IsValidCamera (eye, center, up, origCamera.GetFieldOfViewY (), origCamera.GetNearPlane (), origCamera.GetFarPlane ())) {
101+
double fovY = fovYSpin->GetValue ();
102+
if (Modeler::IsValidCamera (eye, center, up, fovY, origCamera.GetNearPlane (), origCamera.GetFarPlane ())) {
91103
EndModal (wxID_OK);
92104
}
93105
}

Sources/VisualScriptCAD/Application/CameraDialog.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class CameraDialog : public wxDialog
2020
UpXSpinId = 1007,
2121
UpYSpinId = 1008,
2222
UpZSpinId = 1009,
23+
FovYSpinId = 1010,
2324
SaveButtonId = 1100
2425
};
2526

@@ -43,6 +44,7 @@ class CameraDialog : public wxDialog
4344
wxSpinCtrlDouble* upXSpin;
4445
wxSpinCtrlDouble* upYSpin;
4546
wxSpinCtrlDouble* upZSpin;
47+
wxSpinCtrlDouble* fovYSpin;
4648

4749
DECLARE_EVENT_TABLE ();
4850
};

0 commit comments

Comments
 (0)