2차원 transformation
2023. 2. 22. 19:32ㆍ컴퓨터 그래픽스/그래픽 알고리즘 및 표현
2차원 transformation에서는 해볼 것은 3가지 변환이다.
1. rotation
2. translation
3. scale
rotation
회전변환으로 원점을 중심으로 회전하는 것을 나타낸다. 2차원에서는 점을 중심으로 회전을 하고 3차원에서는 축을 중심으로 회전을 하게 된다.
translation
좌표 이동이고 덧셈으로 나타낸다.
vertex.x + translation, vertex.y + translation ...
scale
크기 변환으로 곱셈으로 크기를 변경해준다.
vertex.x * xScale, vertex.y * yScale ...
처음 변환을 하려면 vertex들을 가져오고 rotation을 할때는 어느 각도로 rotation을 할지 넘겨준 뒤 변환한 것을 return하면 된다.
중첩되게 변환을 하려면 return한 것을 또 가져와서 scale이나 translation 계산을 해주면 된다. 그리고 완전히 다 변환한 것을 buffer에 넘겨준다.
for (size_t i = 0; i < circle.vertices.size(); i++) {
auto temp = Rotation(circle.vertices[i], this->rotation1);
temp = temp * vec3(scaleX, scaleY, 1.0f);
temp = temp + this->translation1;
temp = Rotation(temp, this->rotation2);
temp = temp + this->translation2;
this->vertexBuffer[i] = temp;
}
행렬 계산은 곱하거나 더했을 때 간단히 한 개의 행렬로 다 나타낼 수 있다.
'컴퓨터 그래픽스 > 그래픽 알고리즘 및 표현' 카테고리의 다른 글
backface culling, 원근법 (0) | 2023.05.03 |
---|---|
깊이 버퍼(depth buffer) (0) | 2023.04.01 |
Rasterization 원 그리기 (0) | 2023.02.22 |
Rasterization (0) | 2023.02.15 |
perspective 원근표현 (0) | 2023.02.09 |