载入中...
搜索中...
未找到
CameraPixel.h
浏览该文件的文档.
1#pragma once
2
3#include <algorithm>
4#include <cmath>
5
6namespace eve::graphics {
7
17 int scale = 1;
18 float orthoHeight = 1.f;
19 float zoom2D = 1.f;
20 float worldPerPixel = 1.f;
21};
22
31inline PixelPerfectScale computePixelPerfectScale(float pixelsPerUnit, int refWidth, int refHeight, int viewWidth,
32 int viewHeight) {
34 const float ppu = std::max(1e-4f, pixelsPerUnit);
35 if (refWidth > 0 && refHeight > 0 && viewWidth > 0 && viewHeight > 0) {
36 out.scale = std::max(1, std::min(viewWidth / refWidth, viewHeight / refHeight));
37 out.orthoHeight = float(refHeight) / ppu;
38 out.zoom2D = float(out.scale) * ppu;
39 } else if (viewHeight > 0) {
40 out.scale = 1;
41 out.orthoHeight = float(viewHeight) / ppu;
42 out.zoom2D = ppu;
43 } else {
44 out.scale = 1;
45 out.orthoHeight = 1.f / ppu;
46 out.zoom2D = ppu;
47 }
48 out.worldPerPixel = 1.f / (ppu * float(out.scale));
49 return out;
50}
51
53inline float snapWorldToPixel(float world, float zoom) {
54 const float z = zoom <= 0.f ? 1e-4f : zoom;
55 return std::round(world * z) / z;
56}
57
58} // namespace eve::graphics
double z
float zoom
ScriptStructure out
卡牌游戏 UI 工具模块:工厂 + 脚本绑定入口。 功能参考 ycarowr/UiCard:扇形手牌布局、抽牌/洗牌、悬浮放大、拖拽到落牌区、 敌方手牌(背面/偷看)、费用不足置灰,以及可实时调节的布局...
Definition Animation.h:25
float snapWorldToPixel(float world, float zoom)
Snap a world coordinate onto the pixel grid for the given zoom.
Definition CameraPixel.h:53
PixelPerfectScale computePixelPerfectScale(float pixelsPerUnit, int refWidth, int refHeight, int viewWidth, int viewHeight)
Compute integer scale and projection spans for a perfect-pixel camera.
Definition CameraPixel.h:31
Shared sizing for perfect-pixel orthographic / 2D cameras.
Definition CameraPixel.h:16