Beispiel #1
0
WorldModel::WorldModel(int mN , float mMinDis/* , Map mLevelMap*/): maxCord(0.75) , G(9.8) , CUE_MASS(1.0f){
	time = 0;
	dt = 0.0002;
	n = mN;
	minDis2Lines = 0.3;
	minDis = mMinDis;
	COF = 0.2f;
	Random r;
	for(int i = 0 ; i < n ; i++){
		bool isGood = false;
		Vector2Df tmp;
		while(isGood == false){
			tmp = Vector2Df(r.Gauss(0 , 2) , r.Gauss(0 , 2));
			isGood = true;
			if(tmp.x() > maxCord || tmp.y() > maxCord || tmp.x() < -maxCord || tmp.y() < -maxCord)
				isGood = false;
			if(i >= 2)
				for(int j = 0 ; j < i ; j++)
					for(int k = 0 ; k < i ; k++){
						float rate = ((balls[k].pos - balls[j].pos) * (balls[k].pos - tmp)) / 
							((balls[k].pos - balls[j].pos).getLength() * (balls[k].pos - tmp).getLength());
						float thetaByRate = acos(rate);
						if(j > k && sin(thetaByRate) * (balls[k].pos - tmp).getLength() < minDis2Lines)
							isGood = false;
					}
			for(int j = 0 ; j < i ; j++){
				float diss = (tmp - balls[j].pos).getLength();
				if(diss < minDis)
					isGood = false;
			}
		}
		Ball newBall(i , 0.02 , 0.05 , tmp);
		balls.push_back(newBall);
	}
}