Skip to content

Commit

Permalink
#5584: Migrate the RotateManipulator's circle renderable
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Jan 23, 2022
1 parent 2d64d9f commit e0485ef
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 61 deletions.
14 changes: 7 additions & 7 deletions libs/render.h
Expand Up @@ -417,7 +417,7 @@ class RemapZXY

// VertexArray must expose a value_type typedef and implement an index operator[], like std::vector
template<typename remap_policy, typename VertexArray>
inline void draw_ellipse(const std::size_t numSegments, const float radiusX, const float radiusY, VertexArray& vertices, std::size_t firstVertex = 0)
inline void draw_ellipse(const std::size_t numSegments, const double radiusX, const double radiusY, VertexArray& vertices, std::size_t firstVertex = 0)
{
// Per half circle we push in (Segments x 4) vertices (the caller made room for that)
const auto numVerticesPerHalf = numSegments << 2;
Expand All @@ -436,13 +436,13 @@ inline void draw_ellipse(const std::size_t numSegments, const float radiusX, con
}

template<typename remap_policy, typename VertexArray>
inline void draw_semicircle(const std::size_t segments, const float radius, VertexArray& vertices)
inline void draw_semicircle(const std::size_t segments, const double radius, VertexArray& vertices)
{
const double increment = math::PI / double(segments << 2);

std::size_t count = 0;
float x = radius;
float y = 0;
double x = radius;
double y = 0;
remap_policy::set(vertices[segments << 2], -radius, 0, 0);

while (count < segments)
Expand All @@ -460,8 +460,8 @@ inline void draw_semicircle(const std::size_t segments, const float radius, Vert

{
const double theta = increment * count;
x = static_cast<float>(radius * cos(theta));
y = static_cast<float>(radius * sin(theta));
x = radius * cos(theta);
y = radius * sin(theta);
}

remap_policy::set(j, y, -x, 0);
Expand All @@ -470,7 +470,7 @@ inline void draw_semicircle(const std::size_t segments, const float radius, Vert
}

template<typename remap_policy, typename VertexArray>
inline void draw_circle(const std::size_t segments, const float radius, VertexArray& vertices, std::size_t firstVertex = 0)
inline void draw_circle(const std::size_t segments, const double radius, VertexArray& vertices, std::size_t firstVertex = 0)
{
draw_ellipse<remap_policy>(segments, radius, radius, vertices, firstVertex);
}
Expand Down
12 changes: 6 additions & 6 deletions libs/selection/BestPoint.h
Expand Up @@ -454,7 +454,7 @@ inline std::size_t clipLine(const Matrix4& matrix, const Vector3& p0,
return homogenous_clip_line(clipped);
}

inline void LineStrip_BestPoint(const Matrix4& local2view, const Vector3* vertices, const std::size_t size, SelectionIntersection& best)
inline void LineStrip_BestPoint(const Matrix4& local2view, const Vertex3f* vertices, const std::size_t size, SelectionIntersection& best)
{
Vector4 clipped[2];
for (std::size_t i = 0; (i + 1) < size; ++i)
Expand All @@ -464,12 +464,12 @@ inline void LineStrip_BestPoint(const Matrix4& local2view, const Vector3* vertic
}
}

inline void LineLoop_BestPoint(const Matrix4& local2view, const VertexCb* vertices, const std::size_t size, SelectionIntersection& best)
inline void LineLoop_BestPoint(const Matrix4& local2view, const Vertex3f* vertices, const std::size_t size, SelectionIntersection& best)
{
Vector4 clipped[2];
for (std::size_t i = 0; i < size; ++i)
{
const std::size_t count = clipLine(local2view, vertices[i].vertex, vertices[(i + 1) % size].vertex, clipped);
const std::size_t count = clipLine(local2view, vertices[i], vertices[(i + 1) % size], clipped);
BestPoint(count, clipped, best, eClipCullNone);
}
}
Expand Down Expand Up @@ -512,14 +512,14 @@ inline std::size_t clipTriangle(const Matrix4& matrix, const Vector3& p0,
return homogenous_clip_triangle(clipped);
}

inline void Circle_BestPoint(const Matrix4& local2view, clipcull_t cull, const VertexCb* vertices, const std::size_t size, SelectionIntersection& best)
inline void Circle_BestPoint(const Matrix4& local2view, clipcull_t cull, const Vertex3f* vertices, const std::size_t size, SelectionIntersection& best)
{
Vector4 clipped[9];
for (std::size_t i = 0; i < size; ++i)
{
const std::size_t count = clipTriangle(
local2view, g_vector3_identity, vertices[i].vertex,
vertices[(i + 1) % size].vertex, clipped
local2view, g_vector3_identity, vertices[i],
vertices[(i + 1) % size], clipped
);
BestPoint(count, clipped, best, cull);
}
Expand Down
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::_stateOuter = GlobalRenderSystem().capture("$WIRE_OVERLAY");
RotateManipulator::_pivotPointShader = GlobalRenderSystem().capture("$POINT");
RotateManipulator::_glFont = GlobalOpenGL().getFont(manipulatorFontStyle, manipulatorFontSize);
}
Expand All @@ -884,7 +883,6 @@ void RadiantSelectionSystem::releaseShaders()
TranslateManipulator::_stateWire.reset();
TranslateManipulator::_stateFill.reset();
RotateManipulator::_glFont.reset();
RotateManipulator::_stateOuter.reset();
RotateManipulator::_pivotPointShader.reset();
}

Expand Down
13 changes: 1 addition & 12 deletions radiantcore/selection/Renderables.h
Expand Up @@ -3,21 +3,10 @@
#include "render.h"
#include "render/VertexNCb.h"

/* greebo: This contains the renderables (rectangles, arrows, circles, semicircles) to represent
/* greebo: This contains the renderables (rectangles, arrows) to represent
* the manipulators of the selected items
*/

// helper class for rendering a circle
class RenderableCircle :
public RenderablePointVector
{
public:
// Pass the amount of points to render
RenderableCircle(std::size_t size) :
RenderablePointVector(GL_LINE_LOOP, size)
{}
};

// Helper class for rendering an arrow (only the line part)
class RenderableArrowLine :
public RenderablePointVector
Expand Down
47 changes: 33 additions & 14 deletions radiantcore/selection/manipulators/Renderables.h
Expand Up @@ -166,29 +166,18 @@ inline Vector4 toVector4(const Colour4b& colour)

}

template<typename RemapPolicy>
class RenderableSemiCircle :
// Renders a fixed size point array as line strip
class RenderableLineStrip :
public render::RenderableGeometry
{
private:
constexpr static auto Segments = 8;
constexpr static auto Radius = 64.0;

protected:
const Matrix4& _localToWorld;
bool _needsUpdate;
Vector4 _colour;

std::vector<Vertex3f> _rawPoints;

public:
RenderableSemiCircle(const Matrix4& localToWorld) :
_localToWorld(localToWorld),
_needsUpdate(true),
_rawPoints((Segments << 2) + 1)
{
draw_semicircle<RemapPolicy>(Segments, Radius, _rawPoints);
}

void queueUpdate()
{
_needsUpdate = true;
Expand All @@ -206,6 +195,12 @@ class RenderableSemiCircle :
}

protected:
RenderableLineStrip(std::size_t numPoints, const Matrix4& localToWorld) :
_localToWorld(localToWorld),
_needsUpdate(true),
_rawPoints(numPoints)
{}

void updateGeometry() override
{
if (!_needsUpdate) return;
Expand Down Expand Up @@ -234,4 +229,28 @@ class RenderableSemiCircle :
}
};

template<typename RemapPolicy>
class RenderableSemiCircle :
public RenderableLineStrip
{
public:
RenderableSemiCircle(std::size_t segments, double radius, const Matrix4& localToWorld) :
RenderableLineStrip((segments << 2) + 1, localToWorld)
{
draw_semicircle<RemapPolicy>(segments, radius, _rawPoints);
}
};

template<typename RemapPolicy>
class RenderableCircle :
public RenderableLineStrip
{
public:
RenderableCircle(std::size_t segments, double radius, const Matrix4& localToWorld) :
RenderableLineStrip(segments << 3, localToWorld)
{
draw_circle<RemapPolicy>(segments, radius, _rawPoints);
}
};

}
34 changes: 20 additions & 14 deletions radiantcore/selection/manipulators/RotateManipulator.cpp
Expand Up @@ -9,23 +9,26 @@
namespace selection
{

namespace
{
constexpr static auto CircleSegments = 8;
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),
_circleX(_local2worldX),
_circleY(_local2worldY),
_circleZ(_local2worldZ),
_circleScreen(segments<<3),
_circleSphere(segments<<3),
_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)
{
draw_circle<RemapXYZ>(segments, radius * 1.15f, _circleScreen);
draw_circle<RemapXYZ>(segments, radius, _circleSphere);

_pivotPoint.push_back(VertexCb(Vertex3f(0,0,0), ManipulatorBase::COLOUR_SPHERE()));
}

