Java Code Examples for com.watabou.utils.PointF#distance()

The following examples show how to use com.watabou.utils.PointF#distance() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CellSelector.java    From YetAnotherPixelDungeon with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onTouchDown( Touch t ) {

	if (t != touch && another == null) {
				
		if (!touch.down) {
			touch = t;
			onTouchDown( t );
			return;
		}
		
		pinching = true;
		
		another = t;
		startSpan = PointF.distance( touch.current, another.current );
		startZoom = camera.zoom;

		dragging = false;
	}
}
 
Example 2
Source File: CellSelector.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onDrag( NoosaInputProcessor.Touch t ) {

	if (pinching) {

		float curSpan = PointF.distance( touch.current, another.current );
		float zoom = (startZoom * curSpan / startSpan);
		camera.zoom( GameMath.gate(
				PixelScene.minZoom,
				zoom - (zoom % 0.1f),
				PixelScene.maxZoom ) );

	} else {
	
		if (!dragging && PointF.distance( t.current, t.start ) > dragThreshold) {
			
			dragging = true;
			lastPos.set( t.current );
			
		} else if (dragging) {
			camera.shift( PointF.diff( lastPos, t.current ).invScale( camera.zoom ) );
			lastPos.set( t.current );
		}
	}
	
}
 
Example 3
Source File: CellSelector.java    From unleashed-pixel-dungeon with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onTouchDown( Touch t ) {

	if (t != touch && another == null) {
				
		if (!touch.down) {
			touch = t;
			onTouchDown( t );
			return;
		}
		
		pinching = true;
		
		another = t;
		startSpan = PointF.distance( touch.current, another.current );
		startZoom = camera.zoom;

		dragging = false;
	} else if (t != touch) {
		reset();
	}
}
 
Example 4
Source File: CellSelector.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onTouchDown( NoosaInputProcessor.Touch t ) {

	if (t != touch && another == null) {
				
		if (!touch.down) {
			touch = t;
			onTouchDown( t );
			return;
		}
		
		pinching = true;
		
		another = t;
		startSpan = PointF.distance( touch.current, another.current );
		startZoom = camera.zoom;

		dragging = false;
	} else if (t != touch) {
		reset();
	}
}
 
Example 5
Source File: CellSelector.java    From pixel-dungeon with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onTouchDown( Touch t ) {

	if (t != touch && another == null) {
				
		if (!touch.down) {
			touch = t;
			onTouchDown( t );
			return;
		}
		
		pinching = true;
		
		another = t;
		startSpan = PointF.distance( touch.current, another.current );
		startZoom = camera.zoom;

		dragging = false;
	}
}
 
Example 6
Source File: CellSelector.java    From remixed-dungeon with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onTouchDown( Touch t ) {

	if (t != touch && another == null) {
				
		if (!touch.down) {
			touch = t;
			onTouchDown( t );
			return;
		}
		
		pinching = true;
		
		another = t;
		startSpan = PointF.distance( touch.current, another.current );
		startZoom = camera.zoom;

		dragging = false;
	}
}
 
Example 7
Source File: CellSelector.java    From shattered-pixel-dungeon with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onPointerDown( PointerEvent event ) {

	if (event != curEvent && another == null) {
				
		if (!curEvent.down) {
			curEvent = event;
			onPointerDown( event );
			return;
		}
		
		pinching = true;
		
		another = event;
		startSpan = PointF.distance( curEvent.current, another.current );
		startZoom = camera.zoom;

		dragging = false;
	} else if (event != curEvent) {
		reset();
	}
}
 
Example 8
Source File: CellSelector.java    From shattered-pixel-dungeon with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onDrag( PointerEvent event ) {

	if (pinching) {

		float curSpan = PointF.distance( curEvent.current, another.current );
		float zoom = (startZoom * curSpan / startSpan);
		camera.zoom( GameMath.gate(
			PixelScene.minZoom,
				zoom - (zoom % 0.1f),
			PixelScene.maxZoom ) );

	} else {
	
		if (!dragging && PointF.distance( event.current, event.start ) > dragThreshold) {
			
			dragging = true;
			lastPos.set( event.current );
			
		} else if (dragging) {
			camera.shift( PointF.diff( lastPos, event.current ).invScale( camera.zoom ) );
			lastPos.set( event.current );
		}
	}
	
}
 
Example 9
Source File: ScrollPane.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onDrag( NoosaInputProcessor.Touch t ) {
	if (dragging) {

		doScroll(t.current);

	} else if (PointF.distance( t.current, t.start ) > dragThreshold) {

		dragging = true;
		lastPos.set( t.current );
		thumb.am = 1;

	}
}
 
