Skip to content

Commit

Permalink
#5338: Camera class is now implementing the ICameraView interface. Re…
Browse files Browse the repository at this point in the history
…factoring.
  • Loading branch information
codereader committed Sep 25, 2020
1 parent 4ec5acb commit d9b3ccf
Show file tree
Hide file tree
Showing 7 changed files with 156 additions and 84 deletions.
10 changes: 5 additions & 5 deletions include/icameraview.h
Expand Up @@ -15,18 +15,18 @@ class ICameraView :
virtual ~ICameraView() {}

// Move the camera's origin
virtual Vector3 getCameraOrigin() const = 0;
virtual const Vector3& getCameraOrigin() const = 0;
virtual void setCameraOrigin(const Vector3& newOrigin) = 0;

virtual Vector3 getCameraAngles() const = 0;
virtual const Vector3& getCameraAngles() const = 0;
virtual void setCameraAngles(const Vector3& newAngles) = 0;

// Returns the vector pointing to the "right"
virtual Vector3 getRightVector() const = 0;
virtual const Vector3& getRightVector() const = 0;
// Returns the vector pointing "up"
virtual Vector3 getUpVector() const = 0;
virtual const Vector3& getUpVector() const = 0;
// Returns the vector pointing "forward"
virtual Vector3 getForwardVector() const = 0;
virtual const Vector3& getForwardVector() const = 0;
};

class IFreeMoveView :
Expand Down
41 changes: 14 additions & 27 deletions radiant/camera/CamWnd.cpp
Expand Up @@ -45,7 +45,6 @@ namespace
const char* const FAR_CLIP_IN_TEXT = N_("Move far clip plane closer");
const char* const FAR_CLIP_OUT_TEXT = N_("Move far clip plane further away");
const char* const FAR_CLIP_DISABLED_TEXT = N_(" (currently disabled in preferences)");
const char* const RKEY_SELECT_EPSILON = "user/ui/selectionEpsilon";
}

class ObjectFinder :
Expand Down Expand Up @@ -146,7 +145,7 @@ CamWnd::CamWnd(wxWindow* parent) :
_mainWxWidget(loadNamedPanel(parent, "CamWndPanel")),
_id(++_maxId),
_view(true),
_camera(_view, Callback(std::bind(&CamWnd::queueDraw, this))),
_camera(_view, std::bind(&CamWnd::queueDraw, this), std::bind(&CamWnd::forceRedraw, this)),
_drawing(false),
_wxGLWidget(new wxutil::GLWidget(_mainWxWidget, std::bind(&CamWnd::onRender, this), "CamWnd")),
_timer(this),
Expand Down Expand Up @@ -327,19 +326,7 @@ CamWnd::~CamWnd()

SelectionTestPtr CamWnd::createSelectionTestForPoint(const Vector2& point)
{
float selectEpsilon = registry::getValue<float>(RKEY_SELECT_EPSILON);

// Get the mouse position
Vector2 deviceEpsilon(selectEpsilon / getCamera().width, selectEpsilon / getCamera().height);

// Copy the current view and constrain it to a small rectangle
render::View scissored(_view);

auto rect = selection::Rectangle::ConstructFromPoint(point, deviceEpsilon);
scissored.EnableScissor(rect.min[0], rect.max[0],
rect.min[1], rect.max[1]);

return SelectionTestPtr(new SelectionVolume(scissored));
return _camera.createSelectionTestForPoint(point);
}

const VolumeTest& CamWnd::getVolumeTest() const
Expand Down Expand Up @@ -492,7 +479,7 @@ void CamWnd::jumpToObject(SelectionTest& selectionTest) {
}

void CamWnd::changeFloor(const bool up) {
float current = _camera.getOrigin()[2] - 48;
float current = _camera.getCameraOrigin()[2] - 48;
float bestUp;
float bestDown;
FloorHeightWalker walker(current, bestUp, bestDown);
Expand All @@ -506,8 +493,8 @@ void CamWnd::changeFloor(const bool up) {
current = bestDown;
}

const Vector3& org = _camera.getOrigin();
_camera.setOrigin(Vector3(org[0], org[1], current + 48));
const Vector3& org = _camera.getCameraOrigin();
_camera.setCameraOrigin(Vector3(org[0], org[1], current + 48));

_camera.updateModelview();
update();
Expand Down Expand Up @@ -859,39 +846,39 @@ void CamWnd::queueDraw()
_wxGLWidget->Refresh(false);
}

Vector3 CamWnd::getCameraOrigin() const
const Vector3& CamWnd::getCameraOrigin() const
{
return _camera.getOrigin();
return _camera.getCameraOrigin();
}

void CamWnd::setCameraOrigin(const Vector3& origin)
{
_camera.setOrigin(origin);
_camera.setCameraOrigin(origin);
}

Vector3 CamWnd::getRightVector() const
const Vector3& CamWnd::getRightVector() const
{
return _camera.vright;
}

Vector3 CamWnd::getUpVector() const
const Vector3& CamWnd::getUpVector() const
{
return _camera.vup;
}

Vector3 CamWnd::getForwardVector() const
const Vector3& CamWnd::getForwardVector() const
{
return _camera.vpn;
}

Vector3 CamWnd::getCameraAngles() const
const Vector3& CamWnd::getCameraAngles() const
{
return _camera.getAngles();
return _camera.getCameraAngles();
}

void CamWnd::setCameraAngles(const Vector3& angles)
{
_camera.setAngles(angles);
_camera.setCameraAngles(angles);
}

const Frustum& CamWnd::getViewFrustum() const
Expand Down
10 changes: 5 additions & 5 deletions radiant/camera/CamWnd.h
Expand Up @@ -103,14 +103,14 @@ class CamWnd :

Camera& getCamera();

Vector3 getCameraOrigin() const override;
const Vector3& getCameraOrigin() const override;
void setCameraOrigin(const Vector3& origin) override;

Vector3 getRightVector() const override;
Vector3 getUpVector() const override;
Vector3 getForwardVector() const override;
const Vector3& getRightVector() const override;
const Vector3& getUpVector() const override;
const Vector3& getForwardVector() const override;

Vector3 getCameraAngles() const override;
const Vector3& getCameraAngles() const override;
void setCameraAngles(const Vector3& angles) override;

const Frustum& getViewFrustum() const;
Expand Down

0 comments on commit d9b3ccf

Please sign in to comment.