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 5 of 5

Thread: what is the use of this function (in need of line to line explaination)

  1. #1
    Junior Member Newbie
    Join Date
    Apr 2015
    Location
    India
    Posts
    8

    Post what is the use of this function (in need of line to line explaination)

    void add_UFO(void)
    {
    int i;
    for (i = 0; i < MAX_UFO; i++)
    if (UFO[i].speed == 0)
    {

    UFO[i].speed = ((float) (random() % 20)) * 0.0001 + 0.02;
    if (random() & 0x1)
    UFO[i].speed *= -1;
    UFO[i].theta = ((float) (random() % 257)) * 0.1111;
    tick_per_UFO(i);
    if (!moving)
    glutPostRedisplay(); /*Request redisplay*/
    return;
    }
    }

  2. #2
    Junior Member Newbie IonutCava's Avatar
    Join Date
    May 2012
    Location
    Bristol, U.K.
    Posts
    27
    A line by line explanation will not be of any use to you if you can't understand that basic chunk of code. I assume you're just starting out with programing and lack OOP concepts. It has nothing to do with the subforum, anyway: (i.e. "Discussion about 3D math and linear algebra that is essential as a background to OpenGL coding"). I suggest starting with some programming tutorials/books.

    The only non-standard code part in there is the glutPostRedisplay() line and that already has an explanation about what it does right next to it.

  3. #3
    Junior Member Newbie
    Join Date
    Apr 2015
    Location
    India
    Posts
    8
    sorry!!!
    actually I'm having problem in this below function,by mistake i pasted the above one...

    void tick_per_UFO(int i)
    {
    float theta = UFO[i].theta += UFO[i].speed;
    UFO[i].z = -9 + 4 * cos(theta);
    UFO[i].x = 4 * sin(2 * theta);
    UFO[i].y = sin(theta / 3.4) * 3;
    UFO[i].angle = (((2.0) + M_PI_2) * sin(theta) - M_PI_2) * 180 / M_PI; /*calculates nor of degrees using nor of radians*/
    if (UFO[i].speed < 0.0)
    UFO[i].angle += 180;
    }

  4. #4
    Senior Member OpenGL Lord
    Join Date
    May 2009
    Posts
    5,906
    That didn't change the problem: your code doesn't appear to have anything to do with OpenGL.

  5. #5
    Junior Member Newbie
    Join Date
    Apr 2015
    Location
    India
    Posts
    8
    yes u r rt. sir!!!!But it is part of openGl function which hv written using basic language.only my problem is about those x,y,z axis.

Posting Permissions

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