13SpotLightComponent::SpotLightComponent(SceneGraphNode* sgn, PlatformContext& context)
15 Light(sgn, 30.0f,
LightType::
SPOT, *sgn->sceneGraph()->parentScene().lightPool())
17 _shadowProperties._lightDetails.z = 0.0001f;
19 EditorComponentField cutoffAngle = {};
20 cutoffAngle._name =
"Cutoff Angle";
21 cutoffAngle._data = &_coneCutoffAngle;
22 cutoffAngle._type = EditorComponentFieldType::PUSH_TYPE;
23 cutoffAngle._readOnly =
false;
25 cutoffAngle._basicType = PushConstantType::FLOAT;
26 editorComponent().registerField(
MOV(cutoffAngle));
28 EditorComponentField outerCutoffAngle = {};
29 outerCutoffAngle._name =
"Outer Cutoff Angle";
30 outerCutoffAngle._data = &_outerConeCutoffAngle;
31 outerCutoffAngle._type = EditorComponentFieldType::PUSH_TYPE;
32 outerCutoffAngle._readOnly =
false;
34 outerCutoffAngle._basicType = PushConstantType::FLOAT;
35 editorComponent().registerField(
MOV(outerCutoffAngle));
37 EditorComponentField directionField = {};
38 directionField._name =
"Direction";
39 directionField._dataGetter = [
this](
void* dataOut)
noexcept {
static_cast<vec3<F32>*
>(dataOut)->set(directionCache()); };
40 directionField._dataSetter = [
this](
const void* data) {
setDirection(*
static_cast<const vec3<F32>*
>(data)); };
41 directionField._type = EditorComponentFieldType::PUSH_TYPE;
42 directionField._readOnly =
true;
43 directionField._basicType = PushConstantType::VEC3;
45 editorComponent().registerField(
MOV(directionField));
47 EditorComponentField showConeField = {};
48 showConeField._name =
"Show direction cone";
49 showConeField._data = &_showDirectionCone;
50 showConeField._type = EditorComponentFieldType::PUSH_TYPE;
51 showConeField._readOnly =
false;
52 showConeField._basicType = PushConstantType::BOOL;
54 editorComponent().registerField(
MOV(showConeField));
56 registerFields(editorComponent());
58 editorComponent().onChangedCbk([
this](std::string_view)
noexcept {
59 if (coneCutoffAngle() > outerConeCutoffAngle()) {
60 coneCutoffAngle(outerConeCutoffAngle());
67 Attorney::SceneNodeLightComponent::setBounds(sgn->getNode(), bb);
70F32 SpotLightComponent::outerConeRadius() const noexcept {
71 return range() * std::tan(Angle::DegreesToRadians(outerConeCutoffAngle()));
74F32 SpotLightComponent::innerConeRadius() const noexcept {
75 return range() * std::tan(Angle::DegreesToRadians(coneCutoffAngle()));
78F32 SpotLightComponent::coneSlantHeight() const noexcept {
80 const F32 coneHeight = range();
86 SGNComponent::OnData(data);
91 const SceneGraphNode::Flags flag =
static_cast<SceneGraphNode::Flags
>(data.
_flag);
92 if (flag == SceneGraphNode::Flags::SELECTED) {
98void SpotLightComponent::setDirection(
const vec3<F32>& direction)
const {
99 TransformComponent* tComp = _parentSGN->get<TransformComponent>();
100 if (tComp !=
nullptr) {
101 tComp->setDirection(direction);
Handle console commands that start with a forward slash.
constexpr T SQUARED(T input) noexcept
constexpr F32 EPSILON_F32
SGNComponent::Registrar< T, C > BaseComponentType
LightType
The different types of lights supported.
void setDirection(const vec3< F32 > &direction)
F32 outerConeRadius() const noexcept