コード例 #1
0
//Finds a point between between the two distances to point p
Vec Cone::getRandomPoint(const Vec &p, double radius1, double radius2) const{
	fixRadius(radius1,radius2);

	double rad = radius();

	Vec point;
	double rv_choose = GLOBAL_mtrand.rand() * (SA_end + SA_cone);
	double x;
	double y;
	double num_try = 0;
	do{
		do{
			x = GLOBAL_mtrand.rand() * 2 * rad - rad;
			y = GLOBAL_mtrand.rand() * 2 * rad - rad;	
		}while(x * x + y * y > rad * rad);
		Vec xy_point = Vec(x,y,0);
		point = rotationMatrix * xy_point + origin;
		if(rv_choose <= SA_end){
			point += dir * height;
		}else{
			double r = (point - origin).Length();
			point += dir * height * r / rad ;
		}
		num_try++;
	}while(((point - p).Length() > radius1 || (point - p).Length() < radius2) && num_try < MAX_RANDOM_TRIES);

	if(x >= MAX_RANDOM_TRIES){
		return getRandomPoint(p,radius1);
	}

	return point;
}
コード例 #2
0
void InteractiveCamera::changeRadius(float m){
	radius += radius * m; // Change proportional to current radius. Assuming radius isn't allowed to go to zero.
	fixRadius();
}