所以我有这个图形管道的代码,但由于某种原因我遇到了错误。
#include <GL/glut.h>
#include <stdio.h>
#include <unistd.h>
#define UpperBD 3
#define Xe 200
#define Ye 200
#define Ze 200
#define Rho sqrt(sq(Xe) + sq(Ye) + sq(Ze))
#define PI 3.1415926
#define D_focal 20
typedef struct {
float X[] = {};
float Y[] = {};
float Z[] = {};
} pworld;
typedef struct {
float X[] = {};
float Y[] = {};
float Z[] = {};
} pviewer;
typedef struct{
float X[] = {};
float Y[] = {};
} pperspective;
void mydisplay()
{
float p1x = 0.0f, p1y = 1.0f; //the window coordinates (-1.0, 1.0)
float p2x = 0.0f, p2y = -1.0f;
float p3x = 1.0f, p3y = 0.0f;
float p4x = -1.0f, p4y = 0.0f;
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
/* Line starts */
glBegin(GL_LINES);
glVertex2f(p1x, p1y);
glVertex2f(p2x, p2y);
glVertex2f(p3x, p3y);
glVertex2f(p4x, p4y);
glEnd();
/* Line Ends */
// #define Pheta = PI/4.0;
// #define Phi =
/* World to viewer */
pworld world[3];
pviewer viewer[3];
pperspective perspective[3];
float sPheta = Ye / sqrt(sq(Xe) + sq(Ye));
float cPheta = Xe / sqrt(sq(Xe) + sq(Ye));
float sPhi = sqrt(sq(Xe) + sq(Ye)) / Rho;
float cPhi = Ze / Rho;
for(int i = 0; i <= UpperBD; i++)
{
viewer[i].X = -sPheta * world[i].X; + cPheta * world[i].y;
viewer[i].Y = -cPheta * cPhi * world[i].X
- cPhi * sPheta * world[i].Y
+ sPhi * world[i].Z;
viewer[i].Z = -sPhi * cPheta * world[i].X
- sPhi * cPheta * world[i].Y
-cPheta * world[i].Z + Rho;
perspective[i].X = (D_focal / viewer[i].Z) * viewer[i].X;
perspective[i].Y = (D_focal / viewer[i].Z) * viewer[i].Y;
cout << perspective[i].X << endl;
cout << perspective[i].Y << endl;
}
glFlush();
usleep(50);
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutCreateWindow("William");
glutDisplayFunc(mydisplay);
glutMainLoop();
}
错误发生在viewer[i].X = -sPheta * world[i].X; + cPheta * world[i].y;
处,以及for
循环中它下面的行。我不确定发生了什么。 我正在尝试将float
乘以float[]
,但它不起作用。
typedef struct {
float X[] = {};
float Y[] = {};
float Z[] = {};
} pworld;
它的结构由 3 个零元素(空(C 数组组成。-sPheta * world[i].X;
将浮点数(数字(与空数组相乘 - 您想实现什么?我想你不需要这些[]。
但是,我认为禁止零元素 C 数组,但它编译得很好。