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


Java FastMath.nextRandomInt方法代碼示例

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


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

示例1: randomizeCube

import com.jme3.math.FastMath; //導入方法依賴的package包/類
/**
     * Randomly Places a cube on the map between 30 and 90 paces away from player
     */
    private void randomizeCube() {
        Geometry cube = fcube.clone();
        int playerX = (int) player.getLocalTranslation().getX();
        int playerZ = (int) player.getLocalTranslation().getZ();
//        float x = FastMath.nextRandomInt(playerX + difficulty + 10, playerX + difficulty + 150);
        float x = FastMath.nextRandomInt(playerX + difficulty + 30, playerX + difficulty + 90);
        float z = FastMath.nextRandomInt(playerZ - difficulty - 50, playerZ + difficulty + 50);
        cube.getLocalTranslation().set(x, 0, z);

//        playerX+difficulty+30,playerX+difficulty+90

        Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        if (!solidBox){
            mat.getAdditionalRenderState().setWireframe(true);
        }
        mat.setColor("Color", obstacleColors.get(FastMath.nextRandomInt(0, obstacleColors.size() - 1)));
        cube.setMaterial(mat);

        rootNode.attachChild(cube);
        cubeField.add(cube);
    }
 
開發者ID:mleoking,項目名稱:PhET,代碼行數:25,代碼來源:CubeField.java

示例2: getRandomPointAndNormal

import com.jme3.math.FastMath; //導入方法依賴的package包/類
/**
 * This method fills the point with coordinates of randomly selected point on a random face.
 * The normal param is filled with selected face's normal.
 * @param store
 *        the variable to store with coordinates of randomly selected selected point on a random face
 * @param normal
 *        filled with selected face's normal
 */
@Override
public void getRandomPointAndNormal(Vector3f store, Vector3f normal) {
    int meshIndex = FastMath.nextRandomInt(0, vertices.size() - 1);
    // the index of the first vertex of a face (must be dividable by 3)
    int faceIndex = FastMath.nextRandomInt(0, vertices.get(meshIndex).size() / 3 - 1);
    int vertIndex = faceIndex * 3;
    // put the point somewhere between the first and the second vertex of a face
    float moveFactor = FastMath.nextRandomFloat();
    store.set(Vector3f.ZERO);
    store.addLocal(vertices.get(meshIndex).get(vertIndex));
    store.addLocal((vertices.get(meshIndex).get(vertIndex + 1).x - vertices.get(meshIndex).get(vertIndex).x) * moveFactor, (vertices.get(meshIndex).get(vertIndex + 1).y - vertices.get(meshIndex).get(vertIndex).y) * moveFactor, (vertices.get(meshIndex).get(vertIndex + 1).z - vertices.get(meshIndex).get(vertIndex).z) * moveFactor);
    // move the result towards the last face vertex
    moveFactor = FastMath.nextRandomFloat();
    store.addLocal((vertices.get(meshIndex).get(vertIndex + 2).x - store.x) * moveFactor, (vertices.get(meshIndex).get(vertIndex + 2).y - store.y) * moveFactor, (vertices.get(meshIndex).get(vertIndex + 2).z - store.z) * moveFactor);
    normal.set(normals.get(meshIndex).get(faceIndex));
}
 
開發者ID:mleoking,項目名稱:PhET,代碼行數:25,代碼來源:EmitterMeshFaceShape.java

示例3: createInner

import com.jme3.math.FastMath; //導入方法依賴的package包/類
private static String createInner(String prefix, int loopCount) {
    loopCount++;
    String suffix = suffixes[FastMath.nextRandomInt(0, suffixes.length - 1)];
    String temp = prefix + suffix;
    
    // 一般最多loop 2-3次就可以找到一個合適的名字,無限loop的可能性幾乎不存在.
    // 這個限製隻是為了萬一,比如人為設置的prefix和suffix可選太少,則有可能發生。
    if (loopCount > 5) {
        return temp;
    }
    
    // 如果隻有2個字,則直接返回.
    if (temp.length() <= 2) {
        return temp;
    } else {
        // 如果大於或等於3個字,則後綴中的字符不能與前綴中的字符重複
        for (int i = 0; i < suffix.length(); i++) {
            if (prefix.indexOf(suffix.charAt(i)) != -1) {
                // 如果後綴中存在字符與前綴相同,則重新獲取。
                return createInner(prefix, loopCount);
            }
        }
    }
    return temp;
}
 
