本文整理匯總了Java中com.badlogic.gdx.math.Vector2.scl方法的典型用法代碼示例。如果您正苦於以下問題:Java Vector2.scl方法的具體用法?Java Vector2.scl怎麽用?Java Vector2.scl使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.badlogic.gdx.math.Vector2
的用法示例。
在下文中一共展示了Vector2.scl方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: axisSeparatePolygonsMTD
import com.badlogic.gdx.math.Vector2; //導入方法依賴的package包/類
/**測試在Axis軸上的A、B是否分離 並 將軸用於MTD測試
* @param Axis
* @param A
* @param B
* @param positionA
* @param positionB
* @return <code>true</code> 分離
* <code>false</code> 未分離 */
public static final boolean axisSeparatePolygonsMTD(final Vector2 Axis, final Polygon A, final Polygon B,
final Vector2 positionA, final Vector2 positionB) {
pair=CalculateInterval(Axis, A, positionA);
final float mina=pair.min;
final float maxa=pair.max;
pair=CalculateInterval(Axis, B, positionB);
final float minb=pair.min;
final float maxb=pair.max;
if (mina > maxb || minb > maxa)
return true;
// find the interval overlap
final float d0 = maxa - minb;
final float d1 = maxb - mina;
final float depth = (d0 < d1)? d0 : d1;
// convert the separation axis into a push vector (re-normalise
// the axis and multiply by interval overlap)
float axisLengthSquared = V2.dot(Axis, Axis);
Axis.scl(depth / axisLengthSquared);
return false;
}
示例2: axisSeparateAABBMTDX
import com.badlogic.gdx.math.Vector2; //導入方法依賴的package包/類
/**測試X軸向上的兩個AABB是否分離
* <br>true為分離 axis為x軸的單位向量 必須傳入(1,0)<br>
* <b>使用兩個pool</b>
* @param Axis
* @param A
* @param B
* @param positionA
* @param positionB
* @return*/
public static final boolean axisSeparateAABBMTDX(final Vector2 axis,
final AABBShape A, final AABBShape B,
final Vector2 positionA, final Vector2 positionB) {
final float mina=positionA.x+A.getPoints()[0].x;
final float maxa=positionA.x+A.getPoints()[2].x;
final float minb=positionB.x+B.getPoints()[0].x;
final float maxb=positionB.x+B.getPoints()[2].x;
if (mina > maxb || minb > maxa)
return true;
// find the interval overlap
final float d0 = maxa - minb;
final float d1 = maxb - mina;
final float depth = (d0 < d1)? d0 : d1;
// convert the separation axis into a push vector (re-normalise
// the axis and multiply by interval overlap)
axis.scl(depth);
return false;
}
示例3: axisSeparatePolygonsMTDX
import com.badlogic.gdx.math.Vector2; //導入方法依賴的package包/類
/**測試在X軸上的A、B是否分離
* 用於MTD測試的方法
* Axis必須為(1,0)
* @param Axis
* @param A
* @param B
* @return <code>true</code> A與B分離
* <code>false</code> A與B重合 */
public static final boolean axisSeparatePolygonsMTDX(final Vector2 Axis, final Polygon A, final AABBShape B,
final Vector2 positionA, final Vector2 positionB ) {
pair=CalculateInterval(Axis, A, positionA);
final float mina=pair.min;
final float maxa=pair.max;
final float minb=B.getPoints()[0].x+positionB.x;
final float maxb=B.getPoints()[2].x+positionB.x;
if (mina > maxb || minb > maxa)
return true;
// find the interval overlap
final float d0 = maxa - minb;
final float d1 = maxb - mina;
final float depth = (d0 < d1)? d0 : d1;
//直接求出即可
Axis.scl(depth);
return false;
}
示例4: axisSeparatePolygonsMTDY
import com.badlogic.gdx.math.Vector2; //導入方法依賴的package包/類
/**測試在Y軸上的A、B是否分離
* 用於MTD測試的方法
* Axis必須為(0,1)
* <br>true為分離
* @param Axis
* @param A
* @param B
* @return <code>true</code> A與B分離
* <code>false</code> A與B重合*/
public static final boolean axisSeparatePolygonsMTDY(final Vector2 Axis, final Polygon A, final AABBShape B,
final Vector2 positionA, final Vector2 positionB) {
pair=CalculateInterval(Axis, A, positionA);
final float mina=pair.min;
final float maxa=pair.max;
final float minb=B.getPoints()[0].y+positionB.y;
final float maxb=B.getPoints()[2].y+positionB.y;
if (mina > maxb || minb > maxa)
return true;
// find the interval overlap
final float d0 = maxa - minb;
final float d1 = maxb - mina;
final float depth = (d0 < d1)? d0 : d1;
Axis.scl(depth);
return false;
}
示例5: createEntityBody
import com.badlogic.gdx.math.Vector2; //導入方法依賴的package包/類
/**
* Erlaubt es den Unterklassen möglichst einfach einen beliebigen Box2D Körper zu erstellen.
*
* @param position die Startposition des Body
* @param shape die Form, die für dne Body verwendet werden soll
* @param type der Typ des Körpers
* @return ein Box2D Körper
*/
protected Body createEntityBody(Vector2 position, Shape shape, BodyDef.BodyType type)
{
position.scl(Physics.MPP);
BodyDef bodyDef = new BodyDef();
bodyDef.type = type;
bodyDef.position.set(position);
bodyDef.fixedRotation = true;
Body body = worldObjectManager.getPhysicalWorld().createBody(bodyDef);
body.setUserData(this);
FixtureDef fixture = new FixtureDef();
fixture.shape = shape;
fixture.filter.categoryBits = Physics.CATEGORY_ENTITIES;
fixture.filter.maskBits = Physics.MASK_ENTITIES;
body.createFixture(fixture).setUserData(this);
shape.dispose();
return body;
}
示例6: Intersect
import com.badlogic.gdx.math.Vector2; //導入方法依賴的package包/類
/**圓與圓的MTD相交測試
* @param A
* @param B
* @param positionA
* @param positionB
* @param MTD
* @return <code>true</code> 形狀相交
* <code>false</code> 形狀不相交 */
public static final boolean Intersect(final Circle A,final Circle B,
final Vector2 positionA,final Vector2 positionB,final Vector2 MTD){
//pool1為MTD的方向 pool2保存pool1的向量
pool1.set(positionA.x+A.circleCenter.x-positionB.x-B.circleCenter.x,
positionA.y+A.circleCenter.y-positionB.y-B.circleCenter.y);
pool2.set(pool1);
//求出向量的模並單位化向量
final float length = V2.normalize(pool1);
//計算兩圓的刺入深度
final float depth=A.getRadius()+B.getRadius()-length;
if(depth >= 0){
MTD.set(pool1);
MTD.scl(depth);
// MTD方向應該是由positionB指向positionA
if (V2.dot(pool1, MTD)<0) {
V2.negate(MTD);
}
return true;
}
return false;
}
示例7: checkInput
import com.badlogic.gdx.math.Vector2; //導入方法依賴的package包/類
public void checkInput(float delta, @NotNull Vector2 mouseInput) {
// checks for keyboard input to move the player.
// getDeltaTime() returns the time passed between the last and the current frame in seconds.
int speed = Tile.SIZE * 5; // this is technically in units/second.
Vector2 movement = new Vector2();
if(Gdx.input.isKeyPressed(Input.Keys.LEFT)) movement.x--;
if(Gdx.input.isKeyPressed(Input.Keys.RIGHT)) movement.x++;
if(Gdx.input.isKeyPressed(Input.Keys.UP)) movement.y++;
if(Gdx.input.isKeyPressed(Input.Keys.DOWN)) movement.y--;
movement.nor();
movement.add(mouseInput);
movement.nor();
movement.scl(speed * delta);
move(movement.x, movement.y);
if(pressingKey(Input.Keys.Q)) cycleHeldItem(false);
if(pressingKey(Input.Keys.E)) cycleHeldItem(true);
if(pressingKey(Input.Keys.C))
attack();
else if(pressingKey(Input.Keys.V))
interact();
heldItem = heldItem == null ? null : heldItem.consume();
}
示例8: calculateGravityCenter
import com.badlogic.gdx.math.Vector2; //導入方法依賴的package包/類
Vector2 calculateGravityCenter() {
int filledCount = 0;
Vector2 result = new Vector2();
for (int i = 0; i < cellRows; ++i) {
for (int j = 0; j < cellCols; ++j) {
if (shape[i][j]) {
filledCount++;
result.add(
pos.x + j * cellSize - cellSize * 0.5f,
pos.y + i * cellSize - cellSize * 0.5f);
}
}
}
return result.scl(1f / filledCount);
}
示例9: project
import com.badlogic.gdx.math.Vector2; //導入方法依賴的package包/類
public Vector2 project(Vector2 coords) {
Viewport view = layer.getState().getGame().getView();
view.project(coords);
coords.scl(getZoom());
coords.set(coords.x + position.x, coords.y + position.y);
return coords;
}
示例10: render
import com.badlogic.gdx.math.Vector2; //導入方法依賴的package包/類
@Override
public void render(Batch batch, float deltaTime)
{
if (body == null) return;
Color oldColor = batch.getColor();
batch.setColor(1f, (health + 5)/10f, (health + 5)/10f, 1f);
Vector2 pos = body.getPosition();
pos.scl(Physics.PPM);
TextureRegion region = MathUtils.isZero(hitTimer) ? dummy : dummy_hit;
batch.draw(region, // TextureRegion (front, back, side)
pos.x - dummy.getRegionWidth() / 2, // Offset to the X position (character center)
pos.y, // Y position is at the foots
dummy.getRegionWidth() / 2, // Origin X (important for flipping)
dummy.getRegionHeight(), // Origin Y
dummy.getRegionWidth(), // Width
dummy.getRegionHeight(), // Height
1f, // Scale X (-1 to flip)
1f, // Scale Y
0f); // Rotation
batch.setColor(oldColor);
}
示例11: render
import com.badlogic.gdx.math.Vector2; //導入方法依賴的package包/類
@Override
public void render(Batch batch, float deltaTime)
{
if (body == null) return;
animationTime += deltaTime;
Color oldColor = batch.getColor();
batch.setColor(1f, (health + 4)/8f, (health + 4)/8f, 1f);
Vector2 pos = body.getPosition();
pos.scl(Physics.PPM);
TextureRegion region = crabAnimation.getKeyFrame(animationTime);
batch.draw(region, // TextureRegion (front, back, side)
pos.x - region.getRegionWidth() / 2, // Offset to the X position (character center)
pos.y, // Y position is at the foots
region.getRegionWidth() / 2, // Origin X (important for flipping)
region.getRegionHeight(), // Origin Y
region.getRegionWidth(), // Width
region.getRegionHeight(), // Height
1f, // Scale X (-1 to flip)
1f, // Scale Y
0f); // Rotation
batch.setColor(oldColor);
}
示例12: render
import com.badlogic.gdx.math.Vector2; //導入方法依賴的package包/類
@Override
public void render(Batch batch, float deltaTime)
{
if (body == null) return;
Color oldColor = batch.getColor();
batch.setColor(1f, (health + 5)/10f, (health + 5)/10f, 1f);
Vector2 pos = body.getPosition();
pos.scl(Physics.PPM);
float scaleX = 1f;
animationTime += deltaTime;
batch.draw(rabbit, // TextureRegion (front, back, side)
pos.x - rabbit.getRegionWidth() / 2, // Offset to the X position (character center)
pos.y, // Y position is at the foots
rabbit.getRegionWidth() / 2, // Origin X (important for flipping)
rabbit.getRegionHeight(), // Origin Y
rabbit.getRegionWidth(), // Width
rabbit.getRegionHeight(), // Height
scaleX, // Scale X (-1 to flip)
1f, // Scale Y
0f); // Rotation
batch.setColor(oldColor);
}
示例13: render
import com.badlogic.gdx.math.Vector2; //導入方法依賴的package包/類
@Override
public void render(Batch batch, float deltaTime)
{
if (body == null) return;
Color oldColor = batch.getColor();
batch.setColor(1f, (health + 5)/10f, (health + 5)/10f, 1f);
Vector2 pos = body.getPosition();
pos.scl(Physics.PPM);
TextureRegion region = null;
float scaleX = 1f;
animationTime += deltaTime;
switch (orientation)
{
case LOOK_FORWARD:
region = npcFrontWalk.getKeyFrame(animationTime);
break;
case LOOK_LEFT:
region = npcSideWalk.getKeyFrame(animationTime);
break;
case LOOK_BACKWARD:
region = npcBackWalk.getKeyFrame(animationTime);
scaleX = -1f;
break;
case LOOK_RIGHT:
region = npcSideWalk.getKeyFrame(animationTime);
scaleX = -1f;
break;
}
batch.draw(region, // TextureRegion (front, back, side)
pos.x - region.getRegionWidth() / 2, // Offset to the X position (character center)
pos.y, // Y position is at the foots
region.getRegionWidth() / 2, // Origin X (important for flipping)
region.getRegionHeight(), // Origin Y
region.getRegionWidth(), // Width
region.getRegionHeight(), // Height
scaleX, // Scale X (-1 to flip)
1f, // Scale Y
0f); // Rotation
batch.setColor(oldColor);
}
示例14: computePolygonProperties
import com.badlogic.gdx.math.Vector2; //導入方法依賴的package包/類
/**
* Computes the Polygon Properties of a given Polygon.
*
* @param polygon The polygon to be analyzed.
* @return The Polygon Properties computed.
*/
public static PolygonProperties computePolygonProperties(Vector2[] polygon) {
PolygonProperties polygonProperties = null;
int count = polygon.length;
if (count >= 3) {
Vector2 centroid = new Vector2(0, 0);
float area = 0;
Vector2 refPoint = new Vector2(0, 0);
float threeInverse = 1 / 3f;
for (int i = 0; i < count; i++) {
/*
* Create a new vector to represent the reference point for
* forming triangles. Then use refPoint, polygonVertex and
* thirdTriangleVertex as vertices of a triangle.
*/
refPoint.set(0, 0);
Vector2 polygonVertex = polygon[i];
Vector2 thirdTriangleVertex = i + 1 < count ? polygon[i + 1]
: polygon[0];
Vector2 firstDirectionVector = polygonVertex.sub(refPoint);
Vector2 secondDirectionVector = thirdTriangleVertex
.sub(refPoint);
float triangleArea = firstDirectionVector
.crs(secondDirectionVector) / 2;
area += triangleArea;
/* Area weighted centroid */
centroid.add(refPoint.add(polygonVertex)
.add(thirdTriangleVertex)
.scl(triangleArea * threeInverse));
}
if (area > EPSILON) {
centroid.scl(1 / area);
} else {
area = 0;
}
polygonProperties = new PolygonProperties(centroid, area);
}
return polygonProperties;
}
示例15: 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;
}
}