Skip to content

Commit

Permalink
Minor refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Dec 17, 2016
1 parent 38df914 commit 22a1a15
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 67 deletions.
51 changes: 0 additions & 51 deletions libs/pivot.h
Expand Up @@ -167,57 +167,6 @@ inline void ConstructDevice2Manip(Matrix4& device2manip, const Matrix4& object2w
device2manip.invertFull();
}

inline void Pivot2World_worldSpace(Matrix4& manip2world, const Matrix4& pivot2world, const Matrix4& modelview, const Matrix4& projection, const Matrix4& viewport)
{
manip2world = pivot2world;

Matrix4 pivot2screen;
ConstructObject2Screen(pivot2screen, pivot2world, modelview, projection, viewport);

Matrix4 scale;
pivot_scale(scale, pivot2screen);
manip2world.multiplyBy(scale);
pivot_perspective(scale, pivot2screen);
manip2world.multiplyBy(scale);
}

inline void Pivot2World_viewpointSpace(Matrix4& manip2world, Vector3& axis, const Matrix4& pivot2world, const Matrix4& modelview, const Matrix4& projection, const Matrix4& viewport)
{
manip2world = pivot2world;

Matrix4 pivot2screen;
ConstructObject2Screen(pivot2screen, pivot2world, modelview, projection, viewport);

Matrix4 scale;
pivot_scale(scale, pivot2screen);
manip2world.multiplyBy(scale);

billboard_viewpointOriented(scale, pivot2screen);
axis = scale.z().getVector3();
manip2world.multiplyBy(scale);

pivot_perspective(scale, pivot2screen);
manip2world.multiplyBy(scale);
}

inline void Pivot2World_viewplaneSpace(Matrix4& manip2world, const Matrix4& pivot2world, const Matrix4& modelview, const Matrix4& projection, const Matrix4& viewport)
{
manip2world = pivot2world;

Matrix4 pivot2screen;
ConstructObject2Screen(pivot2screen, pivot2world, modelview, projection, viewport);

Matrix4 scale;
pivot_scale(scale, pivot2screen);
manip2world.multiplyBy(scale);

billboard_viewplaneOriented(scale, pivot2screen);
manip2world.multiplyBy(scale);

pivot_perspective(scale, pivot2screen);
manip2world.multiplyBy(scale);
}

const Colour4b g_colour_x(255, 0, 0, 255);
const Colour4b g_colour_y(0, 255, 0, 255);
const Colour4b g_colour_z(0, 0, 255, 255);
Expand Down
82 changes: 68 additions & 14 deletions radiant/selection/Pivot2World.h
@@ -1,22 +1,76 @@
#pragma once

#include "Pivot2World.h"
#include "pivot.h"

struct Pivot2World
namespace selection
{
Matrix4 _worldSpace;
Matrix4 _viewpointSpace;
Matrix4 _viewplaneSpace;
Vector3 _axisScreen;

void update(const Matrix4& pivot2world, const Matrix4& modelview, const Matrix4& projection, const Matrix4& viewport)
{
Pivot2World_worldSpace(_worldSpace, pivot2world, modelview, projection, viewport);
Pivot2World_viewpointSpace(_viewpointSpace, _axisScreen, pivot2world, modelview, projection, viewport);
Pivot2World_viewplaneSpace(_viewplaneSpace, pivot2world, modelview, projection, viewport);
}
};

class Pivot2World
{
public:
Matrix4 _worldSpace;
Matrix4 _viewpointSpace;
Matrix4 _viewplaneSpace;
Vector3 _axisScreen;

void update(const Matrix4& pivot2world, const Matrix4& modelview, const Matrix4& projection, const Matrix4& viewport)
{
calculcateWorldSpace(pivot2world, modelview, projection, viewport);
calculateViewpointSpace(pivot2world, modelview, projection, viewport);
calculateViewplaneSpace(pivot2world, modelview, projection, viewport);
}

private:
void calculcateWorldSpace(const Matrix4& pivot2world, const Matrix4& modelview, const Matrix4& projection, const Matrix4& viewport)
{
_worldSpace = pivot2world;

Matrix4 pivot2screen;
ConstructObject2Screen(pivot2screen, pivot2world, modelview, projection, viewport);

Matrix4 scale;
pivot_scale(scale, pivot2screen);
_worldSpace.multiplyBy(scale);
pivot_perspective(scale, pivot2screen);
_worldSpace.multiplyBy(scale);
}

void calculateViewpointSpace(const Matrix4& pivot2world, const Matrix4& modelview, const Matrix4& projection, const Matrix4& viewport)
{
_viewpointSpace = pivot2world;

Matrix4 pivot2screen;
ConstructObject2Screen(pivot2screen, pivot2world, modelview, projection, viewport);

Matrix4 scale;
pivot_scale(scale, pivot2screen);
_viewpointSpace.multiplyBy(scale);

billboard_viewpointOriented(scale, pivot2screen);
_axisScreen = scale.z().getVector3();
_viewpointSpace.multiplyBy(scale);

pivot_perspective(scale, pivot2screen);
_viewpointSpace.multiplyBy(scale);
}

void calculateViewplaneSpace(const Matrix4& pivot2world, const Matrix4& modelview, const Matrix4& projection, const Matrix4& viewport)
{
_viewplaneSpace = pivot2world;

Matrix4 pivot2screen;
ConstructObject2Screen(pivot2screen, pivot2world, modelview, projection, viewport);

Matrix4 scale;
pivot_scale(scale, pivot2screen);
_viewplaneSpace.multiplyBy(scale);

billboard_viewplaneOriented(scale, pivot2screen);
_viewplaneSpace.multiplyBy(scale);

pivot_perspective(scale, pivot2screen);
_viewplaneSpace.multiplyBy(scale);
}
};

}
5 changes: 3 additions & 2 deletions radiant/selection/RadiantSelectionSystem.cpp
Expand Up @@ -549,7 +549,8 @@ bool RadiantSelectionSystem::SelectManipulator(const render::View& view, const V
_pivotMoving = _activeManipulator->isSelected();

// is a manipulator selected / the pivot moving?
if (_pivotMoving) {
if (_pivotMoving)
{
Pivot2World pivot;
pivot.update(GetPivot2World(), view.GetModelview(), view.GetProjection(), view.GetViewport());

Expand All @@ -559,7 +560,7 @@ bool RadiantSelectionSystem::SelectManipulator(const render::View& view, const V
ConstructDevice2Manip(device2manip, _pivot2worldStart, view.GetModelview(), view.GetProjection(), view.GetViewport());
_activeManipulator->getActiveComponent()->Construct(device2manip, device_point[0], device_point[1]);

_deviceStart = Vector2(device_point[0], device_point[1]);
_deviceStart = device_point;

_undoBegun = false;
}
Expand Down

0 comments on commit 22a1a15

Please sign in to comment.