本文整理匯總了Java中com.badlogic.gdx.math.Vector2.dst2方法的典型用法代碼示例。如果您正苦於以下問題:Java Vector2.dst2方法的具體用法?Java Vector2.dst2怎麽用?Java Vector2.dst2使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.badlogic.gdx.math.Vector2
的用法示例。
在下文中一共展示了Vector2.dst2方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setInfo
import com.badlogic.gdx.math.Vector2; //導入方法依賴的package包/類
@Override
public void setInfo(Cell deadCell, Vector2 culprit) {
cell = deadCell;
vanishSize = cell.size;
vanishColor = cell.getColorCopy();
vanishLifetime = 1f;
// The vanish distance is this measure (distance² + size³ * 20% size)
// because it seems good enough. The more the distance, the more the
// delay, but we decrease the delay depending on the cell size too or
// it would be way too high
Vector2 center = new Vector2(cell.pos.x + cell.size * 0.5f, cell.pos.y + 0.5f);
float vanishDist = Vector2.dst2(
culprit.x, culprit.y, center.x, center.y) / ((float)Math.pow(cell.size, 4.0f) * 0.2f);
// Negative time = delay, + 0.4*lifetime because elastic interpolation has that delay
vanishElapsed = vanishLifetime * 0.4f - vanishDist;
}
示例2: checkForStuckBall
import com.badlogic.gdx.math.Vector2; //導入方法依賴的package包/類
/**
* Checks whether the ball appears to be stuck, and nudges it if so.
*/
void checkForStuckBall(long nanos) {
// Only do this for single balls. This means it's theoretically possible for multiple
// balls to be simultaneously stuck during multiball; that would be impressive.
if (this.getBalls().size() != 1) {
nanosSinceBallMoved = -1;
return;
}
Ball ball = this.getBalls().get(0);
Vector2 pos = ball.getPosition();
if (nanosSinceBallMoved < 0) {
// New ball.
lastBallPositionX = pos.x;
lastBallPositionY = pos.y;
nanosSinceBallMoved = 0;
return;
}
if (ball.getLinearVelocity().len2() > 0.01f ||
pos.dst2(lastBallPositionX, lastBallPositionY) > 0.01f) {
// Ball has moved since last time; reset counter.
lastBallPositionX = pos.x;
lastBallPositionY = pos.y;
nanosSinceBallMoved = 0;
return;
}
// Don't add time if any flipper is activated (the flipper could be trapping the ball).
List<FlipperElement> flippers = this.getFlipperElements();
for (int i=0; i<flippers.size(); i++) {
if (flippers.get(i).isFlipperEngaged()) return;
}
// Increment time counter and bump if the ball hasn't moved in a while.
nanosSinceBallMoved += nanos;
if (nanosSinceBallMoved > STUCK_BALL_NANOS) {
showGameMessage("Bump!", 1000);
// Could make the bump impulse table-specific if needed.
Vector2 impulse = new Vector2(RAND.nextBoolean() ? 1f : -1f, 1.5f);
ball.applyLinearImpulse(impulse);
nanosSinceBallMoved = 0;
}
}
示例3: pointLineDist
import com.badlogic.gdx.math.Vector2; //導入方法依賴的package包/類
/**Returns distance from a point to a line segment.*/
private static float pointLineDist(float x, float y, float x2, float y2, float px, float py){
float l2 = Vector2.dst2(x, y, x2, y2);
float t = Math.max(0, Math.min(1, Vector2.dot(px - x, py - y, x2 - x, y2 - y) / l2));
Vector2 projection = Tmp.v1.set(x, y).add(Tmp.v2.set(x2, y2).sub(x, y).scl(t)); // Projection falls on the segment
return projection.dst(px, py);
}
示例4: moveFocusByDirection
import com.badlogic.gdx.math.Vector2; //導入方法依賴的package包/類
private boolean moveFocusByDirection(MoveFocusDirection direction) {
if (focussedActor == null)
return false;
Vector2 focussedPosition = focussedActor.localToStageCoordinates(
new Vector2(direction == MoveFocusDirection.east ? focussedActor.getWidth() :
direction == MoveFocusDirection.west ? 0 : focussedActor.getWidth() / 2,
direction == MoveFocusDirection.north ? focussedActor.getHeight() :
direction == MoveFocusDirection.south ? 0 : focussedActor.getHeight() / 2));
// in Frage kommende raussuchen
Actor nearestInDirection = null;
float distance = Float.MAX_VALUE;
for (int i = 0; i < focussableActors.size; i++) {
Actor currentActor = focussableActors.get(i);
if (currentActor != focussedActor && isActorFocussable(currentActor)
&& isActorInViewportArea(currentActor)) {
Vector2 currentActorPos = currentActor.localToStageCoordinates(
new Vector2(direction == MoveFocusDirection.west ? currentActor.getWidth() :
direction == MoveFocusDirection.east ? 0 : currentActor.getWidth() / 2,
direction == MoveFocusDirection.south ? currentActor.getHeight() :
direction == MoveFocusDirection.south ? 0 : currentActor.getHeight() / 2));
boolean isInDirection = false;
isInDirection = (direction == MoveFocusDirection.south && currentActorPos.y <= focussedPosition.y)
|| (direction == MoveFocusDirection.north && currentActorPos.y >= focussedPosition.y)
|| (direction == MoveFocusDirection.west && currentActorPos.x <= focussedPosition.x)
|| (direction == MoveFocusDirection.east && currentActorPos.x >= focussedPosition.x);
if (isInDirection && isActorHittable(currentActor)) {
float currentDist = currentActorPos.dst2(focussedPosition);
if (currentDist < distance) {
nearestInDirection = currentActor;
distance = currentDist;
}
}
}
}
if (nearestInDirection != null)
setFocussedActor(nearestInDirection);
return (nearestInDirection != null);
}