Example 10
Source File: ScrollPane.java    From remixed-dungeon with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onDrag( Touch t ) {		
	if (dragging) {
		
		Camera c = content.camera;
		
		c.scroll.offset( PointF.diff( lastPos, t.current ).invScale( c.zoom ) );
		if (c.scroll.x + width > content.width()) {
			c.scroll.x = content.width() - width;
		}
		if (c.scroll.x < 0) {
			c.scroll.x = 0;
		}
		if (c.scroll.y + height > content.height()) {
			c.scroll.y = content.height() - height;
		}
		if (c.scroll.y < 0) {
			c.scroll.y = 0;
		}

		lastPos.set( t.current );	
		
	} else if (PointF.distance( t.current, t.start ) > dragThreshold) {
		
		dragging = true;
		lastPos.set( t.current );
	}
}
 
Example 11
Source File: CellSelector.java    From remixed-dungeon with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onDrag( Touch t ) {
	 
	camera.target = null;

	if (pinching) {

		float curSpan = PointF.distance( touch.current, another.current );
		camera.zoom( GameMath.gate( 
			PixelScene.minZoom, 
			startZoom * curSpan / startSpan, 
			PixelScene.maxZoom ) );

	} else {
	
		if (!dragging && PointF.distance( t.current, t.start ) > dragThreshold) {
			
			dragging = true;
			lastPos.set( t.current );
			
		} else if (dragging) {
			camera.scroll.offset( PointF.diff( lastPos, t.current ).invScale( camera.zoom ) );
			lastPos.set( t.current );	
		}	
	}
	
}
 
Example 12
Source File: ScrollPane.java    From shattered-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onDrag( PointerEvent event ) {
	if (dragging) {

		scroll(event.current);

	} else if (PointF.distance( event.current, event.start ) > dragThreshold) {

		dragging = true;
		lastPos.set( event.current );
		thumb.am = 1;

	}
}
 
Example 13
Source File: ScrollPane.java    From pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onDrag( Touch t ) {		
	if (dragging) {
		
		Camera c = content.camera;
		
		c.scroll.offset( PointF.diff( lastPos, t.current ).invScale( c.zoom ) );
		if (c.scroll.x + width > content.width()) {
			c.scroll.x = content.width() - width;
		}
		if (c.scroll.x < 0) {
			c.scroll.x = 0;
		}
		if (c.scroll.y + height > content.height()) {
			c.scroll.y = content.height() - height;
		}
		if (c.scroll.y < 0) {
			c.scroll.y = 0;
		}
		
		thumb.y = y + height * c.scroll.y / content.height();
		
		lastPos.set( t.current );	
		
	} else if (PointF.distance( t.current, t.start ) > dragThreshold) {
		
		dragging = true;
		lastPos.set( t.current );
		thumb.am = 1;
		
	}
}
 
Example 14
Source File: CellSelector.java    From pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onDrag( Touch t ) {
	 
	camera.target = null;

	if (pinching) {

		float curSpan = PointF.distance( touch.current, another.current );
		camera.zoom( GameMath.gate( 
			PixelScene.minZoom, 
			startZoom * curSpan / startSpan, 
			PixelScene.maxZoom ) );

	} else {
	
		if (!dragging && PointF.distance( t.current, t.start ) > dragThreshold) {
			
			dragging = true;
			lastPos.set( t.current );
			
		} else if (dragging) {
			camera.scroll.offset( PointF.diff( lastPos, t.current ).invScale( camera.zoom ) );
			lastPos.set( t.current );	
		}	
	}
	
}
 
Example 15
Source File: ScrollPane.java    From unleashed-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onDrag( Touch t ) {
	if (dragging) {
		
		Camera c = content.camera;
		
		c.scroll.offset( PointF.diff( lastPos, t.current ).invScale( c.zoom ) );
		if (c.scroll.x + width > content.width()) {
			c.scroll.x = content.width() - width;
		}
		if (c.scroll.x < 0) {
			c.scroll.x = 0;
		}
		if (c.scroll.y + height > content.height()) {
			c.scroll.y = content.height() - height;
		}
		if (c.scroll.y < 0) {
			c.scroll.y = 0;
		}
		
		
		lastPos.set( t.current );
		
	} else if (PointF.distance( t.current, t.start ) > dragThreshold) {
		
		dragging = true;
		lastPos.set( t.current );
		
	}
}
 
Example 16
Source File: CellSelector.java    From unleashed-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onDrag( Touch t ) {
	 
	camera.target = null;

	if (pinching) {

		float curSpan = PointF.distance( touch.current, another.current );
		camera.zoom( GameMath.gate(
			PixelScene.minZoom,
			startZoom * curSpan / startSpan,
			PixelScene.maxZoom ) );

	} else {
	
		if (!dragging && PointF.distance( t.current, t.start ) > dragThreshold) {
			
			dragging = true;
			lastPos.set( t.current );
			
		} else if (dragging) {
			camera.scroll.offset( PointF.diff( lastPos, t.current ).invScale( camera.zoom ) );
			lastPos.set( t.current );
		}
	}
	
}
 
