Vec2d* smoothPath(Vec2d * _PointArray, int _numPoints, float _smooth){
Vec2d p;
//p2[0]=_PointArray[0];
for (int i =1; i< _numPoints -1;i++){
p=(_PointArray[i-1]*_smooth/2) + (_PointArray[i]*(1.0 - _smooth)) + (_PointArray[i+1]*_smooth/2);//smooth fraction has to add to 1
p2[i]=p;
}
return p2;
}
void drawPoints(){
float spacing=30;
//printf( "%f %f\n", mouseDX,mouseDY );
Vec2d k = Vec2d(0,0);
Vec2d* smoothPoints;
// if ( mouseDX != prevX || mouseDY != prevY ){ //without spacing
if ((mouseDX - spacing >= prevX || mouseDX + spacing <= prevX) || (mouseDY - spacing >= prevY || mouseDY+spacing<= prevY)){
k.x = mouseDX;
k.y = mouseDY;
prevX = k.x;
prevY = k.y;
// printf( "%d\n", pointCounter );
drawLinePoints[pointCounter] = k;
pointCounter++;
// printf( "%f %f\n", mouseDX, mouseDY );
}
///draw regular
glBegin(GL_LINE_STRIP);
glColor3f( 0,0,255 );
for (int i = 1; i < pointCounter; i++){// +1 gets rid of zero zero point
glVertex2f(drawLinePoints[i].x, drawLinePoints[i].y); // puts points along line taake out for line draw
// printf( "%f %f\n", p.x,p.y);
}
glEnd();
//draw smooth
smoothPoints = smoothPath( drawLinePoints, pointCounter, .9);
glBegin(GL_LINE_STRIP);
glColor3f( 255,0,0 );
Vec2d offset(0,100);
for (int i = 1; i < pointCounter-2; i++){// +1 gets rid of zero zero point
Vec2d sv = (Vec2d) smoothPoints[i] ;// move it down
glVertex2f(sv.x, sv.y); // puts points along line taake out for line draw
// printf( "%f %f\n", p.x,p.y);
}
glEnd();
}