当前位置: 首页>>代码示例>>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;未经允许,请勿转载。