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


Java Vector2.dot方法代碼示例

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


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

示例1: projectSegment

import com.badlogic.gdx.math.Vector2; //導入方法依賴的package包/類
public Range projectSegment(Vector2 onto) {
    // create new range or use an recycled range
    Range range = RangePool.create();

    // normailize vector
    onto.nor();

    // calculate min and max value with dot product
    float min = onto.dot(point1);
    float max = onto.dot(point2);
    range.set(min, max);

    return range;
}
 
開發者ID:opensourcegamedev,項目名稱:SpaceChaos,代碼行數:15,代碼來源:Segment.java

示例2: onOneSide

import com.badlogic.gdx.math.Vector2; //導入方法依賴的package包/類
public static boolean onOneSide(Line axis, Segment s) {
    Vector2 d1 = Vector2Pool.create(s.getPoint1()).sub(axis.getBase());
    Vector2 d2 = Vector2Pool.create(s.getPoint2()).sub(axis.getBase());
    Vector2 n = FastMath.rotateVector90(axis.getDirection(), Vector2Pool.create());

    float dotProduct = n.dot(d1) * n.dot(d2);

    // recycle vectors
    Vector2Pool.free(d1, d2, n);

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

示例3: checkVectorsParallel

import com.badlogic.gdx.math.Vector2; //導入方法依賴的package包/類
public static boolean checkVectorsParallel(Vector2 v1, Vector2 v2) {
    // rotate vector 90 degrees
    Vector2 rotatedVector1 = rotateVector90(v1, Vector2Pool.create());

    // 2 vectors are parallel, if dot product = 0
    float dotProduct = rotatedVector1.dot(v2);

    Vector2Pool.free(rotatedVector1);

    return dotProduct == 0;
}
 
開發者ID:opensourcegamedev,項目名稱:SpaceChaos,代碼行數:12,代碼來源:FastMath.java

示例4: process

import com.badlogic.gdx.math.Vector2; //導入方法依賴的package包/類
@Override
protected void process(int entityId) {
    PositionComponent pos = mapperPosition.get(entityId);
    CharacterComponent character = mapperCharacterComponent.get(entityId);
    StatComponent stats = mapperStatComponent.get(entityId);
    PhysicComponent physicComponent = mapperPhysicComponent.get(entityId);
    RenderComponent renderComponent = mapperRenderComponent.get(entityId);


    /**
     * Movement code. Does not (as of yet) contain proper pathfinder logic.
     */
    if (character.move.dst(pos.position) != 0 && physicComponent.body.getLinearVelocity().equals(Vector2.Zero) && !stats.getFlag(StatComponent.FlagStat.dead)) {
        if (stats.getRuntimeStat(StatComponent.RuntimeStat.actionPoints) >= 1 && (renderComponent == null || renderComponent.isInState(IDLE)
                || renderComponent.isInState(ATTACK))) {
            Vector2 dir = vectorPool.obtain();
            Vector2 speed = vectorPool.obtain();
            if (Math.abs(character.move.x - pos.position.x) > Math.abs(character.move.y - pos.position.y))
                dir.set(Math.signum(character.move.x - pos.position.x), 0);
            else
                dir.set(0, Math.signum(character.move.y - pos.position.y));

            if (renderComponent != null) {
                renderComponent.setRenderState(dir.y == 0 ? MOVE_SIDE :
                        dir.y < 0 ? MOVE_DOWN : MOVE_UP);
                if (dir.x != 0)
                    renderComponent.flipX = dir.x < 0;
            }
            physicComponent.body.setLinearVelocity(speed.set(dir).scl(stats.getCurrentStat(StatComponent.BaseStat.moveSpeed)));
            character.stepMove.set(dir.add(pos.position));
            character.startToEnd.set(dir.set(pos.position).sub(character.stepMove));
            vectorPool.free(dir);
            vectorPool.free(speed);
            stats.addRuntimeStat(StatComponent.RuntimeStat.actionPoints, -1);
            character.targetId = -1;
        }
    } else if (!physicComponent.body.getLinearVelocity().equals(Vector2.Zero)) {
        Vector2 curr = vectorPool.obtain();

        curr.set(physicComponent.body.getPosition()).sub(character.stepMove);

        if (curr.dot(character.startToEnd) < 0) {
            physicComponent.body.setLinearVelocity(Vector2.Zero);
            physicComponent.body.setTransform(pos.position, physicComponent.body.getAngle());
            renderComponent.setRenderState(IDLE);
        }
        vectorPool.free(curr);
    }

    /**
     * Auto-attack logic.
     */
    if (!character.character.isCasting())
        if (character.targetId == entityId)
            character.targetId = -1;
        else if (character.targetId != -1) {
            Vector2 vector = vectorPool.obtain();
            PositionComponent target = mapperPosition.get(character.targetId);
            if (target == null)
                character.targetId = -1;
            else {
                if (Math.abs(vector.set(pos.position).dst(target.position)) <= stats.getCurrentStat(StatComponent.BaseStat.attackRange)) {
                    if (pos.position.x < target.position.x)
                        renderComponent.faceRight();
                    else if (pos.position.x > target.position.x)
                        renderComponent.faceLeft();
                    character.character.startAttack();
                    renderComponent.setRenderState(ATTACK);
                } else
                    character.targetId = -1;
            }
            vectorPool.free(vector);
        } else if (character.targetId == -1 && renderComponent.isInState(ATTACK))
            renderComponent.setRenderState(IDLE);


    character.character.tick(getWorld().getDelta());
}
 
開發者ID:EtherWorks,項目名稱:arcadelegends-gg,代碼行數:79,代碼來源:CharacterSystem.java


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