Skip to content

Instantly share code, notes, and snippets.

@michalpelka
Created January 19, 2024 10:12
Show Gist options
  • Save michalpelka/c8eebbe3b4efd4475597d53442db575e to your computer and use it in GitHub Desktop.
Save michalpelka/c8eebbe3b4efd4475597d53442db575e to your computer and use it in GitHub Desktop.
O3DE draw coordinate system
#include <Atom/RPI.Public/AuxGeom/AuxGeomFeatureProcessorInterface.h>
#include <Atom/RPI.Public/Scene.h>
void MyComponent::Activate()
{
auto* entityScene = AZ::RPI::Scene::GetSceneForEntityId(GetEntityId());
m_drawQueue = AZ::RPI::AuxGeomFeatureProcessorInterface::GetDrawQueueForScene(entityScene);
AZ::TickBus::Handler::BusConnect();
TwistNotificationBus::Handler::BusConnect(GetEntityId());
}
void DrawCoordinateSystem( AZ::RPI::AuxGeomDrawPtr drawQueue, const AZ::Transform &coordianteSystem, float len)
{
AZ_Assert(drawQueue, "Draw queue is null");
AZStd::vector<AZ::Vector3> linePoints;
AZStd::vector<AZ::Color > colors;
const AZ::Vector3 entityTranslation = coordianteSystem.GetTranslation();
const AZ::Vector3 axisX = coordianteSystem.GetBasisX();
const AZ::Vector3 axisY = coordianteSystem.GetBasisY();
const AZ::Vector3 axisZ = coordianteSystem.GetBasisZ();
AZ::RPI::AuxGeomDraw::AuxGeomDynamicDrawArguments drawArgs;
colors.push_back(AZ::Colors::Red);
colors.push_back(AZ::Colors::Red);
linePoints.push_back(entityTranslation);
linePoints.push_back(entityTranslation + axisX*len);
colors.push_back(AZ::Colors::Green);
colors.push_back(AZ::Colors::Green);
linePoints.push_back(entityTranslation);
linePoints.push_back(entityTranslation + axisY*len);
colors.push_back(AZ::Colors::Blue);
colors.push_back(AZ::Colors::Blue);
linePoints.push_back(entityTranslation);
linePoints.push_back(entityTranslation + axisZ*len);
drawArgs.m_colors = colors.data();
drawArgs.m_verts = linePoints.data();
drawArgs.m_vertCount = linePoints.size();
drawArgs.m_colorCount = colors.size();
drawArgs.m_opacityType = AZ::RPI::AuxGeomDraw::OpacityType::Opaque;
drawQueue->DrawLines(drawArgs);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment