Skip to content

Commit

Permalink
#5584: Migrate the RotateManipulator's pivot point renderable
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Jan 23, 2022
1 parent e0485ef commit 2ef4888
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 10 deletions.
2 changes: 0 additions & 2 deletions radiantcore/selection/RadiantSelectionSystem.cpp
Expand Up @@ -874,7 +874,6 @@ void RadiantSelectionSystem::captureShaders()

TranslateManipulator::_stateWire = GlobalRenderSystem().capture("$WIRE_OVERLAY");
TranslateManipulator::_stateFill = GlobalRenderSystem().capture("$FLATSHADE_OVERLAY");
RotateManipulator::_pivotPointShader = GlobalRenderSystem().capture("$POINT");
RotateManipulator::_glFont = GlobalOpenGL().getFont(manipulatorFontStyle, manipulatorFontSize);
}

Expand All @@ -883,7 +882,6 @@ void RadiantSelectionSystem::releaseShaders()
TranslateManipulator::_stateWire.reset();
TranslateManipulator::_stateFill.reset();
RotateManipulator::_glFont.reset();
RotateManipulator::_pivotPointShader.reset();
}

const WorkZone& RadiantSelectionSystem::getWorkZone()
Expand Down
44 changes: 44 additions & 0 deletions radiantcore/selection/manipulators/Renderables.h
Expand Up @@ -253,4 +253,48 @@ class RenderableCircle :
}
};

class RenderablePoint :
public render::RenderableGeometry
{
protected:
const Vertex3f& _point;
const Matrix4& _localToWorld;
bool _needsUpdate;
Vector4 _colour;

public:
RenderablePoint(const Vertex3f& point, const Matrix4& localToWorld) :
_point(point),
_localToWorld(localToWorld),
_needsUpdate(true)
{}

void queueUpdate()
{
_needsUpdate = true;
}

void setColour(const Colour4b& colour)
{
_colour = detail::toVector4(colour);
queueUpdate();
}

protected:
void updateGeometry() override
{
if (!_needsUpdate) return;

_needsUpdate = false;

std::vector<ArbitraryMeshVertex> vertices;
std::vector<unsigned int> indices;

vertices.push_back(ArbitraryMeshVertex(_localToWorld * _point, { 0,0,0 }, { 0,0 }, _colour));
indices.push_back(0);

RenderableGeometry::updateGeometry(render::GeometryType::Points, vertices, indices);
}
};

}
17 changes: 11 additions & 6 deletions radiantcore/selection/manipulators/RotateManipulator.cpp
Expand Up @@ -15,22 +15,20 @@ namespace
constexpr static auto CircleRadius = 64.0;
}

// Constructor
RotateManipulator::RotateManipulator(ManipulationPivot& pivot, std::size_t segments, float radius) :
_pivot(pivot),
_pivotTranslatable(_pivot),
_rotateFree(*this),
_rotateAxis(*this),
_translatePivot(_pivotTranslatable),
_localPivotPoint(0,0,0),
_circleX(CircleSegments, CircleRadius, _local2worldX),
_circleY(CircleSegments, CircleRadius, _local2worldY),
_circleZ(CircleSegments, CircleRadius, _local2worldZ),
_circleScreen(CircleSegments, CircleRadius * 1.15, _pivot2World._viewpointSpace),
_circleSphere(CircleSegments, CircleRadius, _pivot2World._viewpointSpace),
_pivotPoint(GL_POINTS)
{
_pivotPoint.push_back(VertexCb(Vertex3f(0,0,0), ManipulatorBase::COLOUR_SPHERE()));
}
_pivotPoint(_localPivotPoint, _pivot2World._worldSpace)
{}

void RotateManipulator::updateColours()
{
Expand Down Expand Up @@ -101,6 +99,11 @@ void RotateManipulator::onPreRender(const RenderSystemPtr& renderSystem, const V
_lineShader = renderSystem->capture("$WIRE_OVERLAY");
}

if (!_pivotPointShader)
{
_pivotPointShader = renderSystem->capture("$BIGPOINT");
}

_pivot2World.update(_pivot.getMatrix4(), volume.GetModelview(), volume.GetProjection(), volume.GetViewport());
updateCircleTransforms();

Expand All @@ -111,6 +114,7 @@ void RotateManipulator::onPreRender(const RenderSystemPtr& renderSystem, const V
_circleZ.update(_lineShader);
_circleScreen.update(_lineShader);
_circleSphere.update(_lineShader);
_pivotPoint.update(_pivotPointShader);
}

void RotateManipulator::render(IRenderableCollector& collector, const VolumeTest& volume)
Expand Down Expand Up @@ -151,7 +155,9 @@ void RotateManipulator::clearRenderables()
_circleZ.clear();
_circleScreen.clear();
_circleSphere.clear();
_pivotPoint.clear();
_lineShader.reset();
_pivotPointShader.reset();
}

std::string RotateManipulator::getRotationAxisName() const
Expand Down Expand Up @@ -313,7 +319,6 @@ void RotateManipulator::rotate(const Quaternion& rotation)
}

// Static members
ShaderPtr RotateManipulator::_pivotPointShader;
IGLFont::Ptr RotateManipulator::_glFont;

}
5 changes: 3 additions & 2 deletions radiantcore/selection/manipulators/RotateManipulator.h
Expand Up @@ -33,13 +33,14 @@ class RotateManipulator :
RotateAxis _rotateAxis;
TranslateFree _translatePivot;
Vector3 _axisScreen;
Vertex3f _localPivotPoint;

RenderableSemiCircle<RemapYZX> _circleX;
RenderableSemiCircle<RemapZXY> _circleY;
RenderableSemiCircle<RemapXYZ> _circleZ;
RenderableCircle<RemapXYZ> _circleScreen;
RenderableCircle<RemapXYZ> _circleSphere;
RenderablePointVector _pivotPoint;
RenderablePoint _pivotPoint;
BasicSelectable _selectableX;
BasicSelectable _selectableY;
BasicSelectable _selectableZ;
Expand All @@ -55,9 +56,9 @@ class RotateManipulator :
bool _circleZ_visible;

ShaderPtr _lineShader;
ShaderPtr _pivotPointShader;

public:
static ShaderPtr _pivotPointShader;
static IGLFont::Ptr _glFont;

// Constructor
Expand Down

0 comments on commit 2ef4888

Please sign in to comment.