我有一个 txt 文件,其中的数据是顶部旋转的质心位置的时间函数(在 3D 中)。所以我想用一个圆锥体来表示这个顶部,我拥有的数据应该代表圆锥体基础的中心,及时围绕顶点旋转。
我有一个代表圆锥体的代码,我设法解决了如何围绕底座旋转它。但是我没有设法围绕它的 Vertex 旋转它。我也不知道如何用我的数据移动圆锥。
#include <GL\glut.h>
GLfloat xRotated, yRotated, zRotated;
// Cone
GLdouble base=1;
GLdouble height=1.5;
GLint slices =50;
GLint stacks =50;
void displayCone(void)
{
glMatrixMode(GL_MODELVIEW);
// clear the drawing buffer.
glClear(GL_COLOR_BUFFER_BIT);
// clear the identity matrix.
glLoadIdentity();
// traslate the draw by z = -4.0
// Note this when you decrease z like -8.0 the drawing will looks far , or smaller.
glTranslatef(0.0,0.0,-4.5);
// Red color used to draw.
glColor3f(0.8, 0.2, 0.1);
// changing in transformation matrix.
// rotation about X axis
glRotatef(xRotated,1.0,0.0,0.0);
// rotation about Y axis
glRotatef(yRotated,0.0,1.0,0.0);
// rotation about Z axis
glRotatef(zRotated,0.0,0.0,1.0);
// scaling transfomation
glScalef(1.0,1.0,1.0);
// built-in (glut library) function , draw you a Cone.
glutSolidCone(base,height,slices,stacks);
// Flush buffers to screen
glFlush();
// sawp buffers called because we are using double buffering
// glutSwapBuffers();
}
void idleCone(void)
{
xRotated += 0.1;
yRotated += 0.1;
zRotated += 0.1;
displayCone();
}
int main (int argc, char **argv)
{
//Initialize GLUT
glutInit(&argc, argv);
//double buffering used to avoid flickering problem in animation
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
// window size
glutInitWindowSize(400,350);
// create the window
glutCreateWindow("Cone Rotating Animation");
glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
xRotated = yRotated = zRotated = 30.0;
xRotated=33;
yRotated=40;
glClearColor(0.0,0.0,0.0,0.0);
//Assign the function used in events
glutDisplayFunc(displayCone);
glutReshapeFunc(reshapeCone);
glutIdleFunc(idleCone);
//Let start glut loop
glutMainLoop();
return 0;
}
我已经设法用 Gnuplot 表示质心在 3D 中移动,但是用 OpenGL 旋转的圆锥体来做会更漂亮