Files
XCEngine/docs/api/components/light-component/light-component.md
ssdfasd f5a34f8adc docs: 重构 API 文档 - components 和 scene 模块
- components: 修复英文标题为中文,添加缺失组件文档
  - 新增 camera-component, light-component, audio-source-component, audio-listener-component 类总览
  - 修复 get-position.md 格式
  - 更新 components.md 模块总览
- scene: 修复方法文档格式,新增缺失方法
  - 修复 find.md, create-game-object.md 英文标题
  - 新增 FindByID, SerializeToString, DeserializeFromString 方法文档
  - 更新 scene.md 类总览方法列表
2026-03-26 01:50:27 +08:00

2.7 KiB
Raw Blame History

LightComponent

命名空间: XCEngine::Components

类型: class

头文件: XCEngine/Components/LightComponent.h

描述: 光源组件,支持方向光、点光、聚光灯三种类型,可设置颜色、强度和阴影。

概述

LightComponent 是 XCEngine ECS 系统中的光源组件支持三种光源类型方向光Directional、点光Point和聚光灯Spot。方向光从无穷远处照射模拟太阳光点光从一个点向所有方向照射聚光灯沿一个锥形方向照射。光源组件可以设置颜色、强度、作用范围和是否投射阴影。

枚举

LightType

枚举值 描述
Directional 方向光,从无穷远处照射
Point 点光,从一个点向所有方向照射
Spot 聚光灯,沿锥形方向照射

公共方法

光源类型

方法 描述
GetLightType 获取光源类型
SetLightType 设置光源类型

光源属性

方法 描述
GetColor 获取光源颜色
SetColor 设置光源颜色
GetIntensity 获取光源强度
SetIntensity 设置光源强度
GetRange 获取作用范围(点光/聚光灯)
SetRange 设置作用范围

聚光灯属性

方法 描述
GetSpotAngle 获取聚光灯角度
SetSpotAngle 设置聚光灯角度

阴影

方法 描述
GetCastsShadows 检查是否投射阴影
SetCastsShadows 设置是否投射阴影

使用示例

#include <XCEngine/Components/LightComponent.h>
#include <XCEngine/Components/GameObject.h>

using namespace XCEngine::Components;

void SetupLighting(GameObject* lightObject) {
    auto light = lightObject->AddComponent<LightComponent>();
    
    light->SetLightType(LightType::Directional);
    light->SetColor(Math::Color::White());
    light->SetIntensity(1.0f);
    light->SetCastsShadows(true);
}

void SetupPointLight(GameObject* pointLightObject) {
    auto pointLight = pointLightObject->AddComponent<LightComponent>();
    
    pointLight->SetLightType(LightType::Point);
    pointLight->SetColor(Math::Color(1.0f, 0.8f, 0.6f, 1.0f));
    pointLight->SetIntensity(2.0f);
    pointLight->SetRange(10.0f);
}

相关文档