Skip to content

Commit

Permalink
#5584: Draw entity angle arrows
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Dec 10, 2021
1 parent 7b2f1dd commit 2832096
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 5 deletions.
1 change: 1 addition & 0 deletions radiantcore/CMakeLists.txt
Expand Up @@ -47,6 +47,7 @@ add_library(radiantcore MODULE
entity/ModelKey.cpp
entity/NameKeyObserver.cpp
entity/NamespaceManager.cpp
entity/RenderableArrow.cpp
entity/RenderableEntityBox.cpp
entity/RotationKey.cpp
entity/RotationMatrix.cpp
Expand Down
63 changes: 63 additions & 0 deletions radiantcore/entity/RenderableArrow.cpp
@@ -0,0 +1,63 @@
#include "RenderableArrow.h"

#include "EntityNode.h"

namespace entity
{

RenderableArrow::RenderableArrow(EntityNode& node) :
_node(node),
_needsUpdate(true)
{}

void RenderableArrow::queueUpdate()
{
_needsUpdate = true;
}

void RenderableArrow::updateGeometry()
{
if (!_needsUpdate) return;

_needsUpdate = false;

static Vector3 Up(0, 0, 1);
const auto& origin = _node.worldAABB().getOrigin();
const auto& direction = _node.getDirection();
Vector3 left(-direction.y(), direction.x(), 0);

Vector3 endpoint(origin + direction * 32.0);

Vector3 tip1(endpoint + direction * (-8.0) + Up * (-4.0));
Vector3 tip2(tip1 + Up * 8.0);
Vector3 tip3(endpoint + direction * (-8.0) + left * (-4.0));
Vector3 tip4(tip3 + left * 8.0);

std::vector<ArbitraryMeshVertex> vertices
{
ArbitraryMeshVertex(origin, {1,0,0}, {0,0}),
ArbitraryMeshVertex(endpoint, {1,0,0}, {0,0}),
ArbitraryMeshVertex(tip1, {1,0,0}, {0,0}),
ArbitraryMeshVertex(tip2, {1,0,0}, {0,0}),
ArbitraryMeshVertex(tip3, {1,0,0}, {0,0}),
ArbitraryMeshVertex(tip4, {1,0,0}, {0,0}),
};

// Indices are always the same, therefore constant
static const std::vector<unsigned int> Indices
{
0, 1, // origin to endpoint
1, 2, // endpoint to tip1
1, 3, // endpoint to tip2
1, 4, // endpoint to tip3
1, 5, // endpoint to tip4
2, 4, // tip1 to tip3
4, 3, // tip3 to tip2
3, 5, // tip2 to tip4
5, 2, // tip4 to tip1
};

RenderableGeometry::updateGeometry(render::GeometryType::Lines, vertices, Indices);
}

}
25 changes: 25 additions & 0 deletions radiantcore/entity/RenderableArrow.h
@@ -0,0 +1,25 @@
#pragma once

#include "render/RenderableGeometry.h"

namespace entity
{

class EntityNode;

class RenderableArrow :
public render::RenderableGeometry
{
private:
const EntityNode& _node;
bool _needsUpdate;

public:
RenderableArrow(EntityNode& node);

void queueUpdate();

virtual void updateGeometry() override;
};

}
2 changes: 1 addition & 1 deletion radiantcore/entity/RenderableEntityBox.cpp
Expand Up @@ -119,7 +119,7 @@ void RenderableEntityBox::setFillMode(bool fill)
if (_filledBox != fill)
{
_filledBox = fill;
clear(); // maybe only clear the box part?
clear();
}
}

Expand Down
14 changes: 12 additions & 2 deletions radiantcore/entity/generic/GenericEntityNode.cpp
Expand Up @@ -13,7 +13,7 @@ GenericEntityNode::GenericEntityNode(const IEntityClassPtr& eclass) :
m_angleKey(std::bind(&GenericEntityNode::angleChanged, this)),
m_angle(AngleKey::IDENTITY),
m_rotationKey(std::bind(&GenericEntityNode::rotationChanged, this)),
m_arrow(m_ray),
_renderableArrow(*this),
m_aabb_solid(m_aabb_local),
m_aabb_wire(m_aabb_local),
_renderableBox(*this),
Expand All @@ -29,7 +29,7 @@ GenericEntityNode::GenericEntityNode(const GenericEntityNode& other) :
m_angleKey(std::bind(&GenericEntityNode::angleChanged, this)),
m_angle(AngleKey::IDENTITY),
m_rotationKey(std::bind(&GenericEntityNode::rotationChanged, this)),
m_arrow(m_ray),
_renderableArrow(*this),
m_aabb_solid(m_aabb_local),
m_aabb_wire(m_aabb_local),
_renderableBox(*this),
Expand Down Expand Up @@ -134,15 +134,18 @@ void GenericEntityNode::onPreRender(const VolumeTest& volume)
EntityNode::onPreRender(volume);

_renderableBox.update(getColourShader());
_renderableArrow.update(getColourShader());
}

void GenericEntityNode::renderArrow(const ShaderPtr& shader, IRenderableCollector& collector,
const VolumeTest& volume, const Matrix4& localToWorld) const
{
#if 0
if (EntitySettings::InstancePtr()->getShowEntityAngles())
{
collector.addRenderable(*shader, m_arrow, localToWorld);
}
#endif
}

