Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: animation not working correctly

  1. #1
    Junior Member Newbie
    Join Date
    Apr 2013
    Posts
    23

    animation not working correctly

    it is a very simple code in which length of lines is changed by comparing with a data in vector. Here is the code:


    using namespace std;
    ifstream fin("testanim.txt");

    double x,y,z;

    struct point
    {
    double x,y,z;
    };

    vector<point> temp;



    void ReadTp(int)
    {
    if(!fin.eof())
    {

    double x,y,z;
    fin>>x>>y>>z;
    point hold={x,y,z};
    temp.push_back(hold);
    }


    glClear(GL_COLOR_BUFFER_BIT);
    glutTimerFunc(100, ReadTp,1);
    glutPostRedisplay();

    }

    void reshape (int w, int h)
    {
    glViewport (0, 0, (GLsizei) w, (GLsizei) h);
    glMatrixMode (GL_PROJECTION);
    glLoadIdentity ();
    glOrtho(-35,35,-35,35,-20,20);

    }

    void display()
    {

    glClear(GL_COLOR_BUFFER_BIT);
    glColor3f(1,0,0);
    glMatrixMode (GL_MODELVIEW);
    glLoadIdentity();
    glRotatef(-90, 1.0f, 0.0f, 0.0f);
    glRotatef(xrot, 1.0f, 0.0f, 0.0f);
    glRotatef(yrot, 0.0f, 1.0f, 0.0f);

    double tt=10;
    glBegin(GL_LINES);

    for(float i=0;i<20;i=i+1)
    {

    tt=12;
    for(int k=0;k<temp.size();k++)
    {

    if(i==temp[k].x)
    {
    tt=temp[k].z;
    }

    }
    glVertex3f(i,0,0);
    glVertex3f(i,0,tt);
    }


    glEnd();
    glutSwapBuffers();

    }


    void initialize(int argc, char* argv[])
    {
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
    glutInitWindowSize(500,500);
    glutInitWindowPosition(100,101);
    glutCreateWindow("try");
    glClearColor(1,1,1,0.3);
    glutDisplayFunc(display);
    glutTimerFunc(0,ReadTp,1);

    glutReshapeFunc(reshape);
    glutMainLoop();

    }
    void main(int argc, char* argv[])
    {
    double j,k,l;

    for(int i=0;i<100;i++)
    {
    fin>>j>>k>>l;
    point tempo={j,k,l};
    temp.push_back(tempo);
    }
    initialize(argc,argv);
    }

    But the height of some of the first lines does not change by animation(i.e. one by one) but displays instantly. and the next lines change length one by one giving a animation

    I am using glut in vc++ 2010.

    The file testanim has the following data:
    0 0 9
    1 0 8
    2 0 7
    3 0 6
    4 0 5
    5 0 4
    6 0 5
    7 0 6
    8 0 7
    9 0 8
    10 0 9
    11 0 8
    12 0 7
    13 0 6
    14 0 5
    15 0 4
    16 0 5
    17 0 6
    18 0 7
    19 0 8
    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	1.jpg 
Views:	84 
Size:	13.4 KB 
ID:	1067  

  2. #2
    Junior Member Newbie
    Join Date
    Apr 2013
    Posts
    23
    [QUOTE=qawded;1252518]it is a very simple code in which length of lines is changed by comparing with a data in vector. Here is the code:


    SOMEONE PLEASE HELP.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •