本文整理匯總了Java中com.badlogic.gdx.math.Vector2.len方法的典型用法代碼示例。如果您正苦於以下問題:Java Vector2.len方法的具體用法?Java Vector2.len怎麽用?Java Vector2.len使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.badlogic.gdx.math.Vector2
的用法示例。
在下文中一共展示了Vector2.len方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: normalize
import com.badlogic.gdx.math.Vector2; //導入方法依賴的package包/類
/** Normalize this vector and return the length before normalization. Alters this vector. */
public static final float normalize(Vector2 self) {
final float length = self.len();
if (length < Settings.EPSILON) {
return 0f;
}
self.x /= length;
self.y /= length;
return length;
}
示例2: ballReachedEnd
import com.badlogic.gdx.math.Vector2; //導入方法依賴的package包/類
/**
* Checks whether the ball's model reached the level's end position.
*
* @return True if ball reached end position, false otherwise.
*/
private boolean ballReachedEnd() {
Vector2 diff = new Vector2(endPos);
diff.sub(ballModel.getX(), ballModel.getY());
return diff.len() < BallModel.RADIUS;
}
示例3: processEntity
import com.badlogic.gdx.math.Vector2; //導入方法依賴的package包/類
@Override
public void processEntity(Entity entity, float deltaTime) {
TransformComponent transform = pm.get(entity);
VelocityComponent velocity = vm.get(entity);
PathComponent path = pathM.get(entity);
MinionComponent minionComponent = minionM.get(entity);
if (path.nextPoint == null) {
velocity.linear.setZero();
velocity.angular = 0;
return;
}
// calc dir and len
Vector2 toTarget = temp.set(path.nextPoint).sub(transform.position);
float distance = toTarget.len();
// don't go too far!
if (distance <= 0.05) {
velocity.linear.setZero();
velocity.angular = 0;
path.nextPoint = null;
return;
}
float maxSpeed = minionComponent.speed;
System.out.println("speed " + maxSpeed);
// Target velocity combines speed and direction
Vector2 targetVelocity = toTarget.scl(maxSpeed / distance); // Optimized code for:
// toTarget.nor().scl(maxSpeed)
// Acceleration tries to get to the nextPoint velocity without exceeding max acceleration
targetVelocity.sub(velocity.linear).scl(1f / linearAccelerationTime).limit(maxLinearAcceleration);
// set it
velocity.linear.set(toTarget);
// angular
// Check for a zero direction, and set to 0 is so
if (velocity.linear.isZero(zeroThreshold)) {
velocity.angular = 0;
return;
}
// Calculate the orientation based on the velocity of the owner
float targetOrientation = VectorUtil.vectorToAngle(velocity.linear);
// Get the rotation direction to the nextPoint wrapped to the range [-PI, PI]
float rotation = ArithmeticUtils.wrapAngleAroundZero(targetOrientation - (transform.rotation - 90) * MathUtils.degreesToRadians);
// Absolute rotation
float rotationSize = rotation < 0f ? -rotation : rotation;
// Check if we are there, set velocity to 0 and return if so
if (rotationSize <= 0.1) {
velocity.angular = 0;
return;
}
// Use maximum rotation
float targetRotation = maxAngularSpeed;
// The final nextPoint rotation combines
// speed (already in the variable) and direction
targetRotation *= rotation / rotationSize;
// Acceleration tries to get to the nextPoint rotation
velocity.angular = (targetRotation - velocity.angular) / angularAccelerationTime;
// Check if the absolute acceleration is too great
float angularAcceleration = velocity.angular < 0f ? -velocity.angular : velocity.angular;
if (angularAcceleration > maxAngularAcceleration) {
velocity.angular *= maxAngularAcceleration / angularAcceleration;
}
}