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