Expand All @@ -34,9 +37,9 @@ void RotateManipulator::updateColours()
_circleX.setColour(colourSelected(COLOUR_X(), _selectableX.isSelected()));
_circleY.setColour(colourSelected(COLOUR_Y(), _selectableY.isSelected()));
_circleZ.setColour(colourSelected(COLOUR_Z(), _selectableZ.isSelected()));
_circleScreen.setColour(colourSelected(ManipulatorBase::COLOUR_SCREEN(), _selectableScreen.isSelected()));
_circleSphere.setColour(colourSelected(ManipulatorBase::COLOUR_SPHERE(), false));
_pivotPoint.setColour(colourSelected(ManipulatorBase::COLOUR_SPHERE(), _selectablePivotPoint.isSelected()));
_circleScreen.setColour(colourSelected(COLOUR_SCREEN(), _selectableScreen.isSelected()));
_circleSphere.setColour(colourSelected(COLOUR_SPHERE(), false));
_pivotPoint.setColour(colourSelected(COLOUR_SPHERE(), _selectablePivotPoint.isSelected()));
}

void RotateManipulator::updateCircleTransforms()
Expand Down Expand Up @@ -106,6 +109,8 @@ void RotateManipulator::onPreRender(const RenderSystemPtr& renderSystem, const V
_circleX.update(_lineShader);
_circleY.update(_lineShader);
_circleZ.update(_lineShader);
_circleScreen.update(_lineShader);
_circleSphere.update(_lineShader);
}

