claw-code/.guardrails/examples/cpp/unreal-ui/volumetric-ui.cpp

309 lines
8.1 KiB
C++

/*
* volumetric-ui.cpp - Volumetric UI with Z-Depth
*
* Production-ready example demonstrating:
* - Volumetric rendering for UI elements
* - Z-depth parallax for XR environments
* - Holographic inventory previews
* - Eye-tracking focus indicators
* - Spatial computing patterns
*
* © 2026 - Agent Guardrails Template
*/
#include "CoreMinimal.h"
#include "Spatial/VolumetricRenderer.h"
#include "CommonUI/CommonUserWidget.h"
#include "DDA/DDAManager.h"
#include "Accessibility/AccessibilityPreferences.h"
namespace AgentGuardrails::UnrealUI
{
/**
* Volumetric UI System for UE5
* Z-depth parallax rendering for XR environments
*/
class UVolumetricUISystem : public UObject
{
GENERATED_BODY()
private:
VolumetricRenderer* volumetricRenderer;
DDAManager* ddaManager;
AccessibilityPreferences* accessibilityPrefs;
TArray<UCommonUserWidget*> volumetricWidgets;
float zDepthFactor = 0.5f;
public:
void Initialize()
{
volumetricRenderer = VolumetricRenderer::GetInstance();
ddaManager = DDAManager::GetInstance();
accessibilityPrefs = AccessibilityPreferences::GetInstance();
// Set default Z-depth factor for parallax
zDepthFactor = 0.3f;
}
/**
* Creates volumetric widget with Z-depth
* Holographic preview for inventory items
*/
UCommonUserWidget* CreateVolumetricWidget(const FString& widgetName, float depth)
{
auto* widget = NewObject<UCommonUserWidget>();
widget->SetName(widgetName);
// Set Z-depth for volumetric rendering
widget->SetDepth(depth);
// Enable holographic rendering
widget->EnableHolographic(true);
// Set parallax factor for spatial computing
widget->SetParallaxFactor(zDepthFactor);
volumetricWidgets.Add(widget);
return widget;
}
/**
* Creates holographic inventory preview
* Z-depth parallax for item cards
*/
UCommonUserWidget* CreateHolographicInventory()
{
auto* inventoryPanel = NewObject<UCommonUserWidget>();
inventoryPanel->SetName("HolographicInventory");
// Volumetric depth for item cards
inventoryPanel->SetDepth(0.5f);
inventoryPanel->EnableHolographic(true);
// GPU instancing for batch rendering
inventoryPanel->EnableGPUInstancing(true);
// Add item cards with Z-depth
auto* lootTable = LootTableManager::GetCurrentTable();
for (auto* item : lootTable->GetItems())
{
auto* itemCard = CreateVolumetricItemCard(item, 0.5f);
inventoryPanel->AddChild(itemCard);
}
return inventoryPanel;
}
/**
* Creates volumetric item card
* Z-depth parallax for XR environments
*/
UCommonUserWidget* CreateVolumetricItemCard(F LootItem* item, float depth)
{
auto* itemCard = NewObject<UCommonUserWidget>();
itemCard->SetName(item->GetName());
// Set Z-depth
itemCard->SetDepth(depth);
// Holographic glow for legendary items
if (item->GetRarity() == ERarity::Legendary)
{
itemCard->EnableHolographic(true);
itemCard->SetGlowIntensity(1.0f);
}
// Parallax scrolling
itemCard->SetParallaxFactor(zDepthFactor);
// Eye-tracking focus ring
itemCard->EnableEyeTrackingFocus(true);
itemCard->SetDwellThreshold(150.0f); // 150ms
return itemCard;
}
/**
* Creates parallax scrolling UI layer
* Multiple Z-depth layers for XR
*/
UCommonUserWidget* CreateParallaxLayer(const FString& layerName, float depth)
{
auto* layer = NewObject<UCommonUserWidget>();
layer->SetName(layerName);
// Set Z-depth for parallax
layer->SetDepth(depth);
layer->SetParallaxFactor(zDepthFactor);
// Enable volumetric rendering
layer->EnableVolumetric(true);
return layer;
}
/**
* Updates volumetric widgets based on DDA tier
* Reduces Z-depth complexity for stressed players
*/
void UpdateForDDATier(DDAManager::EDifficultyTier tier)
{
switch (tier)
{
case DDAManager::EDifficultyTier::Difficult:
// Stressed players: reduce Z-depth complexity
zDepthFactor = 0.1f;
SetVolumetricIntensity(0.5f);
break;
case DDAManager::EDifficultyTier::Normal:
// Standard Z-depth
zDepthFactor = 0.3f;
SetVolumetricIntensity(1.0f);
break;
case DDAManager::EDifficultyTier::Relaxed:
// Engaged players: enhanced Z-depth
zDepthFactor = 0.5f;
SetVolumetricIntensity(1.2f);
break;
}
}
/**
* Sets volumetric rendering intensity
* Scales with DDA 3.0 tier
*/
void SetVolumetricIntensity(float intensity)
{
for (auto* widget : volumetricWidgets)
{
widget->SetVolumetricIntensity(intensity);
}
}
/**
* Eye-tracking focus indicator
* Pupil dilation detection for stress
*/
void UpdateEyeTrackingFocus()
{
for (auto* widget : volumetricWidgets)
{
widget->EnableEyeTrackingFocus(true);
widget->SetDwellThreshold(150.0f);
}
}
/**
* Creates Z-depth health bar
| Volumetric health indicator with parallax
*/
UCommonUserWidget* CreateVolumetricHealthBar(const FString& healthBarName)
{
auto* healthBar = NewObject<UCommonUserWidget>();
healthBar->SetName(healthBarName);
// Z-depth for volumetric rendering
healthBar->SetDepth(0.3f);
healthBar->SetParallaxFactor(zDepthFactor);
// Shape + color redundancy for colorblindness
healthBar->SetShapeIndicator(true);
healthBar->SetHighContrast(accessibilityPrefs->IsHighContrastEnabled());
// DDA opacity adaptation
healthBar->SetOpacity(ddaManager->GetUIOpacityFactor());
return healthBar;
}
/**
* Creates volumetric skill tree
* Z-depth nodes for spatial computing
*/
UCommonUserWidget* CreateVolumetricSkillTree()
{
auto* skillTree = NewObject<UCommonUserWidget>();
skillTree->SetName("VolumetricSkillTree");
// Z-depth for skill nodes
skillTree->SetDepth(0.5f);
skillTree->EnableHolographic(true);
// GPU instancing for node rendering
skillTree->EnableGPUInstancing(true);
// Parallax factor for XR
skillTree->SetParallaxFactor(zDepthFactor);
return skillTree;
}
};
/**
* Volumetric UI Component
* Stores Z-depth and holographic state
*/
USTRUCT()
struct FVolumetricUIComponent
{
GENERATED_BODY()
float Depth; // Z-depth value (0.0-1.0)
bool IsHolographic; // Holographic rendering enabled
float ParallaxFactor; // Parallax scrolling factor
float VolumetricIntensity; // Intensity multiplier
bool EyeTrackingEnabled; // Eye-tracking support
float DwellThreshold; // Dwell threshold in ms
};
/**
* Volumetric rendering utilities
*/
namespace VolumetricUIUtils
{
/**
* Calculates parallax offset based on Z-depth
*/
FVector2D CalculateParallaxOffset(float depth, FVector2D viewportSize)
{
return FVector2D(
viewportSize.X * depth * 0.1f,
viewportSize.Y * depth * 0.1f
);
}
/**
* Creates holographic glow effect
*/
void ApplyHolographicGlow(UCommonUserWidget* widget, float intensity)
{
widget->SetGlowIntensity(intensity);
widget->EnableHolographic(true);
}
/**
* Enables eye-tracking focus ring
*/
void EnableEyeTrackingFocus(UCommonUserWidget* widget, float dwellThreshold)
{
widget->EnableEyeTrackingFocus(true);
widget->SetDwellThreshold(dwellThreshold);
}
}
// Enumeration definitions
UENUM()
enum class ERarity
{
Common,
Rare,
Epic,
Legendary
};
} // namespace AgentGuardrails::UnrealUI