Files
Vivid2DRenderer/Vivid2DRenderer/model/util/LightSource.h
tzdwindows 7 f4e10bcccc feat(animation): implement animation clip and layer systems
- Added AnimationClip class with curve and keyframe management
- Implemented AnimationCurve with multiple interpolation types
- Created AnimationEventMarker for timeline events
- Added AnimationLayer with track and clip playback support
- Implemented blending modes for animation mixing
- Added event system with listeners and triggers
- Included utility functions for time/frame conversion
- Added copy and merge functionality for clips
- Implemented loop and playback control mechanisms
- Added metadata support including author and description
- Included UUID generation for unique identification
- Added frame rate and duration management
- Implemented parameter override system
- Added physics system integration support
2025-11-15 16:24:52 +08:00

63 lines
2.0 KiB
C++

#pragma once
#ifndef LIGHTSOURCE_H
#define LIGHTSOURCE_H
#include <glm/glm.hpp>
#include <glm/vec2.hpp>
#include <glm/vec3.hpp>
namespace Vivid2D::util {
struct VIVID_2D_MYDLL_API Color {
int r, g, b;
Color() : r(255), g(255), b(255) {}
Color(int red, int green, int blue) : r(red), g(green), b(blue) {}
};
/**
* 光源系统
*/
class VIVID_2D_MYDLL_API LightSource {
public:
// 构造函数:点光源/常规光源
LightSource(const glm::vec2& pos, const Color& color, float intensity);
// 构造函数:环境光
LightSource(const Color& color, float intensity);
// 静态工具函数:将 Color 转换为 glm::vec3 (归一化到 0.0-1.0)
static glm::vec3 colorToVector3f(const Color& color);
// 静态工具函数:将 glm::vec3 (0.0-1.0) 转换为 Color (0-255)
static Color vector3fToColor(const glm::vec3& colorVec);
// Getter 方法
const glm::vec2& getPosition() const { return position; }
const glm::vec3& getColor() const { return color; }
float getIntensity() const { return intensity; }
bool isEnabled() const { return enabled; }
bool isAmbient() const { return m_isAmbient; }
// Setter 方法
void setEnabled(bool enabled) { this->enabled = enabled; }
void setAmbient(bool ambient) { this->m_isAmbient = ambient; }
bool operator==(const LightSource& other) const {
return position == other.position &&
color == other.color &&
intensity == other.intensity &&
enabled == other.enabled &&
m_isAmbient == other.m_isAmbient;
}
private:
glm::vec2 position; // 光源位置
glm::vec3 color; // 光源颜色 (RGB, 0.0 - 1.0)
float intensity; // 光源强度
bool enabled = true;
bool m_isAmbient = false; // 是否为环境光
};
} // namespace Vivid2D
#endif // LIGHTSOURCE_H