我正尝试在我的函数中添加旋转。
我不知道如何在功能中旋转它
void draw_filled_circle(const RenderListPtr& render_list, const Vec2& position, float radius, CircleType type, Color color, float rotate){
float pi;
if (type == FULL) pi = D3DX_PI; // Full circle
if (type == HALF) pi = D3DX_PI / 2; // 1/2 circle
if (type == QUARTER) pi = D3DX_PI / 4; // 1/4 circle
const int segments = 32;
float angle = rotate * D3DX_PI / 180;
Vertex v[segments + 1];
for (int i = 0; i <= segments; i++){
float theta = 2.f * pi * static_cast<float>(i) / static_cast<float>(segments);
v[i] = Vertex{
position.x + radius * std::cos(theta),
position.y + radius * std::sin(theta),
color
};
}
add_vertices(render_list, v, D3DPT_TRIANGLEFAN);
}
答案 0 :(得分:1)
通常,您不会通过直接修改顶点来旋转任何东西。相反,您使用矩阵(模型-视图-投影矩阵)来转换数据。这3种组合矩阵可以归结为:
通常,您将所有3个矩阵合并为一个MVP矩阵,您可以使用该MVP矩阵在一次操作中完成所有3个变换。本文档介绍了一些基本知识:https://docs.microsoft.com/en-us/windows/win32/dxtecharts/the-direct3d-transformation-pipeline
D3DXMATRIX proj_mat; //< set with projection you need
D3DXMATRIX view_mat; //< invert the matrix for the camera position & orientation
D3DXMATRIX model_mat; //< set the rotation here
D3DXMATRIX MVP;
MVP = model_mat * view_mat * proj_mat; //< combine into a single MVP to set on your shader
如果您