開發者ID:huliqing,項目名稱:LuoYing,代碼行數:26,代碼來源:NpcNameUtils.java

示例4: getSkill

import com.jme3.math.FastMath; //導入方法依賴的package包/類
/**
 * 獲取一個可以用的fight技能
 * @return 
 */
private Skill getSkill() {
    if (fightSkills.isEmpty()) {
        return null;
    }
    int startIndex = FastMath.nextRandomInt(0, fightSkills.size() - 1);
    Skill result;
    for (int i = startIndex;;) {
        result = fightSkills.get(i);
        if (!result.isCooldown() 
                && result.isPlayableByAttributeLimit() 
                && result.isPlayableByElCheck()) {
            return result;
        }
        i++;
        // 達到list最後則i重新從0開始。
        if (i >= fightSkills.size()) {
            i = 0;
        }
        // 繞了一個loop,如果還沒有適合的技能,則返回null.
        if (i == startIndex) {
            return null;
        }
    }
}
 
開發者ID:huliqing,項目名稱:LuoYing,代碼行數:29,代碼來源:DynamicFightAction.java

示例5: emitParticle

import com.jme3.math.FastMath; //導入方法依賴的package包/類
private boolean emitParticle(Vector3f min, Vector3f max) {
//        int idx = newIndex();
//        if (idx == -1)
//            return false;
        int idx = lastUsed + 1;
        if (idx >= particles.length) {
            return false;
        }

        Particle p = particles[idx];
        if (selectRandomImage) {
            p.imageIndex = FastMath.nextRandomInt(0, imagesY - 1) * imagesX + FastMath.nextRandomInt(0, imagesX - 1);
        }

        p.startlife = lowLife + FastMath.nextRandomFloat() * (highLife - lowLife);
        p.life = p.startlife;
        p.color.set(startColor);
        p.size = startSize;
        //shape.getRandomPoint(p.position);
        particleInfluencer.influenceParticle(p, shape);
        if (worldSpace) {
            p.position.addLocal(worldTransform.getTranslation());
        }
        if (randomAngle) {
            p.angle = FastMath.nextRandomFloat() * FastMath.TWO_PI;
        }
        if (rotateSpeed != 0) {
            p.rotateSpeed = rotateSpeed * (0.2f + (FastMath.nextRandomFloat() * 2f - 1f) * .8f);
        }

        temp.set(p.position).addLocal(p.size, p.size, p.size);
        max.maxLocal(temp);
        temp.set(p.position).subtractLocal(p.size, p.size, p.size);
        min.minLocal(temp);

        ++lastUsed;
        firstUnUsed = idx + 1;
        return true;
    }
 
開發者ID:mleoking,項目名稱:PhET,代碼行數:40,代碼來源:ParticleEmitter.java

示例6: getRandomPoint

import com.jme3.math.FastMath; //導入方法依賴的package包/類
/**
 * This method fills the point with coordinates of randomly selected mesh vertex.
 * @param store
 *        the variable to store with coordinates of randomly selected mesh vertex
 */
@Override
public void getRandomPoint(Vector3f store) {
    int meshIndex = FastMath.nextRandomInt(0, vertices.size() - 1);
    int vertIndex = FastMath.nextRandomInt(0, vertices.get(meshIndex).size() - 1);
    store.set(vertices.get(meshIndex).get(vertIndex));
}
 
開發者ID:mleoking,項目名稱:PhET,代碼行數:12,代碼來源:EmitterMeshVertexShape.java

示例7: getRandomPoint

