當前位置: 首頁>>代碼示例>>Java>>正文


Java Vector2.add方法代碼示例

本文整理匯總了Java中com.badlogic.gdx.math.Vector2.add方法的典型用法代碼示例。如果您正苦於以下問題:Java Vector2.add方法的具體用法?Java Vector2.add怎麽用?Java Vector2.add使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.badlogic.gdx.math.Vector2的用法示例。


在下文中一共展示了Vector2.add方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: trans

import com.badlogic.gdx.math.Vector2; //導入方法依賴的package包/類
/**平移 變更形狀	更新AABB
 * @param x
 * @param y */
public final void trans(final float x,final float y){
	for(Vector2 v: points){
		v.add(x, y);
	}
	computeShapeAABB();
	computeShapeCenter();
}
 
開發者ID:mingwuyun,項目名稱:cocos2d-java,代碼行數:11,代碼來源:Polygon.java

示例2: trans

import com.badlogic.gdx.math.Vector2; //導入方法依賴的package包/類
public void trans(float x, float y) {
	for(Vector2 v:points){
		v.add(x,y);
	}
	this.computeShapeAABB();
	computeShapeCenter();
}
 
開發者ID:mingwuyun,項目名稱:cocos2d-java,代碼行數:8,代碼來源:AABBShape.java

示例3: resetWithPoints

import com.badlogic.gdx.math.Vector2; //導入方法依賴的package包/類
public void resetWithPoints(Vector2 pointA, Vector2 pointB) {
	float distance = pointA.dst(pointB);
	Vector2 diffVector = pointA.sub(pointB);
	float multiplier = distance / (numPoints - 1);
	for(int i=0;i<numPoints;i++) {
		Vector2 tmpVector = pointA.add(diffVector.nor().mul(multiplier*i*(1-antiSagHack)));
		VPoint tmpPoint = vPoints.get(i);
		tmpPoint.setPos(tmpVector.x, tmpVector.y);
		
	}
}
 
開發者ID:game-libgdx-unity,項目名稱:GDX-Engine,代碼行數:12,代碼來源:VRope.java

示例4: 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();
}
 
開發者ID:chrisj42,項目名稱:miniventure,代碼行數:30,代碼來源:Player.java

示例5: 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);
}
 
開發者ID:LonamiWebs,項目名稱:Klooni1010,代碼行數:16,代碼來源:Piece.java

示例6: move

import com.badlogic.gdx.math.Vector2; //導入方法依賴的package包/類
public void move(Enemy enemy){
    float speed = this.speed + 0.04f * enemy.tier;
    float range = this.range + enemy.tier * 5;

    if(Net.client() && Net.active()){
        enemy.interpolate(); //TODO? better structure for interpolation
        return;
    }

    Tile core = Vars.control.getCore();

    if(enemy.idletime > maxIdleLife){
        enemy.onDeath();
        return;
    }

    boolean nearCore = enemy.distanceTo(core.worldx(), core.worldy()) <= range - 18f && stopNearCore;
    Vector2 vec;

    if(nearCore){
        vec = Tmp.v1.setZero();
        if(targetCore) enemy.target = core.entity;
    }else{
        vec = Vars.world.pathfinder().find(enemy);
        vec.sub(enemy.x, enemy.y).limit(speed);
    }

    Vector2 shift = Tmp.v3.setZero();
    float shiftRange = enemy.hitbox.width + 2f;
    float avoidRange = shiftRange + 4f;
    float attractRange = avoidRange + 7f;
    float avoidSpeed = this.speed/2.7f;

    Entities.getNearby(Vars.control.enemyGroup, enemy.x, enemy.y, range, en -> {
        Enemy other = (Enemy)en;
        if(other == enemy) return;
        float dst = other.distanceTo(enemy);

        if(dst < shiftRange){
            float scl = Mathf.clamp(1.4f - dst / shiftRange) * mass * 1f/mass;
            shift.add((enemy.x - other.x) * scl, (enemy.y - other.y) * scl);
        }else if(dst < avoidRange){
            Tmp.v2.set((enemy.x - other.x), (enemy.y - other.y)).setLength(avoidSpeed);
            shift.add(Tmp.v2.scl(1.1f));
        }else if(dst < attractRange && !nearCore){
            Tmp.v2.set((enemy.x - other.x), (enemy.y - other.y)).setLength(avoidSpeed);
            shift.add(Tmp.v2.scl(-1));
        }
    });

    shift.limit(1f);
    vec.add(shift.scl(0.5f));

    enemy.move(vec.x * Timers.delta(), vec.y * Timers.delta());

    updateTargeting(enemy, nearCore);
}
 
開發者ID:Anuken,項目名稱:Mindustry,代碼行數:58,代碼來源:EnemyType.java

示例7: 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;
}
 
開發者ID:AndreFCruz,項目名稱:feup-lpoo-armadillo,代碼行數:55,代碼來源:PolygonIntersector.java

示例8: chase

import com.badlogic.gdx.math.Vector2; //導入方法依賴的package包/類
public static void chase(Vector2 toModify, final Vector2 target, final float speed) {
	vct2_tmp1.set(target).sub(toModify);
	toModify.add(vct2_tmp1.nor().scl(speed));
}
 
開發者ID:cn-s3bit,項目名稱:TH902,代碼行數:5,代碼來源:GameHelper.java


注:本文中的com.badlogic.gdx.math.Vector2.add方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。