Пример #1
0
//----------------------------------------------------
bool guiQuad::selectPoint(float x, float y, float offsetX, float offsetY, float width, float height, float hitArea){

	//make sure selected is -1 unless we really find a point			
	selected = -1;

	if(width == 0 || height == 0 || x < offsetX || x > offsetX + width || y < offsetY ||  y > offsetY + height){
		//then we are out of our possible quad area
		//so we ignore :)
		return false;
	}  
	
	//lets get it in range x(0 - width) y(0 - height)
	float px = x - offsetX;
	float py = y - offsetY;
	
	//now get in 0-1 range
	px /= width;
	py /= height;
	
	hitArea /= width;
	
	//we want to store the smallest distance found
	//because in the case when two points are in the 
	//hit area we want to pick the closet
	float storeDist = 9999999.0;
	
	for(int i = 0; i < 4; i++){
		float dx = floatAbs(px -  srcZeroToOne[i].x);
		float dy = floatAbs(py -  srcZeroToOne[i].y);
		
		float dist = sqrt(dx*dx + dy*dy);
		
		if(dist > hitArea)continue;
		
		if(dist < storeDist){
			selected = i;
			storeDist = dist;
		}
	}

	if(selected != -1){
		srcZeroToOne[selected].x 	= px;
		srcZeroToOne[selected].y 	= py;	
		srcScaled[selected].x		= px;
		srcScaled[selected].y		= py;					
	
		if(selected == 0)setCommonText("status: Quad - Top Left");
		else
		if(selected == 1)setCommonText("status: Quad - Top Right");
		else
		if(selected == 2)setCommonText("status: Quad - Bottom Right");
		else 
		if(selected == 3)setCommonText("status: Quad - Bottom Left");
		
		return true;
	}
	
	return false;
}
Пример #2
0
//-----------------------------------	
bool drip::update(){
				
	if(!isDripping())return false;
				
	//lets figure out how far we will have travelled
	distance += floatAbs(vel.x) + floatAbs(vel.y);
	
	//only update pos if doing so would keep us
	//under the dripLength - otherwise we could
	//go outside of the image dimensions
	
	//printf("dist is %f - length is %i \n", distance, dripLength);
	
	if(distance >= dripLength){
		stopDripping();
		return false;
	}else{
		
		//lets see if we have moved less than 1 pixel
		float preDist = floatAbs( (pre - pos).length() );
		
		//if(preDist > 1){
			//update our previous point
			pre = pos;
		//}
		
		//some deceleration 
		if( dripLength - distance < 24) {
			vel.x *= 0.987;
			vel.y *= 0.987;
			
			if( floatAbs(vel.x) < 0.01 && floatAbs(vel.y) < 0.01){
				stopDripping();
				return false;
			}
		}
		
		//update our current point
		pos.x += vel.x;
		pos.y += vel.y;
		
		//printf("pos is %f %f - vel is %f %f \n", pos.x, pos.y, vel.x, vel.y);
						
		//if we have moved less than a pixel
		//then no need to draw 
		//if(preDist < 1){
		//	return false;
		//}
		
	}

	return true;		
}
Пример #3
0
//-----------------------------------	
bool drip::setup(float x, float y, int imageW, int imageH, int _direction, float length, float speed, int dWidth){
				
	//set position
	pos.x = x;
	pos.y = y;
	
	//lets make sure it lies in the image
	if(pos.x < 0)pos.x = 0;
	else if(pos.x >= imageW)pos.x = imageW -1;
	if(pos.y < 0)pos.y = 0;
	else if(pos.y >= imageH)pos.y = imageH -1;
	
	//set pre to be the same as position
	pre = pos;
				
	//make sure we have only 4 directions
	direction = _direction;
	
	if(direction < 0) direction = 0;
	if(direction > 3) direction = 3;
	
	
	//figure out target and 
	//acceleration based on direction
	if(direction == 0){	//south
		dst.x = pos.x;
		dst.y = pos.y + length;
		vel.x = 0;
		vel.y = speed;
	}
	else
	if(direction == 1){	//west
		dst.x = pos.x - length;
		dst.y = pos.y;
		vel.x = -speed;
		vel.y = 0;			}
	else
	if(direction == 2){	//north
		dst.x = pos.x;
		dst.y = pos.y - length;
		vel.x = 0;
		vel.y = -speed;				
	}
	else
	if(direction == 3){	//east
		dst.x = pos.x + length;
		dst.y = pos.y;
		vel.x = speed;
		vel.y = 0;
	}
							
	//now lets check we haven't gone over our image border
	if(dst.x >= imageW){
		dst.x = imageW - 1;
	}
	else if(dst.x < 0){
		dst.x = 0;
	}
	
	if(dst.y >= imageH){
		dst.y = imageH - 1;
	}
	else if(dst.y < 0){
		dst.y = 0;
	}
	
	//recalculate the dripLength
	dripLength = floatAbs(dst.x - pos.x) + floatAbs(dst.y - pos.y);

	//lets not start dripping until specifically told to do so
	dripping	= false;
	
	//store our drip width
	dripWidth = dWidth;
	
	return true;
}