import com.jme3.math.FastMath; //導入方法依賴的package包/類
/**
 * This method fills the point with coordinates of randomly selected point on a random face.
 * @param store
 *        the variable to store with coordinates of randomly selected selected point on a random face
 */
@Override
public void getRandomPoint(Vector3f store) {
    int meshIndex = FastMath.nextRandomInt(0, vertices.size() - 1);
    // the index of the first vertex of a face (must be dividable by 3)
    int vertIndex = FastMath.nextRandomInt(0, vertices.get(meshIndex).size() / 3 - 1) * 3;
    // put the point somewhere between the first and the second vertex of a face
    float moveFactor = FastMath.nextRandomFloat();
    store.set(Vector3f.ZERO);
    store.addLocal(vertices.get(meshIndex).get(vertIndex));
    store.addLocal((vertices.get(meshIndex).get(vertIndex + 1).x - vertices.get(meshIndex).get(vertIndex).x) * moveFactor, (vertices.get(meshIndex).get(vertIndex + 1).y - vertices.get(meshIndex).get(vertIndex).y) * moveFactor, (vertices.get(meshIndex).get(vertIndex + 1).z - vertices.get(meshIndex).get(vertIndex).z) * moveFactor);
    // move the result towards the last face vertex
    moveFactor = FastMath.nextRandomFloat();
    store.addLocal((vertices.get(meshIndex).get(vertIndex + 2).x - store.x) * moveFactor, (vertices.get(meshIndex).get(vertIndex + 2).y - store.y) * moveFactor, (vertices.get(meshIndex).get(vertIndex + 2).z - store.z) * moveFactor);
}
 
開發者ID:mleoking,項目名稱:PhET,代碼行數:20,代碼來源:EmitterMeshFaceShape.java

示例8: createFemale

import com.jme3.math.FastMath; //導入方法依賴的package包/類
/**
 * 生成一個女性隨機名字.
 */
public static String createFemale() {
    if (!init) {
        prefixes = ResManager.get("npc.name.prefix").split(",");
        suffixes = ResManager.get("npc.name.suffix").split(",");
        init = true;
    }
    String prefix = prefixes[FastMath.nextRandomInt(0, prefixes.length - 1)];
    return createInner(prefix, 0);
}
 
開發者ID:huliqing,項目名稱:LuoYing,代碼行數:13,代碼來源:NpcNameUtils.java

示例9: getRandomSprite

import com.jme3.math.FastMath; //導入方法依賴的package包/類
private TextureRegion getRandomSprite(ElementParticle particle) {
	currentIndex = FastMath.nextRandomInt(0, emitter.particles.getTextureRegions().size() - 1);
	particle.putData("currentIndex", currentIndex);
	return emitter.particles.getTextureRegion("sprite" + currentIndex);
}
 
開發者ID:rockfireredmoon,項目名稱:icetone,代碼行數:6,代碼來源:SpriteInfluencer.java

示例10: getRandomSpriteFromRange

import com.jme3.math.FastMath; //導入方法依賴的package包/類
private TextureRegion getRandomSpriteFromRange(ElementParticle particle) {
	currentIndex = FastMath.nextRandomInt(0, spriteOrder.length - 1);
	particle.putData("currentIndex", currentIndex);
	return emitter.particles.getTextureRegion("sprite" + spriteOrder[currentIndex]);
}
 
開發者ID:rockfireredmoon,項目名稱:icetone,代碼行數:6,代碼來源:SpriteInfluencer.java

示例11: getRandomName

import com.jme3.math.FastMath; //導入方法依賴的package包/類
private String getRandomName() {
    if (randomNames == null) {
        randomNames = ResourceManager.get("npc.name.full").split(",");
    }
    return randomNames[FastMath.nextRandomInt(0, randomNames.length - 1)];
}
 
開發者ID:huliqing,項目名稱:LuoYing,代碼行數:7,代碼來源:ActorSelectView.java

示例12: initialize

