私は動いている間にオブジェクトを回転しようとしていますが、移動させたいポイントに沿って回転させることはできません。openglを使ってcで動くオブジェクトを回転させることができません
struct point {
int x;
int y;
};
// A line between two points.
struct line {
struct point start;
struct point end;
};
float j = 100.0;
float rotationAngle = 0.0f; // The angle of rotation for our object
void rotateObjectWithMovement(void functionToDrawObject(), struct point pivot, float rotationAngle) {
glPushMatrix();
glTranslatef(pivot.x, pivot.y, 0.0f);
glRotatef(rotationAngle, 0.0f, 0.0f, 1.0f);
functionToDrawObject();
glPopMatrix();
}
void rotateObjectWithoutMovement(void functionToDrawObject(), struct point pivot, float rotationAngle) {
glPushMatrix();
glTranslatef(pivot.x, pivot.y, 0.0f);
glRotatef(rotationAngle, 0.0f, 0.0f, 1.0f);
glTranslatef(-pivot.x, -pivot.y, 0.0f);
functionToDrawObject();
glPopMatrix();
}
void rocket() {
struct point allPoints[2] = {
{ 100, 100},
{ 150, 150}
};
struct line line1 = {allPoints[0], allPoints[1]};
glColor3f(1.0, 1.0, 0.0);
drawLines(&line1, 1);
}
void display() {
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
struct point pivot={j,100};
rotateObjectWithoutMovement(rocket,pivot,rotationAngle);
//rotateObjectWithMovement(rocket,pivot,rotationAngle);
//reference line
glBegin(GL_LINES);
glVertex2f(0, 100);
glVertex2d(1000, 100);
glEnd();
j += 1;
rotationAngle += 0.5f; // Increment our rotation value
if (rotationAngle > 360.0f) // If we have rotated beyond 360 degrees (a full rotation)
rotationAngle -= 360.0f; // Subtract 360 degrees off of our rotation
glutSwapBuffers(); // Swap our buffers
}
void myinit() {
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, 988.0, 0.0, 999.0);
glClearColor(0.5f, 0.5f, 1, 1);
glMatrixMode(GL_MODELVIEW);
}
int main(int argc, char *argv[]) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE);
glutInitWindowSize(700, 500);
glutInitWindowPosition(100, 100);
glutCreateWindow("OpenGL Hierarchical Modeling 2D Example");
myinit();
glutDisplayFunc(display);
glutIdleFunc(display);
glutMainLoop();
return 0;
}
rotateWithMoment()関数は、オブジェクトを回転させる必要があり、ピボットとしてSTATIS共ordinatsでそれを回転するオブジェクト、静的座標及び角度をとります。
rotateWithoutMovement()関数は、オブジェクトを回転させなければならない座標と角度を変更し、変更する座標をピボットとして回転させます(例:線を回転させるとホイールが回転しているように見えます)。この関数は、ラインを回転させるようになっています。
私はそれを2日間働かせようとしていて、どこが間違っているのか分からない。
送信したオブジェクトを(x、y)点に移動し、指定された角度で回転させようとしています。これを行うには、オブジェクトを回転させて移動させるための関数を受け入れることで、これを行う関数を作成しようとしていました。
rotateWithoutMovementは、一定の座標を送信するとうまくいきます。
"動作しない"を定義してください。 –
'main(...)'関数はどこにありますか? – ryyker
私はC++タグを理解していません。あなたのタイトルには「C」言語があります。彼らは異なる言語です。たとえば、C++には 'std :: vector'と' std :: string'があり、Cではそうではありません。 C言語では、エラーなく変数 "クラス"に名前を付けることができます。 –