Grass: Brush

wk6grassscreenshot_1.png
A small step towards realistic grass in openGL and C. Grass responds to “petting” via mouse control.

//grass
# define nBlades 30000

int randomX[nBlades];
int randomY[nBlades];
int randomHeight[nBlades];
float randomWindVelocity[nBlades];
float t[nBlades];
float distance[nBlades];
float angle[nBlades];
float sway[nBlades];
float	pmouseX=0;
float	pmouseY=0;
void drawBlade2(float x, float y, int i){
	angle[i]=atan2(mouseX-x,mouseY-y); //angle to mouse
	distance[i]=dist(x,y,mouseX,mouseY); //distance to mouse
	float tilt=sin(radians(t[i]))*randomHeight[i]/5;//sway distance
		Vec2d mouse=Vec2d(mouseX,mouseY);
		Vec2d A=Vec2d(x,y);//grass root
			Vec2d B=Vec2d(x*3,y*3+randomHeight[i]*.1);//first control point 
				Vec2d C=Vec2d(x*3,y*3+randomHeight[i]*.7);
				Vec2d D=Vec2d(x+tilt,y+randomHeight[i]);//grass tip
					
					float brushSize=dist(pmouseX,pmouseY,mouseX,mouseY);
					

					if( distance[i].01|| t[i]