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


Java Vector2.sub方法代碼示例

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


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

示例1: 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

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

import com.badlogic.gdx.math.Vector2; //導入方法依賴的package包/類
public static boolean checkIfLinesAreEquals(Line a, Line b) {
    // check if lines are parallel, else they cannot be equals
    if (!checkVectorsParallel(a.getDirection(), b.getDirection())) {
        return false;
    }

    Vector2 d = Vector2Pool.create();
    d.set(a.getBase().x, a.getBase().y);

    d.sub(b.getBase());

    Vector2Pool.free(d);

    return checkVectorsParallel(d, a.getDirection());
}
 
開發者ID:opensourcegamedev,項目名稱:SpaceChaos,代碼行數:16,代碼來源:FastMath.java

示例5: 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

示例6: testSegmentCollision

import com.badlogic.gdx.math.Vector2; //導入方法依賴的package包/類
public static boolean testSegmentCollision(Segment a, Segment b) {
    Vector2 d = Vector2Pool.create(a.getPoint2()).sub(a.getPoint1());

    Line axisA = LinePool.create();
    axisA.setBase(a.getPoint1());
    axisA.setDirection(d);

    Line axisB = LinePool.create();

    if (onOneSide(axisA, b)) {
        // recycle objects
        LinePool.free(axisA, axisB);
        Vector2Pool.free(d);

        return false;
    }

    axisB.setBase(b.getPoint1());
    d.set(b.getPoint2());
    d = d.sub(b.getPoint1());
    axisB.setDirection(d);

    if (onOneSide(axisB, a)) {
        // recycle objects
        LinePool.free(axisA, axisB);
        Vector2Pool.free(d);

        return false;
    }

    if (FastMath.checkVectorsParallel(axisA.getDirection(), axisB.getDirection())) {
        Range rangeA = a.projectSegment(axisA.getDirection());
        Range rangeB = b.projectSegment(axisB.getDirection());

        // recycle objects
        LinePool.free(axisA, axisB);
        Vector2Pool.free(d);

        return rangeA.overlaps(rangeB);
    } else {
        // recycle objects
        LinePool.free(axisA, axisB);
        Vector2Pool.free(d);

        return true;
    }
}
 
開發者ID:opensourcegamedev,項目名稱:SpaceChaos,代碼行數:48,代碼來源:ColliderUtils.java

示例7: dropItem

import com.badlogic.gdx.math.Vector2; //導入方法依賴的package包/類
public void dropItem(@NotNull Item item, Vector2 dropPos, @Nullable Vector2 targetPos) {
	
	/* this drops the itemEntity at the given coordinates, with the given direction (random if null).
	 	However, if the given coordinates reside within a solid tile, the adjacent tiles are checked.
	 		If all surrounding tiles are solid, then it just uses the given coordinates.
	 		But if it finds a non-solid tile, it drops it towards the non-solid tile.
	  */
	
	Rectangle itemBounds = new Rectangle(dropPos.x, dropPos.y, item.getItemData().getTexture().getRegionWidth(), item.getItemData().getTexture().getRegionHeight());
	Tile closest = getClosestTile(itemBounds);
	
	if(closest == null) {
		System.err.println("ERROR dropping item, closest tile is null");
		return;
	}
	
	ItemEntity ie = new ItemEntity(item, Vector2.Zero.cpy()); // this is a dummy variable.
	
	if(!closest.isPermeableBy(ie)) {
		// we need to look around for a tile that the item *can* be placed on.
		Array<Tile> adjacent = closest.getAdjacentTiles(true);
		Tile.sortByDistance(adjacent, targetPos);
		for(Tile adj: adjacent) {
			if(adj.isPermeableBy(ie)) {
				closest = adj;
				break;
			}
		}
	}
	
	// make sure the item will be fully inside the "closest" tile when dropped.
	MyUtils.moveRectInside(itemBounds, closest.getBounds(), 1);
	
	dropPos.x = itemBounds.x;
	dropPos.y = itemBounds.y;
	
	if(targetPos == null)
		targetPos = dropPos.cpy().add(new Vector2(MathUtils.random(Tile.SIZE/2), MathUtils.random(Tile.SIZE/2)));
	
	ie = new ItemEntity(item, targetPos.sub(dropPos));
	
	ie.moveTo(this, dropPos);
	addEntity(ie);
}
 
開發者ID:chrisj42,項目名稱:miniventure,代碼行數:45,代碼來源:Level.java

示例8: 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


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