本文整理汇总了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;
}
}
示例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);
}
示例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));
}
示例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;
}
示例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);
}
}
示例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);
}
}
示例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();
}
}
示例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;
}
示例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);
}
示例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);
}
示例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));
}
}
示例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;
}
示例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);
}
示例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();
}
示例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;
}
}