Creating a new sample generator
The sample generator fills a list of angles that other modules use to generate the direction rays.
This is an example of the default generator:
#pragma once
#include "CoreMinimal.h"
#include "UObject/ObjectMacros.h"
#include "UObject/Object.h"
#include "Atoms/Agent.h"
#include "AtomsUnreal/Public/ContextSteering/AtomsContextSteeringSampleGenerator.h"
#include "AtomsContextSteeringMySampleGenerator.generated.h"
UCLASS(DefaultToInstanced, editinlinenew, DisplayName = "My Radial Sample Generator")
class UAtomsContextSteeringMySampleGenerator : public UAtomsContextSteeringSampleGenerator
{
GENERATED_BODY()
public:
UAtomsContextSteeringMySampleGenerator();
virtual void GenerateSamples(Atoms::Agent* Agent) override;
};
#include "AtomsContextSteeringMySampleGenerator.h"
#include "Atoms/Agent.h"
UAtomsContextSteeringMySampleGenerator::UAtomsContextSteeringMySampleGenerator() : UAtomsContextSteeringSampleGenerator()
{
}
void UAtomsContextSteeringMySampleGenerator::GenerateSamples(Atoms::Agent* Agent)
{
Atoms::ContextSteeringData& contextData = Agent->contextSteeringData();
contextData.setNumSamples(contextData.dynamicSamples > 0 ? contextData.dynamicSamples : NumSamples);
contextData.distance = MaxDistance;
auto& sampleDirections = contextData.samples;
auto& danger = contextData.danger;
AtomsMath::Vector3 upVector(0.0, 1.0, 0.0);
const AtomsMath::Vector3& AgentDirection = Agent->direction()->get();
contextData.direction = AgentDirection;
contextData.up = Agent->up()->get();
AtomsMath::Rand48 randVal(Agent->groupId()->get());
float angleStep = 2.0f * M_PI / static_cast<float>(NumSamples);
for (int32 j = 0; j < NumSamples; ++j)
{
float randangle = j != 0 ? randVal.nextf(-0.1, 0.1) * angleStep : 0.0;
float value = static_cast<float>(j) * angleStep + randangle;
sampleDirections[j] = value;
}
// reset the dynamic samples since we have generated them
contextData.dynamicSamples = 0;
}
Copyright © 2017, Toolchefs LTD.