实现核心渲染功能,包括着色器管理、批处理系统、相机控制和纹理加载 - 添加着色器管理器用于加载和管理GLSL着色器程序 - 实现批处理系统优化绘制调用 - 添加相机控制支持视图和投影矩阵 - 实现纹理加载和管理功能 - 添加基础2D渲染API包括绘制四边形和精灵 - 集成到应用系统中,支持自动初始化和清理 - 添加示例着色器用于彩色四边形和纹理精灵 - 更新构建系统包含新的渲染相关文件
46 lines
1.2 KiB
C++
46 lines
1.2 KiB
C++
#include <frostbite2D/graphics/camera.h>
|
|
#include <glm/gtc/matrix_transform.hpp>
|
|
|
|
namespace frostbite2D {
|
|
|
|
Camera::Camera() : position_(0, 0), zoom_(1.0f) {}
|
|
|
|
void Camera::setPosition(const Vec2 &pos) { position_ = pos; }
|
|
|
|
void Camera::setZoom(float zoom) { zoom_ = zoom; }
|
|
|
|
void Camera::setViewport(int width, int height) {
|
|
viewportWidth_ = width;
|
|
viewportHeight_ = height;
|
|
}
|
|
|
|
void Camera::lookAt(const Vec2 &target) { position_ = target; }
|
|
|
|
void Camera::move(const Vec2 &delta) { position_ = position_ + delta; }
|
|
|
|
void Camera::zoomAt(float factor, const Vec2 &screenPos) {
|
|
Vec2 worldBefore = screenPos - position_;
|
|
zoom_ *= factor;
|
|
Vec2 worldAfter = screenPos - position_;
|
|
position_ = position_ + (worldBefore - worldAfter);
|
|
}
|
|
|
|
glm::mat4 Camera::getViewMatrix() const {
|
|
glm::mat4 view = glm::mat4(1.0f);
|
|
view[3][0] = -position_.x;
|
|
view[3][1] = -position_.y;
|
|
view[0][0] = zoom_;
|
|
view[1][1] = zoom_;
|
|
return view;
|
|
}
|
|
|
|
glm::mat4 Camera::getProjectionMatrix() const {
|
|
float left = 0.0f;
|
|
float right = static_cast<float>(viewportWidth_);
|
|
float bottom = static_cast<float>(viewportHeight_);
|
|
float top = 0.0f;
|
|
|
|
return glm::ortho(left, right, bottom, top, -1.0f, 1.0f);
|
|
}
|
|
|
|
} // namespace frostbite2D
|