import com.jme3.math.FastMath; //導入方法依賴的package包/類
@Override
    public void initialize() {
        super.initialize();
        skillModule = actor.getModule(SkillModule.class);
        
        // 初始化巡邏點坐標,如果沒有指別設置角色的出生地點則將當前世界位置作為巡邏
        // 的原點,並在這個原點上向四周生成幾個巡邏坐標點。
        if (idlePositions == null) {
            if (bornPlace == null) {
                bornPlace = new Vector3f(actor.getSpatial().getWorldTranslation());
            }
            patrolOrgin.set(bornPlace);
            // 生成可用idle坐標點.
            // 邏輯:隨機在角色原始坐標的周圍生成幾個idle坐標點.
            idlePositions = new ArrayList<Vector3f>(walkPosTotal);
            int angle = 360 / walkPosTotal;
            int startAngle = FastMath.nextRandomInt(0, 180);
            Vector3f startPoint = new Vector3f(0, 0, walkRadius);
            Quaternion quater = new Quaternion();
            idlePositions.add(patrolOrgin.clone());
            for (int i = 0; i < walkPosTotal; i++) {
                quater.fromAngleAxis((startAngle + angle * i) * FastMath.DEG_TO_RAD
                        , Vector3f.UNIT_Y.clone());
                Vector3f pos = quater.mult(startPoint);
                idlePositions.add(pos.addLocal(patrolOrgin));
            }
            currentPos = idlePositions.get(FastMath.nextRandomInt(0, idlePositions.size() - 1));
            
            // debug
//            DebugUtils.debugPoints(idlePositions, actor.getActor().getParent());
        }
        
        rayDetour.setActor(actor);
        rayDetour.setAutoFacing(true);
        rayDetour.setUseRun(false);

        List<Skill> waitSkills = skillModule.getSkillWait(null);
        if (waitSkills != null && !waitSkills.isEmpty()) {
            waitSkill = waitSkills.get(0);
        }
        List<Skill> walkSkills = skillModule.getSkillWalk(null);
        if (walkSkills != null && !walkSkills.isEmpty()) {
            walkSkill = walkSkills.get(0);
        }
        List<Skill> runSkills = skillModule.getSkillRun(null);
        if (runSkills != null && !runSkills.isEmpty()) {
            runSkill = runSkills.get(0);
        }
        
        // 緩存IDLE技能並添加偵聽器
        recacheIdleSkill();
        
        actor.addDataListener(this);
    }
 
開發者ID:huliqing,項目名稱:LuoYing,代碼行數:55,代碼來源:PatrolIdleAction.java

示例13: getRandomPointAndNormal

import com.jme3.math.FastMath; //導入方法依賴的package包/類
/**
 * This method fills the point with coordinates of randomly selected mesh vertex.
 * The normal param is filled with selected vertex's normal.
 * @param store
 *        the variable to store with coordinates of randomly selected mesh vertex
 * @param normal
 *        filled with selected vertex's normal
 */
@Override
public void getRandomPointAndNormal(Vector3f store, Vector3f normal) {
    int meshIndex = FastMath.nextRandomInt(0, vertices.size() - 1);
    int vertIndex = FastMath.nextRandomInt(0, vertices.get(meshIndex).size() - 1);
    store.set(vertices.get(meshIndex).get(vertIndex));
    normal.set(normals.get(meshIndex).get(vertIndex));
}
 
開發者ID:mleoking,項目名稱:PhET,代碼行數:16,代碼來源:EmitterMeshVertexShape.java

示例14: randomPON

import com.jme3.math.FastMath; //導入方法依賴的package包/類
/**
 * 隨機取數-1或1, 該方法要不返回-1,要不返回1(randomPositiveOrNegative)
 * @return 
 */
public static int randomPON() {
    return POSITIVE_OR_NEGATIVE[FastMath.nextRandomInt(0, 1)];
}
 
開發者ID:huliqing,項目名稱:LuoYing,代碼行數:8,代碼來源:MathUtils.java


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