1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
#include <iostream>
#include <utility>
float width{ 1920.f };
float height{ 1080.f };
std::pair<float, float> ScreenCoordToNDC(float x, float y) {
const float XTransform = (2.f / width);
const float YTransform = -(2.f / height);
x = x * XTransform - 1.f;
y = y * YTransform + 1.f;
return std::pair{ x,y };
};
std::pair<float, float> NDCToScreenCoord(float x, float y) {
x = x * (width / 2) + (width / 2);
y = y * -(height / 2) + (height / 2);
return std::pair{ x,y };
};
int main() {
for (int i = 0; i <= width; ++i) {
auto [x, y] = ScreenCoordToNDC(i, 0);
std::cout << "Screen pos x : " << i << " width : " << x << std::endl;
std::cout << "Screen pos y : " << 0 << " height : " << y << std::endl;
};
for (int i = 0; i <= height; ++i) {
auto [x, y] = ScreenCoordToNDC(0, i);
std::cout << "Screen pos x : " << 0 << " width : " << x << std::endl;
std::cout << "Screen pos y : " << i << " height : " << y << std::endl;
};
}
|
cs |