Skip to content

Commit

Permalink
#5584: Speaker radii rendered in the colour of the entity
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Dec 17, 2021
1 parent 4bf23fc commit 8c607e9
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 17 deletions.
8 changes: 4 additions & 4 deletions radiantcore/entity/speaker/SpeakerNode.cpp
Expand Up @@ -19,8 +19,8 @@ SpeakerNode::SpeakerNode(const IEntityClassPtr& eclass) :
m_originKey(std::bind(&SpeakerNode::originChanged, this)),
m_origin(ORIGINKEY_IDENTITY),
_renderableBox(m_aabb_local, worldAABB().getOrigin()),
_renderableRadiiWireframe(m_origin, _radiiTransformed),
_renderableRadiiFill(m_origin, _radiiTransformed),
_renderableRadiiWireframe(*this, m_origin, _radiiTransformed),
_renderableRadiiFill(*this, m_origin, _radiiTransformed),
_showRadiiWhenUnselected(EntitySettings::InstancePtr()->getShowAllSpeakerRadii()),
m_useSpeakerRadii(true),
m_minIsSet(false),
Expand All @@ -37,8 +37,8 @@ SpeakerNode::SpeakerNode(const SpeakerNode& other) :
m_originKey(std::bind(&SpeakerNode::originChanged, this)),
m_origin(ORIGINKEY_IDENTITY),
_renderableBox(m_aabb_local, worldAABB().getOrigin()),
_renderableRadiiWireframe(m_origin, _radiiTransformed),
_renderableRadiiFill(m_origin, _radiiTransformed),
_renderableRadiiWireframe(*this, m_origin, _radiiTransformed),
_renderableRadiiFill(*this, m_origin, _radiiTransformed),
_showRadiiWhenUnselected(EntitySettings::InstancePtr()->getShowAllSpeakerRadii()),
m_useSpeakerRadii(true),
m_minIsSet(false),
Expand Down
21 changes: 13 additions & 8 deletions radiantcore/entity/speaker/SpeakerRenderables.cpp
Expand Up @@ -60,10 +60,13 @@ void RenderableSpeakerRadiiWireframe::updateGeometry()
// The indices for 6 circles stay the same, so we can store this statically
static auto CircleIndices = generateWireframeCircleIndices(vertices.size(), NumCircles);

auto colour = _entity.getEntityColour();

// Move the points to their world position
for (auto& vertex : vertices)
{
vertex.vertex += _origin;
vertex.colour = colour;
}

RenderableGeometry::updateGeometry(render::GeometryType::Lines, vertices, CircleIndices);
Expand Down Expand Up @@ -142,8 +145,12 @@ inline std::vector<unsigned int> generateSphereIndices()
return indices;
}

inline void generateSphereVertices(std::vector<ArbitraryMeshVertex>& vertices, double radius, const Vector3& origin)
}

void RenderableSpeakerRadiiFill::generateSphereVertices(std::vector<ArbitraryMeshVertex>& vertices, double radius)
{
auto colour = _entity.getEntityColour();

for (auto strip = 0; strip < NumCircles; ++strip)
{
auto theta = ThetaStep * (strip + 1);
Expand All @@ -159,15 +166,13 @@ inline void generateSphereVertices(std::vector<ArbitraryMeshVertex>& vertices, d
auto unit = Vector3(cos(phi) * sinTheta, sin(phi) * sinTheta, cosTheta);

// Move the points to their world position
vertices.push_back(ArbitraryMeshVertex(unit * radius + origin, unit, { 0, 0 }));
vertices.push_back(ArbitraryMeshVertex(unit * radius + _origin, unit, { 0, 0 }, colour));
}
}

// The north and south pole vertices
vertices.push_back(ArbitraryMeshVertex(Vector3(0, 0, radius) + origin, { 0,0,1 }, { 0,0 }));
vertices.push_back(ArbitraryMeshVertex(Vector3(0, 0, -radius) + origin, { 0,0,-1 }, { 0,0 }));
}

vertices.push_back(ArbitraryMeshVertex(Vector3(0, 0, radius) + _origin, { 0,0,1 }, { 0,0 }, colour));
vertices.push_back(ArbitraryMeshVertex(Vector3(0, 0, -radius) + _origin, { 0,0,-1 }, { 0,0 }, colour));
}

void RenderableSpeakerRadiiFill::updateGeometry()
Expand All @@ -181,8 +186,8 @@ void RenderableSpeakerRadiiFill::updateGeometry()
// Make space for two spheres
vertices.reserve(NumVerticesPerSphere << 1);

generateSphereVertices(vertices, _radii.getMax(), _origin);
generateSphereVertices(vertices, _radii.getMin(), _origin);
generateSphereVertices(vertices, _radii.getMax());
generateSphereVertices(vertices, _radii.getMin());

// Generate the quad indices for two spheres
static auto SphereIndices = generateSphereIndices();
Expand Down
16 changes: 11 additions & 5 deletions radiantcore/entity/speaker/SpeakerRenderables.h
Expand Up @@ -13,14 +13,17 @@ class RenderableSpeakerRadiiBase :
protected:
bool _needsUpdate;

const IEntityNode& _entity;

const Vector3& _origin;

// SoundRadii reference containing min and max radius values
// (the actual instance resides in the SpeakerNode)
const SoundRadii& _radii;

protected:
RenderableSpeakerRadiiBase(const Vector3& origin, const SoundRadii& radii) :
RenderableSpeakerRadiiBase(const IEntityNode& entity, const Vector3& origin, const SoundRadii& radii) :
_entity(entity),
_origin(origin),
_radii(radii)
{}
Expand All @@ -42,8 +45,8 @@ class RenderableSpeakerRadiiWireframe :
{
public:
// Construct an instance with the given origin and radius.
RenderableSpeakerRadiiWireframe(const Vector3& origin, const SoundRadii& radii) :
RenderableSpeakerRadiiBase(origin, radii)
RenderableSpeakerRadiiWireframe(const IEntityNode& entity, const Vector3& origin, const SoundRadii& radii) :
RenderableSpeakerRadiiBase(entity, origin, radii)
{}

void updateGeometry() override;
Expand All @@ -59,11 +62,14 @@ class RenderableSpeakerRadiiFill :
{
public:
// Construct an instance with the given origin and radius.
RenderableSpeakerRadiiFill(const Vector3& origin, const SoundRadii& radii) :
RenderableSpeakerRadiiBase(origin, radii)
RenderableSpeakerRadiiFill(const IEntityNode& entity, const Vector3& origin, const SoundRadii& radii) :
RenderableSpeakerRadiiBase(entity, origin, radii)
{}

void updateGeometry() override;

private:
void generateSphereVertices(std::vector<ArbitraryMeshVertex>& vertices, double radius);
};

} // namespace

0 comments on commit 8c607e9

Please sign in to comment.