- 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
66 lines
2.0 KiB
C++
66 lines
2.0 KiB
C++
#include "pch.h"
|
|
|
|
#include "LightSource.h"
|
|
#include <algorithm>
|
|
#include <cmath>
|
|
|
|
namespace Vivid2D::util {
|
|
|
|
// -------------------
|
|
// 构造函数实现
|
|
// -------------------
|
|
|
|
// 构造函数:点光源/常规光源
|
|
LightSource::LightSource(const glm::vec2& pos, const Color& color, float intensity)
|
|
: position(pos),
|
|
color(colorToVector3f(color)),
|
|
intensity(intensity),
|
|
m_isAmbient(false) {
|
|
}
|
|
|
|
// 构造函数:环境光
|
|
LightSource::LightSource(const Color& color, float intensity)
|
|
: position(glm::vec2(0.0f, 0.0f)), // 环境光位置通常不重要,设为 (0,0)
|
|
color(colorToVector3f(color)),
|
|
intensity(intensity),
|
|
m_isAmbient(true) {
|
|
}
|
|
|
|
// -------------------
|
|
// 静态工具函数实现
|
|
// -------------------
|
|
|
|
/**
|
|
* 静态工具函数:将 Color 转换为 glm::vec3 (归一化到 0.0-1.0)
|
|
*/
|
|
glm::vec3 LightSource::colorToVector3f(const Color& color) {
|
|
return glm::vec3(
|
|
(float)color.r / 255.0f,
|
|
(float)color.g / 255.0f,
|
|
(float)color.b / 255.0f
|
|
);
|
|
}
|
|
|
|
/**
|
|
* 静态工具函数:将 glm::vec3 (0.0-1.0) 转换为 Color (0-255)
|
|
*/
|
|
Color LightSource::vector3fToColor(const glm::vec3& colorVec) {
|
|
// 确保值在 [0.0, 1.0] 范围内
|
|
float r = std::min(1.0f, std::max(0.0f, colorVec.x));
|
|
float g = std::min(1.0f, std::max(0.0f, colorVec.y));
|
|
float b = std::min(1.0f, std::max(0.0f, colorVec.z));
|
|
|
|
// 转换为 0-255 整数,使用四舍五入
|
|
int red = (int)(r * 255.0f + 0.5f);
|
|
int green = (int)(g * 255.0f + 0.5f);
|
|
int blue = (int)(b * 255.0f + 0.5f);
|
|
|
|
// 确保结果在 [0, 255] 范围内
|
|
red = std::min(255, std::max(0, red));
|
|
green = std::min(255, std::max(0, green));
|
|
blue = std::min(255, std::max(0, blue));
|
|
|
|
return Color(red, green, blue);
|
|
}
|
|
|
|
} // namespace Vivid2D
|