PDA

View Full Version : Benzier curves rendering WAY too fast

xerid
07-27-2002, 02:17 AM
This is the code... I try slowing everything down by reducing "t" to very small about, increasing # of points to ten of thousands, and adding a sleep function (jumpy, luck). but it's too fast.... any ideas.

#define MAX_PARTS 10000

_my_particle_type myparticles[MAX_PARTS];

void init_part(int i)
{
/* cN are control points c0 = start, c2 = end , etc... */
myparticles[i].c0.x = myparticles[i].c0.y = myparticles[i].c0.z = 0.0;

/* Random x,z with a radius of 5.00 */
myparticles[i].c2.x = (float)(random() % 20) / 10.0 + 0.1;
myparticles[i].c2.z = (float)(random() % 20) / 10.0 + 0.1;

if((random() % 2)) myparticles[i].c2.x = (-1.0 * myparticles[i].c2.x);
if((random() % 2)) myparticles[i].c2.z = (-1.0 * myparticles[i].c2.z);

/* and on the same y-plane */
myparticles[i].c2.y = 0.0;

/* Let the 2nd control point be mid-point of c0, c2 */
myparticles[i].c1.x = ((myparticles[i].c2.x - myparticles[i].c0.x) / 2.0) + myparticles[i].c0.x;
myparticles[i].c1.z = ((myparticles[i].c2.z - myparticles[i].c0.z) / 2.0) + myparticles[i].c0.z;

/* but set the height at a minimum 0.2 */
myparticles[i].c1.y = ((float)(random() % 40) / 10.0) + 0.5; /* Don't want the Y to be too low, so +0.2 sets a minimum height */

/* Random speed along curve. Minimum 0.01, max 0.02 */
myparticles[i].t = 0.00000000001; /*(((float)(random() % 10)) / 1000000.0) + 0.000001;*/

/* Same with colors, but we want Red to be the dominate color */
}

void init_all_parts(){
int i;
for(i = 0; i < MAX_PARTS ; i++) init_part(i);
}

void init_mman (ModeInfo *mi){
.....

init_all_parts();

}

void set_p(int i){
GLfloat t2 = myparticles[i].t * myparticles[i].t;
GLfloat _2tmomt = 2 * (myparticles[i].t) * (1.0 - myparticles[i].t);

/* The formula for a Benzier curve with 3 control points is:
* p.x = (c0.x)(1.0 - t)^2 + 2(c1.x)(t)(1.0 - t) + (c2.x)(t)^2;
* p.y = (c0.y)(1.0 - t)^2 + 2(c1.y)(t)(1.0 - t) + (c2.y)(t)^2;
* p.z = (c0.z)(1.0 - t)^2 + 2(c1.z)(t)(1.0 - t) + (c2.z)(t)^2;
*
* but since c0 is at the 0,0,0 origin, we just eliminate it from the
* equations below since it will always equal 0. All recompute ****
* to speed things up a bit so they are not repeat 3 times.
*/

myparticles[i].p.x = myparticles[i].c1.x * _2tmomt + myparticles[i].c2.x * t2;
myparticles[i].p.y = myparticles[i].c1.y * _2tmomt + myparticles[i].c2.y * t2;
myparticles[i].p.z = myparticles[i].c1.z * _2tmomt + myparticles[i].c2.z * t2;
}

void draw_parts(){
int i;
for(i=0;i<MAX_PARTS;i++){

if(myparticles[i].t > 1.0) myparticles[i].t = 1.0;

if((myparticles[i].t == 1.0)) init_part(i);

set_p(i);

glBegin(GL_POINTS);
glVertex3f(myparticles[i].p.x, myparticles[i].p.y, myparticles[i].p.z);
glEnd();
myparticles[i].t += myparticles[i].t;
}
}

void main_drap_loop (ModeInfo *mi){
...
draw_parts();
...
}

Don't Disturb
07-27-2002, 07:05 AM
Why is rendering quickly a problem?

xerid
07-27-2002, 10:35 AM
Originally posted by Don't Disturb:
Why is rendering quickly a problem?

Because I can't see the motion of the particle as it moves along the curve.

xerid
07-27-2002, 10:58 AM
Ok, I figured it out...
I changed the following line...

init (){
myparticles[i].step += myparticles[i].t;
}

draw(){
.....
myparticles[i].t += myparticles[i].step;
}

I was adding t to itself, which was accelerating the particles to blinding speeds...

richardve
07-28-2002, 03:39 AM