opengl - opngl中的“旋转算法”不起作用
问题描述
我正在 opngl 中尝试“旋转算法”,但它不起作用我在运行程序时得到一个空白页。我应该放 POINT* verts 还是 Point verts[6] 我的代码有问题吗?
void rotate(POINT* verts, GLint nverts, POINT fixedv, GLdouble theta) {
POINT newverts[6]; //POINT fixedv
GLint k;
for (k = 0; k < nverts; k++) {
newverts[k].x = fixedv.x + (verts[k].x - fixedv.x) * cos(theta) - (verts[k].y - fixedv.y) * sin(theta);
newverts[k].y = fixedv.y + (verts[k].x - fixedv.x) * sin(theta) + (verts[k].y - fixedv.y) * cos(theta);
newverts[k].x = (verts[k].x) * cos(theta) - (verts[k].y) * sin(theta);
newverts[k].y = (verts[k].x) * sin(theta) + (verts[k].y) * cos(theta);
}
glBegin(GL_TRIANGLE_FAN);
for (k = 0; k < nverts; k++)
glVertex2f(newverts[k].x, newverts[k].y);
glEnd();
glFlush();
}
显示代码:
void display() {
glColor3f(r, g, b);
if (check == 3) {
double theta = 3.14 * 0.5;
POINT verts[6],fixedpivot;
fixedpivot.x = x;
fixedpivot.y = y;
verts[0].x = x + 25;
verts[0].y = y + 50;
verts[1].x = x;
verts[1].y = y;
verts[2].x = x+50;
verts[2].y = y;
verts[3].x = x + 25;
verts[3].y = y + 50;
verts[4].x = x + 50;
verts[4].y = y + 100;
verts[5].x = x;
verts[5].y = y + 100;
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(r, g, b);
rotate(verts, 6, fixedpivot, theta);
glFlush();
解决方案
推荐阅读
- angular - 在 app.module.ts 中添加导入 BrowserAnimation 模块时,UI 加载奇怪
- vb.net - 在 VB.NET 中从 dotx 文件生成 pdf 文件
- python - 如何保存 .qcut() 的间隔?
- arrays - 如何在 React 中遍历 JSON 数组并根据 API 响应值显示特定信息?
- c# - 来自 IConfigurationSection 集合的 AutoMapper 映射
- php - Wordpress:如何在标签或类别描述中允许 PHP?
- android - 是否可以在 android 的 infoWindow 中添加操作?
- algorithm - 生成括号问题的闭包数法
- hazelcast - 受控分区和 MapStore
- php - 无法通过 composer 和 flex 安装 symfony/console:3.2