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


Java FastMath.nextRandomFloat方法代碼示例

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


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

示例1: updateAudioApp

import com.jme3.math.FastMath; //導入方法依賴的package包/類
@Override
public void updateAudioApp(float tpf){
    time += tpf;

    if (time > nextTime){
        Vector3f v = new Vector3f();
        v.setX(FastMath.nextRandomFloat());
        v.setY(FastMath.nextRandomFloat());
        v.setZ(FastMath.nextRandomFloat());
        v.multLocal(40, 2, 40);
        v.subtractLocal(20, 1, 20);

        src.setLocalTranslation(v);
        audioRenderer.playSourceInstance(src);
        time = 0;
        nextTime = FastMath.nextRandomFloat() * 2 + 0.5f;
    }
}
 
開發者ID:mleoking,項目名稱:PhET,代碼行數:19,代碼來源:TestReverb.java

示例2: sendDelayedMessages

import com.jme3.math.FastMath; //導入方法依賴的package包/類
private void sendDelayedMessages(){
    ArrayList<Long> removeList = new ArrayList<Long>();
    for (Map.Entry<Long, SyncMessage> entry : latencyQueue.entrySet()){
        if (entry.getKey() > System.currentTimeMillis())
            continue;

        removeList.add(entry.getKey());
        if (packetDropRate > FastMath.nextRandomFloat())
            continue;

        for (Client client : server.getConnectors()){
            try {
                client.send(entry.getValue());
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
    }
    for (Long removeEntry : removeList)
        latencyQueue.remove(removeEntry);
}
 
開發者ID:mleoking,項目名稱:PhET,代碼行數:22,代碼來源:ServerSyncService.java

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

示例4: doDefend

import com.jme3.math.FastMath; //導入方法依賴的package包/類
private boolean doDefend() {
//        LOG.log(Level.INFO, "defendActorLogic==> doDefend actor={0} defendRateAttribute={1}, defendSkill size={2}"
//                , new Object[] {actor.getData().getId(), defendRateAttribute, defendSkills.size()});
        if (defendRateAttribute != null && defendSkills.size() > 0) {
            float defendRate = entityService.getNumberAttributeValue(actor, duckRateAttribute, 0).floatValue();
            if(defendRate >= FastMath.nextRandomFloat()) {
                Skill defendSkill = defendSkills.get(FastMath.nextRandomInt(0, defendSkills.size() - 1));
                
//                skillNetwork.playSkill(actor, defendSkill, false); // remove20161217
                entityNetwork.useObjectData(actor, defendSkill.getData().getUniqueId());
                
                return true;
            }
        }
        return false;
    }
 
開發者ID:huliqing,項目名稱:LuoYing,代碼行數:17,代碼來源:DefendLogic.java

示例5: doDrop

import com.jme3.math.FastMath; //導入方法依賴的package包/類
@Override
public void doDrop(Entity source, Entity target) {
    if (target == null) {
        return;
    }
    if (item == null || count <= 0 || rate <= 0) {
        return;
    }
    
    // 注:如果rate>=1.0, 則忽略其它設置(dropFactor)的影響,把物品視為始終掉落的。
    if (rate >= 1.0f) {
        entityNetwork.addObjectData(target, Loader.loadData(item), count);
        playDropSounds(source);
        return;
    }
    
    // 按機率掉落
    if (rate >= FastMath.nextRandomFloat()) {
        entityNetwork.addObjectData(target, Loader.loadData(item), count);
        playDropSounds(source);
    }
}
 
開發者ID:huliqing,項目名稱:LuoYing,代碼行數:23,代碼來源:ItemDrop.java

示例6: doDrop

import com.jme3.math.FastMath; //導入方法依賴的package包/類
@Override
public void doDrop(Entity source, Entity target) {
    if (skin == null || count <= 0 || rate <= 0) {
        return;
    }
    
    // 注:如果rate>=1.0, 則忽略configService全局掉落設置(dropFactor)的影響,把物品視為始終掉落的。
    if (rate >= 1.0f) {
        entityNetwork.addObjectData(target, Loader.loadData(skin), count);
        playDropSounds(source);
        return;
    }
    
    // 按機率掉落,這個機率受全局掉落設置影響
    if (rate >= FastMath.nextRandomFloat()) {
        entityNetwork.addObjectData(target, Loader.loadData(skin), count);
        playDropSounds(source);
    }
}
 
開發者ID:huliqing,項目名稱:LuoYing,代碼行數:20,代碼來源:SkinDrop.java

示例7: doLogic

import com.jme3.math.FastMath; //導入方法依賴的package包/類
@Override
public void doLogic(float tpf) {
    intervalUsed += tpf;
    
    if (intervalUsed < interval) {
        // 在idle動作執行的間隔要執行一個wait動作,使角色看起來不會像是完全靜止的。
        if (!skillService.isPlayingSkill(actor)) {
            // 注:wait可能不是循環的,所以需要判斷
            if (!skillModule.isWaiting() && waitSkill != null) {
                entityNetwork.useObjectData(actor, waitSkill.getData().getUniqueId());
            }
        }
        return;
    }
    
    Skill idle = getIdleSkill();
    if (idle == null) {
        return;
    }
    
    entityNetwork.useObjectData(actor, idle.getData().getUniqueId());
    
    intervalUsed = 0;
    interval = (intervalMax - intervalMin) * FastMath.nextRandomFloat() + intervalMin;
    if (idle instanceof SimpleAnimationSkill) {
        interval += ((SimpleAnimationSkill)idle).getTrueUseTime();
    }
}
 
開發者ID:huliqing,項目名稱:LuoYing,代碼行數:29,代碼來源:DynamicIdleAction.java

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

示例9: getRandomPoint

import com.jme3.math.FastMath; //導入方法依賴的package包/類
@Override
public void getRandomPoint(Vector3f store) {
    do {
        store.x = (FastMath.nextRandomFloat() * 2f - 1f) * radius;
        store.y = (FastMath.nextRandomFloat() * 2f - 1f) * radius;
        store.z = (FastMath.nextRandomFloat() * 2f - 1f) * radius;
    } while (store.distance(center) > radius);
}
 
開發者ID:mleoking,項目名稱:PhET,代碼行數:9,代碼來源:EmitterSphereShape.java

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

示例11: update

import com.jme3.math.FastMath; //導入方法依賴的package包/類
@Override
public void update(ElementParticle particle, float tpf) {
	if (isEnabled) {
		float incX = FastMath.nextRandomFloat();
		if (FastMath.rand.nextBoolean())
			incX = -incX;
		float incY = FastMath.nextRandomFloat();
		if (FastMath.rand.nextBoolean())
			incY = -incY;
		temp.set(particle.velocity).addLocal(incX, incY);
		particle.velocity.interpolate(temp, (variationStrength));
	}
}
 
開發者ID:rockfireredmoon,項目名稱:icetone,代碼行數:14,代碼來源:ImpulseInfluencer.java

示例12: getRandomPositionInXZPlane

import com.jme3.math.FastMath; //導入方法依賴的package包/類
/**
 * 以原點為中心,在半徑為radius的xz平麵範圍內取一個點
 * @param maxRadius
 * @param store
 * @return 
 */
public static Vector3f getRandomPositionInXZPlane(float maxRadius, Vector3f store) {
    if (store == null) {
        store = new Vector3f();
    }
    TempVars tv = TempVars.get();
   
    float radius = FastMath.nextRandomFloat() * maxRadius;
    float angleInRadian = FastMath.nextRandomFloat() * FastMath.TWO_PI;
    float x = FastMath.cos(angleInRadian) * radius;
    float y = FastMath.sin(angleInRadian) * radius;
    store.set(x, 0, y); // xz平麵
    tv.release();
    return store;
}
 
開發者ID:huliqing,項目名稱:LuoYing,代碼行數:21,代碼來源:MathUtils.java

示例13: startFollow

import com.jme3.math.FastMath; //導入方法依賴的package包/類
private void startFollow(Entity target) {
//        LOG.log(Level.INFO, "Start follow, follower={0}, target={1}"
//                , new Object[] {actor.getData().getId(), target.getData().getId()});
        lastFollow = target;
        
        if (isFighting()) {
            return;
        }
        lastFollowDistance = FastMath.nextRandomFloat() * (maxFollow - minFollow) + minFollow;
        followAction.setFollow(lastFollow.getSpatial());
        followAction.setNearest(lastFollowDistance);
        actionModule.startAction(followAction);
    }
 
開發者ID:huliqing,項目名稱:LuoYing,代碼行數:14,代碼來源:FollowLogic.java

示例14: onSkillStart

import com.jme3.math.FastMath; //導入方法依賴的package包/類
@Override
    public void onSkillStart(Skill skill) {
//        if (Config.debug) {
//            LOG.log(Level.INFO, "defendActorLogic==> onSkillStart, actor={0}, skill={1}", new Object[] {skill.getActor().getData().getId(), skill.getData().getId()});
//        }
        
        if (!hasUsableSkill) 
            return;
        
        // 暫不支持shot類技能的防守
        if (skill instanceof ShotSkill)
            return;
        
        // 不是所偵聽的技能(隻有listenSkillTypes所指定的技能類型才需要防守或躲閃 )
        if ((listenSkillTypes & skill.getTypes()) == 0) 
            return;
        
        // 2.正常防守,隻有普通攻擊技能才允許防守
        if (skill instanceof AttackSkill) {
            AttackSkill aSkill = (AttackSkill) skill;
            if (aSkill.isDefendable()) {
                // 在可防守的技能下給一個機會使用躲閃技能,以避免可能出現的一直使用防守技能的問題。
                if (FastMath.nextRandomFloat() < 0.75f) {
                    if (doDefend()) {
                        return;
                    }
                }
            }
        }
        
        // 3.閃避防守
        if (getSkillModule().isPlayingSkill(duckSkillTypes)) {
            return;
        }
        doDuck();
    }
 
開發者ID:huliqing,項目名稱:LuoYing,代碼行數:37,代碼來源:DefendLogic.java

示例15: update

import com.jme3.math.FastMath; //導入方法依賴的package包/類
public void update(float tpf){
    if (latencyQueue != null)
        sendDelayedMessages();

    if (npcs.size() == 0)
        return;

    time += tpf;
    if (time < updateRate){
        return;
    }else{
        time = 0;
    }

    SyncMessage msg = new SyncMessage();
    msg.setReliable(false); // Purely SYNC message, reliability not needed

    msg.heartbeat = heartbeat;
    synchronized (npcs){
        EntitySyncInfo[] infos = new EntitySyncInfo[npcs.size()];
        msg.infos = infos;
        for (int i = 0; i < npcs.size(); i++){
            SyncEntity entity = npcs.get(i);
            EntitySyncInfo info = generateSyncInfo(entity);
            entity.onLocalUpdate();
            infos[i] = info;
        }
    }

    if (latencyQueue != null){
        long latencyTime = (long) (latency + (FastMath.nextRandomFloat()-0.5f) * latency);
        long timeToSend = System.currentTimeMillis() + latencyTime;
        latencyQueue.put(timeToSend, msg);
    }else{
        for (Client client : server.getConnectors()){
            try {
                client.send(msg); // unreliable
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
    }
    
    heartbeat++;
    if (heartbeat < 0){
        // overflow detected
        heartbeat = 0;
    }
}
 
開發者ID:mleoking,項目名稱:PhET,代碼行數:50,代碼來源:ServerSyncService.java


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