本文整理汇总了Java中com.jme3.math.FastMath.isPowerOfTwo方法的典型用法代码示例。如果您正苦于以下问题:Java FastMath.isPowerOfTwo方法的具体用法?Java FastMath.isPowerOfTwo怎么用?Java FastMath.isPowerOfTwo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.jme3.math.FastMath
的用法示例。
在下文中一共展示了FastMath.isPowerOfTwo方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: TerrainQuad
import com.jme3.math.FastMath; //导入方法依赖的package包/类
protected TerrainQuad(String name, int patchSize, int size,
Vector3f stepScale, float[] heightMap, int totalSize,
Vector2f offset, float offsetAmount,
LodCalculatorFactory lodCalculatorFactory)
{
super(name);
if (!FastMath.isPowerOfTwo(size - 1)) {
throw new RuntimeException("size given: " + size + " Terrain quad sizes may only be (2^N + 1)");
}
if (heightMap == null)
heightMap = generateDefaultHeightMap(size);
this.offset = offset;
this.offsetAmount = offsetAmount;
this.totalSize = totalSize;
this.size = size;
this.patchSize = patchSize;
this.stepScale = stepScale;
this.lodCalculatorFactory = lodCalculatorFactory;
split(patchSize, heightMap);
}
示例2: updateTexImageData
import com.jme3.math.FastMath; //导入方法依赖的package包/类
public void updateTexImageData(Image img, Texture.Type type, boolean mips, int unit) {
int texId = img.getId();
if (texId == -1) {
// create texture
glGenTextures(ib1);
texId = ib1.get(0);
img.setId(texId);
objManager.registerForCleanup(img);
statistics.onNewTexture();
}
// bind texture
int target = convertTextureType(type);
// if (context.boundTextureUnit != unit) {
// glActiveTexture(GL_TEXTURE0 + unit);
// context.boundTextureUnit = unit;
// }
if (context.boundTextures[unit] != img) {
glEnable(target);
glBindTexture(target, texId);
context.boundTextures[unit] = img;
statistics.onTextureUse(img, true);
}
// Check sizes if graphics card doesn't support NPOT
if (!GLContext.getCapabilities().GL_ARB_texture_non_power_of_two) {
if (img.getWidth() != 0 && img.getHeight() != 0) {
if (!FastMath.isPowerOfTwo(img.getWidth())
|| !FastMath.isPowerOfTwo(img.getHeight())
|| img.getWidth() != img.getHeight()) {
// Resize texture to Power-of-2 size
MipMapGenerator.resizeToPowerOf2(img);
}
}
}
if (!img.hasMipmaps() && mips) {
// No pregenerated mips available,
// generate from base level if required
// Check if hardware mips are supported
if (GLContext.getCapabilities().OpenGL14) {
glTexParameteri(target, GL14.GL_GENERATE_MIPMAP, GL_TRUE);
} else {
MipMapGenerator.generateMipMaps(img);
}
} else {
}
/*
if (target == GL_TEXTURE_CUBE_MAP) {
List<ByteBuffer> data = img.getData();
if (data.size() != 6) {
logger.log(Level.WARNING, "Invalid texture: {0}\n"
+ "Cubemap textures must contain 6 data units.", img);
return;
}
for (int i = 0; i < 6; i++) {
TextureUtil.uploadTexture(img, GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, i, 0, tdc);
}
} else if (target == EXTTextureArray.GL_TEXTURE_2D_ARRAY_EXT) {
List<ByteBuffer> data = img.getData();
// -1 index specifies prepare data for 2D Array
TextureUtil.uploadTexture(img, target, -1, 0, tdc);
for (int i = 0; i < data.size(); i++) {
// upload each slice of 2D array in turn
// this time with the appropriate index
TextureUtil.uploadTexture(img, target, i, 0, tdc);
}
} else {*/
TextureUtil.uploadTexture(img, target, 0, 0, false);
//}
img.clearUpdateNeeded();
}
示例3: MidpointDisplacementHeightMap
import com.jme3.math.FastMath; //导入方法依赖的package包/类
/**
* The constructor generates the heightmap. After the first 4 corners are
* randomly given an height, the center will be heighted to the average of
* the 4 corners to which a random value is added. Then other passes fill
* the heightmap by the same principle.
* The random value is generated between the values <code>-range</code>
* and <code>range</code>. The <code>range</code> parameter is multiplied by
* the <code>persistence</code> parameter each pass to smoothen close cell heights.
* Extends this class and override the getOffset function for more control of
* the randomness (you can use the coordinates and/or the computed average height
* to influence the random amount added.
*
* @param size
* The size of the heightmap, must be 2^N+1
* @param range
* The range in which randomness will be added. A value of 1 will
* allow -1 to 1 value changes.
* @param persistence
* The factor by which the range will evolve at each iteration.
* A value of 0.5f will halve the range at each iteration and is
* typically a good choice
* @param seed
* A seed to feed the random number generator.
* @throw JMException if size is not a power of two plus one.
*/
public MidpointDisplacementHeightMap(int size, float range, float persistence, long seed) throws Exception {
if (size < 0 || !FastMath.isPowerOfTwo(size - 1)) {
throw new JMException("The size is negative or not of the form 2^N +1"
+ " (a power of two plus one)");
}
this.size = size;
this.range = range;
this.persistence = persistence;
this.seed = seed;
load();
}
示例4: isNPOT
import com.jme3.math.FastMath; //导入方法依赖的package包/类
/**
* Determine if the image is NPOT.
*
* @return if the image is a non-power-of-2 image, e.g. having dimensions
* that are not powers of 2.
*/
public boolean isNPOT() {
return width != 0 && height != 0
&& (!FastMath.isPowerOfTwo(width) || !FastMath.isPowerOfTwo(height));
}