本文整理汇总了Java中com.jme3.math.FastMath.clamp方法的典型用法代码示例。如果您正苦于以下问题:Java FastMath.clamp方法的具体用法?Java FastMath.clamp怎么用?Java FastMath.clamp使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.jme3.math.FastMath
的用法示例。
在下文中一共展示了FastMath.clamp方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setScrollAreaPositionTo
import com.jme3.math.FastMath; //导入方法依赖的package包/类
private void setScrollAreaPositionTo(float relativeScrollAmount, Orientation orientation) {
relativeScrollAmount = FastMath.clamp(relativeScrollAmount, 0, 1);
if (orientation == Orientation.VERTICAL) {
float lastY = scrollableArea.getY();
float newY = Math.round(-(getVerticalScrollDistance() * relativeScrollAmount));
if (lastY != newY) {
scrollableArea.setY(newY);
if (lastY > -(getVerticalScrollDistance() * relativeScrollAmount))
onScrollContent(ScrollDirection.Up);
else
onScrollContent(ScrollDirection.Down);
}
} else {
float lastX = scrollableArea.getX();
float newX = Math.min(0, Math.round(-(getHorizontalScrollDistance() * relativeScrollAmount)));
if (lastX != newX) {
scrollableArea.setX(newX);
if (lastX < -(getHorizontalScrollDistance() * relativeScrollAmount))
onScrollContent(ScrollDirection.Left);
else
onScrollContent(ScrollDirection.Right);
}
}
}
示例2: onMouseMotionEvent
import com.jme3.math.FastMath; //导入方法依赖的package包/类
public void onMouseMotionEvent(MouseMotionEvent evt) {
x += evt.getDX();
y += evt.getDY();
// Prevent mouse from leaving screen
AppSettings settings = TestSoftwareMouse.this.settings;
x = FastMath.clamp(x, 0, settings.getWidth());
y = FastMath.clamp(y, 0, settings.getHeight());
// adjust for hotspot
cursor.setPosition(x, y - 64);
}
示例3: computeAnalogValue
import com.jme3.math.FastMath; //导入方法依赖的package包/类
private float computeAnalogValue(long timeDelta) {
if (safeMode || frameDelta == 0) {
return 1f;
} else {
return FastMath.clamp((float) timeDelta / (float) frameDelta, 0, 1);
}
}
示例4: getColor
import com.jme3.math.FastMath; //导入方法依赖的package包/类
private Color getColor(String r, String g, String b, String a) {
try {
float fr = FastMath.clamp(Float.parseFloat(r), 0, 1);
float fg = FastMath.clamp(Float.parseFloat(g), 0, 1);
float fb = FastMath.clamp(Float.parseFloat(b), 0, 1);
float fa = FastMath.clamp(Float.parseFloat(a), 0, 1);
return new Color(fr, fg, fb, fa);
} catch (NumberFormatException e) {
return null;
}
}
示例5: fixTimePointByCutTime
import com.jme3.math.FastMath; //导入方法依赖的package包/类
/**
* 重新计算受cutTime影响的时间插值点。
* @param interpolation 原始的时间插值点(未受cutTime影响的时间插值)
* @return 经过cutTime计算后的实际的时间插值点
*/
protected float fixTimePointByCutTime(float interpolation) {
// float cutTimeStart = data.getCutTimeStart();
// float cutTimeEnd = data.getCutTimeEnd();
float cutTimeStart = 0;
float cutTimeEnd = 0;
float result = FastMath.clamp((interpolation - cutTimeStart) / (1.0f - cutTimeStart - cutTimeEnd)
, 0f, 1.0f);
return result;
}
示例6: toJfxColor
import com.jme3.math.FastMath; //导入方法依赖的package包/类
private Color toJfxColor(ColorRGBA jmeColor) {
if (jmeColor == null) {
return new Color(1,1,1,1);
}
return new Color(FastMath.clamp(jmeColor.r, 0, 1)
, FastMath.clamp(jmeColor.g, 0, 1)
, FastMath.clamp(jmeColor.b, 0, 1)
, FastMath.clamp(jmeColor.a, 0, 1));
}
示例7: apply
import com.jme3.math.FastMath; //导入方法依赖的package包/类
@Override
public float apply (float a) {
return FastMath.clamp(a * a * a * (a * (a * 6 - 15) + 10), 0, 1);
}
示例8: setAngle
import com.jme3.math.FastMath; //导入方法依赖的package包/类
public void setAngle(float ang) {
angles[1] = ang;
angles[1] = FastMath.clamp(angles[1], minAngle, maxAngle);
quat.fromAngles(angles);
node.setLocalRotation(quat);
}
示例9: update
import com.jme3.math.FastMath; //导入方法依赖的package包/类
@Override
public void update(float tpf) {
if (!enabled) {
return;
}
super.update(tpf);
if (velocity > 0 && holding.size() > 0) {
release();
}
if (holding.size() > 0) {
velocity = 0;
return;
}
// check holding objects
float maxDiff = opening * FastMath.tan(FastMath.QUARTER_PI / 4);
for (Entry<Float, Spatial> e1 : leftContacts.entrySet()) {
for (Entry<Float, Spatial> e2 : rightContacts.entrySet()) {
if (e1.getValue() != e2.getValue()) {
continue;
}
if (FastMath.abs(e1.getKey() - e2.getKey()) > maxDiff) {
continue;
}
Spatial s = e1.getValue();
if (holding.contains(s)) {
continue;
}
MyRigidBodyControl rbc = s.getControl(MyRigidBodyControl.class);
if (rbc == null || rbc.getMass() == 0 || rbc.isKinematic()) {
continue;
}
hold(s);
logger.log(Level.INFO, "hold");
}
}
if ((leftContacts.size() > 0 || rightContacts.size() > 0) && holding.size() <= 0) {
logger.log(Level.INFO, "cannot hold: {0}", maxDiff);
}
leftContacts.clear();
rightContacts.clear();
if (velocity != 0) {
if (velocity < 0) {
float impulse = -velocity * tpf * FINGER_MASS * 2;
impulse -= fingerPressure;
float offset = impulse / (FINGER_MASS * 2);
offset = FastMath.clamp(offset, 0, offset);
opening -= offset;
checkDigitCollision = true;
} else {
opening += velocity * tpf;
checkDigitCollision = false;
}
opening = FastMath.clamp(opening, 0, Gripper.MAX_OPENING);
// update finger opeining
Vector3f v = leftFinger.getLocalTranslation();
v.x = -opening / 2 - Gripper.FINGER_SIZE.x / 2;
leftFinger.setLocalTranslation(v);
v = rightFinger.getLocalTranslation();
v.x = opening / 2 + Gripper.FINGER_SIZE.x / 2;
rightFinger.setLocalTranslation(v);
fingerPressure = 0;
velocity = 0;
} else {
checkDigitCollision = false;
}
}
示例10: setData
import com.jme3.math.FastMath; //导入方法依赖的package包/类
@Override
public void setData(SkillData data) {
super.setData(data);
timePoint = FastMath.clamp(data.getAsFloat("timePoint", timePoint), 0, 1.0f);
}
示例11: setTime
import com.jme3.math.FastMath; //导入方法依赖的package包/类
/**
* @param time Set the time of the currently playing animation, the time
* is clamped from 0 to getAnimMaxTime().
*/
public void setTime(float time) {
this.time = FastMath.clamp(time, 0, getAnimMaxTime());
}