View Full Version : what is the use of this function (in need of line to line explaination)

prateek

05-01-2015, 03:09 AM

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;

}

}

IonutCava

05-01-2015, 06:25 AM

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.

prateek

05-04-2015, 01:01 PM

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;

}

Alfonse Reinheart

05-04-2015, 03:19 PM

That didn't change the problem: your code doesn't appear to have anything to do with OpenGL.

prateek

05-04-2015, 08:12 PM

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.

Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.