Example 17
Source File: ScrollPane.java    From YetAnotherPixelDungeon with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onDrag( Touch t ) {		
	if (dragging) {
		
		Camera c = content.camera;
		
		c.scroll.offset( PointF.diff( lastPos, t.current ).invScale( c.zoom ) );
		if (c.scroll.x + width > content.width()) {
			c.scroll.x = content.width() - width;
		}
		if (c.scroll.x < 0) {
			c.scroll.x = 0;
		}
		if (c.scroll.y + height > content.height()) {
			c.scroll.y = content.height() - height;
		}
		if (c.scroll.y < 0) {
			c.scroll.y = 0;
		}

              indicator.y = y + height * c.scroll.y / content.height();
		
		lastPos.set( t.current );	
		
	} else if (PointF.distance( t.current, t.start ) > dragThreshold) {

              indicator.am = INDICATOR_SOLID;
              dragging = true;
              lastPos.set( t.current );

	}
}
 
Example 18
Source File: CellSelector.java    From YetAnotherPixelDungeon with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onDrag( Touch t ) {
	 
	camera.target = null;

	if (pinching) {

		float curSpan = PointF.distance( touch.current, another.current );
		camera.zoom( GameMath.gate( 
			PixelScene.minZoom, 
			startZoom * curSpan / startSpan, 
			PixelScene.maxZoom ) );

	} else {
	
		if (!dragging && PointF.distance( t.current, t.start ) > dragThreshold) {
			
			dragging = true;
			lastPos.set( t.current );
			
		} else if (dragging) {
			camera.scroll.offset( PointF.diff( lastPos, t.current ).invScale( camera.zoom ) );
			lastPos.set( t.current );	
		}	
	}
	
}
 
Example 19
Source File: ConeAOE.java    From shattered-pixel-dungeon with GNU General Public License v3.0 4 votes vote down vote up
public ConeAOE( int from, int to, float maxDist, float degrees, int ballisticaParams ){

		//we want to use true coordinates for our trig functions, not game cells
		// so get the center of from and to as points
		PointF fromP = new PointF(Dungeon.level.cellToPoint(from));
		fromP.x += 0.5f;
		fromP.y += 0.5f;
		PointF toP = new PointF(Dungeon.level.cellToPoint(to));
		toP.x += 0.5f;
		toP.y += 0.5f;

		//clamp distance of cone to maxDist (in true distance, not game distance)
		if (PointF.distance(fromP, toP) > maxDist){
			toP = PointF.inter(fromP, toP, maxDist/PointF.distance(fromP, toP) );
		}

		//now we can get the circle's radius. We bump it by 0.5 as we want the cone to reach
		// The edge of the target cell, not the center.
		float circleRadius = PointF.distance(fromP, toP);
		circleRadius += 0.5f;

		//Now we find every unique cell along the outer arc of our cone.
		PointF scan = new PointF();
		Point scanInt = new Point();
		float initalAngle = PointF.angle(fromP, toP)/PointF.G2R;
		//want to preserve order so that our collection of rays is going clockwise
		LinkedHashSet<Integer> targetCells = new LinkedHashSet<>();

		//cast a ray every 0.5 degrees in a clockwise arc, to find cells along the cone's outer arc
		for (float a = initalAngle+degrees/2f; a >= initalAngle-degrees/2f; a-=0.5f){
			scan.polar(a * PointF.G2R, circleRadius);
			scan.offset(fromP);
			scan.x += (fromP.x > scan.x ? +0.5f : -0.5f);
			scan.y += (fromP.y > scan.y ? +0.5f : -0.5f);
			scanInt.set(
					(int)GameMath.gate(0, (int)Math.floor(scan.x), Dungeon.level.width()-1),
					(int)GameMath.gate(0, (int)Math.floor(scan.y), Dungeon.level.height()-1));
			targetCells.add(Dungeon.level.pointToCell(scanInt));
			//if the cone is large enough, also cast rays to cells just inside of the outer arc
			// this helps fill in any holes when casting rays
			if (circleRadius >= 7) {
				scan.polar(a * PointF.G2R, circleRadius - 1);
				scan.offset(fromP);
				scan.x += (fromP.x > scan.x ? +0.5f : -0.5f);
				scan.y += (fromP.y > scan.y ? +0.5f : -0.5f);
				scanInt.set(
						(int)GameMath.gate(0, (int)Math.floor(scan.x), Dungeon.level.width()-1),
						(int)GameMath.gate(0, (int)Math.floor(scan.y), Dungeon.level.height()-1));
				targetCells.add(Dungeon.level.pointToCell(scanInt));
			}
		}

		//cast a ray to each found cell, these make up the cone
		for( int c : targetCells ){
			Ballistica ray = new Ballistica(from, c, ballisticaParams);
			cells.addAll(ray.subPath(1, ray.dist));
			rays.add(ray);
		}

	}