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


Java Vector2.set方法代碼示例

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


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

示例1: move

import com.badlogic.gdx.math.Vector2; //導入方法依賴的package包/類
@Override
public void move(Enemy enemy){
	super.move(enemy);

	float range = 10f;
	Vector2 offset = Tmp.v3.setZero();

	if(enemy.target instanceof TileEntity){
		TileEntity e = (TileEntity)enemy.target;
		range = (e.tile.block().width * Vars.tilesize) /2f + 8f;
		offset.set(e.tile.block().getPlaceOffset());
	}
	
	if(enemy.target != null && enemy.target.distanceTo(enemy.x - offset.x, enemy.y - offset.y) < range){
		explode(enemy);
	}
}
 
開發者ID:Anuken,項目名稱:Mindustry,代碼行數:18,代碼來源:BlastType.java

示例2: testSegment

import com.badlogic.gdx.math.Vector2; //導入方法依賴的package包/類
public boolean testSegment(RaycastResult out, Segment segment, float maxLambda) {
		Vector2 s = segment.p1;
		Vector2 r = tlR.get().set(segment.p2);
//		r.subLocal(s);
		r.sub(s);
		Vector2 d = tlD.get().set(p2);
//		d.subLocal(p1);
		d.sub(p1);
		Vector2 n = tlN.get();
		V2.crossToOut(d, 1.0f, n);
		Vector2 b = tlB.get();

		float k_slop = 100.0f * Settings.EPSILON;
		float denom = -V2.dot(r, n);

		// Cull back facing collision and ignore parallel segments.
		if (denom > k_slop){
			
			// Does the segment intersect the infinite line associated with this segment?
			b.set(s);
			b.sub(p1);
			float a = V2.dot(b, n);

			if (0.0f <= a && a <= maxLambda * denom){
				float mu2 = -r.x * b.y + r.y * b.x;

				// Does the segment intersect this segment?
				if (-k_slop * denom <= mu2 && mu2 <= denom * (1.0f + k_slop)){
					a /= denom;
//					n.normalize();
					n.nor();
					out.lambda = a;
					out.normal.set(n);
					return true;
				}
			}
		}
		return false;
	}
 
開發者ID:mingwuyun,項目名稱:cocos2d-java,代碼行數:40,代碼來源:Segment.java

示例3: 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;
}
 
開發者ID:kyperbelt,項目名稱:KyperBox,代碼行數:8,代碼來源:GameLayer.java

示例4: rotate180

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

示例5: rotate270

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

示例6: getBounds

import com.badlogic.gdx.math.Vector2; //導入方法依賴的package包/類
/**
 * Returns the axis aligned bounding box (AABB) of the region and mesh attachments for the current pose.
 *
 * @param offset An output value, the distance from the skeleton origin to the bottom left corner of the AABB.
 * @param size   An output value, the width and height of the AABB.
 */
public void getBounds(Vector2 offset, Vector2 size) {
    if (offset == null) throw new IllegalArgumentException("offset cannot be null.");
    if (size == null) throw new IllegalArgumentException("size cannot be null.");
    Array<Slot> drawOrder = this.drawOrder;
    float minX = Integer.MAX_VALUE, minY = Integer.MAX_VALUE, maxX = Integer.MIN_VALUE, maxY = Integer.MIN_VALUE;
    for (int i = 0, n = drawOrder.size; i < n; i++) {
        Slot slot = drawOrder.get(i);
        float[] vertices = null;
        Attachment attachment = slot.attachment;
        if (attachment instanceof RegionAttachment)
            vertices = ((RegionAttachment) attachment).updateWorldVertices(slot, false);
        else if (attachment instanceof MeshAttachment) //
            vertices = ((MeshAttachment) attachment).updateWorldVertices(slot, true);
        if (vertices != null) {
            for (int ii = 0, nn = vertices.length; ii < nn; ii += 5) {
                float x = vertices[ii], y = vertices[ii + 1];
                minX = Math.min(minX, x);
                minY = Math.min(minY, y);
                maxX = Math.max(maxX, x);
                maxY = Math.max(maxY, y);
            }
        }
    }
    offset.set(minX, minY);
    size.set(maxX - minX, maxY - minY);
}
 
開發者ID:laurencegw,項目名稱:jenjin,代碼行數:33,代碼來源:Skeleton.java

示例7: 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;
}
 
開發者ID:mingwuyun,項目名稱:cocos2d-java,代碼行數:35,代碼來源:CollideAlgorithms.java

示例8: move

import com.badlogic.gdx.math.Vector2; //導入方法依賴的package包/類
/**移動物理對象
 * 這個方法會設置prePosition<br>
 * @return */