void GenericEntityNode::renderSolid(IRenderableCollector& collector, const VolumeTest& volume) const
Expand Down Expand Up @@ -172,6 +175,7 @@ void GenericEntityNode::setRenderSystem(const RenderSystemPtr& renderSystem)

// Clear the geometry from any previous shader
_renderableBox.clear();
_renderableArrow.clear();
}

const Vector3& GenericEntityNode::getDirection() const
Expand Down Expand Up @@ -237,6 +241,7 @@ void GenericEntityNode::updateTransform()
.transformDirection(Vector3(1, 0, 0));
}

_renderableArrow.queueUpdate();
transformChanged();
}

Expand All @@ -251,6 +256,7 @@ void GenericEntityNode::_onTransformationChanged()

updateTransform();
_renderableBox.queueUpdate();
_renderableArrow.queueUpdate();
}
}

Expand Down Expand Up @@ -323,6 +329,7 @@ void GenericEntityNode::onInsertIntoScene(scene::IMapRootNode& root)
EntityNode::onInsertIntoScene(root);

_renderableBox.queueUpdate();
_renderableArrow.queueUpdate();
}

void GenericEntityNode::onRemoveFromScene(scene::IMapRootNode& root)
Expand All @@ -331,6 +338,7 @@ void GenericEntityNode::onRemoveFromScene(scene::IMapRootNode& root)
EntityNode::onRemoveFromScene(root);

_renderableBox.clear();
_renderableArrow.clear();
}

void GenericEntityNode::onVisibilityChanged(bool isVisibleNow)
Expand All @@ -340,10 +348,12 @@ void GenericEntityNode::onVisibilityChanged(bool isVisibleNow)
if (isVisibleNow)
{
_renderableBox.queueUpdate();
_renderableArrow.queueUpdate();
}
else
{
_renderableBox.clear();
_renderableArrow.clear();
}
}

Expand Down
4 changes: 2 additions & 2 deletions radiantcore/entity/generic/GenericEntityNode.h
Expand Up @@ -16,7 +16,7 @@
#include "../SpawnArgs.h"
#include "../KeyObserverDelegate.h"

#include "RenderableArrow.h"
#include "../RenderableArrow.h"
#include "../RenderableEntityBox.h"

namespace entity
Expand Down Expand Up @@ -46,7 +46,7 @@ class GenericEntityNode: public EntityNode, public Snappable
AABB m_aabb_local;
Ray m_ray;

RenderableArrow m_arrow;
RenderableArrow _renderableArrow;
RenderableSolidAABB m_aabb_solid;
RenderableWireframeAABB m_aabb_wire;
RenderableEntityBox _renderableBox;
Expand Down
2 changes: 2 additions & 0 deletions tools/msvc/DarkRadiantCore.vcxproj
Expand Up @@ -61,6 +61,7 @@
<ClCompile Include="..\..\radiantcore\entity\ModelKey.cpp" />
<ClCompile Include="..\..\radiantcore\entity\NameKeyObserver.cpp" />
<ClCompile Include="..\..\radiantcore\entity\NamespaceManager.cpp" />
<ClCompile Include="..\..\radiantcore\entity\RenderableArrow.cpp" />
<ClCompile Include="..\..\radiantcore\entity\RenderableEntityBox.cpp" />
<ClCompile Include="..\..\radiantcore\entity\RotationKey.cpp" />
<ClCompile Include="..\..\radiantcore\entity\RotationMatrix.cpp" />
Expand Down Expand Up @@ -783,6 +784,7 @@
<ClInclude Include="..\..\radiantcore\entity\NameKeyObserver.h" />
<ClInclude Include="..\..\radiantcore\entity\NamespaceManager.h" />
<ClInclude Include="..\..\radiantcore\entity\OriginKey.h" />
<ClInclude Include="..\..\radiantcore\entity\RenderableArrow.h" />
<ClInclude Include="..\..\radiantcore\entity\RenderableEntityBox.h" />
<ClInclude Include="..\..\radiantcore\entity\RotationKey.h" />
<ClInclude Include="..\..\radiantcore\entity\RotationMatrix.h" />
Expand Down
6 changes: 6 additions & 0 deletions tools/msvc/DarkRadiantCore.vcxproj.filters
Expand Up @@ -1111,6 +1111,9 @@
<ClCompile Include="..\..\radiantcore\entity\RenderableEntityBox.cpp">
<Filter>src\entity</Filter>
</ClCompile>
<ClCompile Include="..\..\radiantcore\entity\RenderableArrow.cpp">
<Filter>src\entity</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\radiantcore\modulesystem\ModuleLoader.h">
Expand Down Expand Up @@ -2262,5 +2265,8 @@
<ClInclude Include="..\..\radiantcore\entity\RenderableEntityBox.h">
<Filter>src\entity</Filter>
</ClInclude>
<ClInclude Include="..\..\radiantcore\entity\RenderableArrow.h">
<Filter>src\entity</Filter>
</ClInclude>
</ItemGroup>
</Project>

0 comments on commit 2832096

Please sign in to comment.