void RotateManipulator::render(IRenderableCollector& collector, const VolumeTest& volume)
Expand Down Expand Up @@ -144,6 +149,8 @@ void RotateManipulator::clearRenderables()
_circleX.clear();
_circleY.clear();
_circleZ.clear();
_circleScreen.clear();
_circleSphere.clear();
_lineShader.reset();
}

Expand Down Expand Up @@ -217,13 +224,13 @@ void RotateManipulator::testSelect(SelectionTest& test, const Matrix4& pivot2wor

{
SelectionIntersection best;
LineLoop_BestPoint(local2view, &_circleScreen.front(), _circleScreen.size(), best);
LineLoop_BestPoint(local2view, &_circleScreen.getRawPoints().front(), _circleScreen.getRawPoints().size(), best);
selector.addSelectable(best, &_selectableScreen);
}

{
SelectionIntersection best;
Circle_BestPoint(local2view, eClipCullCW, &_circleSphere.front(), _circleSphere.size(), best);
Circle_BestPoint(local2view, eClipCullCW, &_circleSphere.getRawPoints().front(), _circleSphere.getRawPoints().size(), best);
selector.addSelectable(best, &_selectableSphere);
}
}
Expand Down Expand Up @@ -306,7 +313,6 @@ void RotateManipulator::rotate(const Quaternion& rotation)
}

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

Expand Down
6 changes: 2 additions & 4 deletions radiantcore/selection/manipulators/RotateManipulator.h
Expand Up @@ -37,9 +37,8 @@ class RotateManipulator :
RenderableSemiCircle<RemapYZX> _circleX;
RenderableSemiCircle<RemapZXY> _circleY;
RenderableSemiCircle<RemapXYZ> _circleZ;

RenderableCircle _circleScreen;
RenderableCircle _circleSphere;
RenderableCircle<RemapXYZ> _circleScreen;
RenderableCircle<RemapXYZ> _circleSphere;
RenderablePointVector _pivotPoint;
BasicSelectable _selectableX;
BasicSelectable _selectableY;
Expand All @@ -58,7 +57,6 @@ class RotateManipulator :
ShaderPtr _lineShader;

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

Expand Down
Expand Up @@ -100,7 +100,7 @@ constexpr double DefaultCrossHairSize = 10; // in device pixels
TextureToolRotateManipulator::TextureToolRotateManipulator(TextureToolManipulationPivot& pivot) :
_pivot(pivot),
_rotator(std::bind(&TextureToolRotateManipulator::rotateSelected, this, std::placeholders::_1, std::placeholders::_2)),
_renderableCircle(CircleSegments << 3),
_renderableCircle(GL_LINE_LOOP, CircleSegments << 3),
_circleRadius(DefaultCircleRadius)
{
draw_ellipse<RemapXYZ>(CircleSegments, static_cast<float>(DefaultCircleRadius), static_cast<float>(DefaultCircleRadius), _renderableCircle);
Expand Down
Expand Up @@ -54,7 +54,7 @@ class TextureToolRotateManipulator :

selection::BasicSelectable _selectableZ;
TextureRotator _rotator;
RenderableCircle _renderableCircle;
RenderablePointVector _renderableCircle;

ShaderPtr _shader;
IGLFont::Ptr _glFont;
Expand Down

0 comments on commit e0485ef

Please sign in to comment.