public final float move(final TimeInfo time, final Vector2 argVector2, PhysicsObject obj) {
	argVector2.set(velocity.x * time.ratio, velocity.y * time.ratio);
	prevPosition.set(position);
	obj.updatePositionGenerators(time, argVector2);
	position.add(argVector2);
	return 0f;
	
}
 
開發者ID:mingwuyun,項目名稱:cocos2d-java,代碼行數:12,代碼來源:PhysicsObjectDynamic.java

示例9: getPosition

import com.badlogic.gdx.math.Vector2; //導入方法依賴的package包/類
/** 返回指定行列的位置存儲到pos中
 * @param row 行(y)
 * @param col 列(x)
 * @param pos
 */
public void getPosition(int row, int col, final Vector2 pos) {
	final float x = this.x + col * cellWidth;
	final float y = this.y + row * cellHeight;
	pos.set(x, y);
}
 
開發者ID:mingwuyun,項目名稱:cocos2d-java,代碼行數:11,代碼來源:TileShape.java

示例10: snipeVct

import com.badlogic.gdx.math.Vector2; //導入方法依賴的package包/類
public static void snipeVct(Vector2 current, Vector2 target, float biasAng, Vector2 out) {
	target = target == null ? JudgingSystem.playerJudge : target;
	vct2_tmp1.set(target).sub(current).rotate(biasAng);
	out.set(vct2_tmp1);
}
 
開發者ID:cn-s3bit,項目名稱:TH902,代碼行數:6,代碼來源:GameHelper.java

示例11: worldToTouch

import com.badlogic.gdx.math.Vector2; //導入方法依賴的package包/類
public static Vector2 worldToTouch(Vector2 point, Camera camera) {
    vector3.set(point, 0);
    camera.project(vector3);
    point.set(vector3.x, vector3.y);
    return point;
}
 
開發者ID:MiniDigger,項目名稱:projecttd,代碼行數:7,代碼來源:CoordinateUtil.java

示例12: update

import com.badlogic.gdx.math.Vector2; //導入方法依賴的package包/類
public void update() {
    Piece piece;
    if (heldPiece > -1) {
        piece = pieces[heldPiece];

        Vector2 mouse = new Vector2(
                Gdx.input.getX(),
                Gdx.graphics.getHeight() - Gdx.input.getY()); // Y axis is inverted

        if (Klooni.onDesktop) { //FIXME(oliver): This is a bad assumption to make. There are desktops with touch input and non-desktops with mouse input.
            // Center the piece to the mouse
            mouse.sub(piece.getRectangle().width * 0.5f, piece.getRectangle().height * 0.5f);
        } else {
            // Center the new piece position horizontally
            // and push it up by it's a cell (arbitrary) vertically, thus
            // avoiding to cover it with the finger (issue on Android devices)
            mouse.sub(piece.getRectangle().width * 0.5f, -pickedCellSize);
        }
        if (Klooni.shouldSnapToGrid())
            mouse.set(board.snapToGrid(piece, mouse));

        piece.pos.lerp(mouse, DRAG_SPEED);
        piece.cellSize = Interpolation.linear.apply(piece.cellSize, pickedCellSize, DRAG_SPEED);
    }

    // Return the pieces to their original position
    // TODO This seems somewhat expensive, can't it be done any better?
    Rectangle original;
    for (int i = 0; i < count; ++i) {
        if (i == heldPiece)
            continue;

        piece = pieces[i];
        if (piece == null)
            continue;

        original = originalPositions[i];
        piece.pos.lerp(new Vector2(original.x, original.y), 0.3f);
        piece.cellSize = Interpolation.linear.apply(piece.cellSize, original.width, 0.3f);
    }
}
 
開發者ID:LonamiWebs,項目名稱:Klooni1010,代碼行數:42,代碼來源:PieceHolder.java

示例13: averageInto

import com.badlogic.gdx.math.Vector2; //導入方法依賴的package包/類
public static Vector2 averageInto(Vector2 first, Vector2 second) {
    return first.set((first.x + second.x) / 2.0F, (first.y + second.y) / 2.0F);
}
 
開發者ID:CypherCove,項目名稱:gdx-cclibs,代碼行數:4,代碼來源:VectorUtil.java

示例14: getCenter

import com.badlogic.gdx.math.Vector2; //導入方法依賴的package包/類
@Override
public Vector2 getCenter(Vector2 result) {
    return result.set(bounds.x, bounds.y);
}
 
開發者ID:ezet,項目名稱:penguins-in-space,代碼行數:5,代碼來源:CircularBoundsComponent.java

示例15: create

import com.badlogic.gdx.math.Vector2; //導入方法依賴的package包/類
public static Vector2 create(float x, float y) {
    Vector2 v = create();
    v.set(x, y);

    return v;
}
 
開發者ID:opensourcegamedev,項目名稱:SpaceChaos,代碼行數:7,代碼來源:Vector2Pool.java


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