本文整理匯總了Java中com.jme3.math.FastMath.abs方法的典型用法代碼示例。如果您正苦於以下問題:Java FastMath.abs方法的具體用法?Java FastMath.abs怎麽用?Java FastMath.abs使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.jme3.math.FastMath
的用法示例。
在下文中一共展示了FastMath.abs方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: whichSide
import com.jme3.math.FastMath; //導入方法依賴的package包/類
/**
* <code>whichSide</code> takes a plane (typically provided by a view
* frustum) to determine which side this bound is on.
*
* @param plane
* the plane to check against.
*/
public Plane.Side whichSide(Plane plane) {
float radius = FastMath.abs(xExtent * plane.getNormal().getX())
+ FastMath.abs(yExtent * plane.getNormal().getY())
+ FastMath.abs(zExtent * plane.getNormal().getZ());
float distance = plane.pseudoDistance(center);
//changed to < and > to prevent floating point precision problems
if (distance < -radius) {
return Plane.Side.Negative;
} else if (distance > radius) {
return Plane.Side.Positive;
} else {
return Plane.Side.None;
}
}
示例2: getMaxAxis
import com.jme3.math.FastMath; //導入方法依賴的package包/類
private float getMaxAxis(Vector3f scale) {
float x = FastMath.abs(scale.x);
float y = FastMath.abs(scale.y);
float z = FastMath.abs(scale.z);
if (x >= y) {
if (x >= z) {
return x;
}
return z;
}
if (y >= z) {
return y;
}
return z;
}
示例3: controlUpdate
import com.jme3.math.FastMath; //導入方法依賴的package包/類
@Override
protected void controlUpdate(final float tpf) {
// check rotation
final float rotation = spatial.getWorldRotation().toAngles(null)[1] * FastMath.RAD_TO_DEG;
final float dist = FastMath.abs(direction.getAngle() - rotation);
if (dist > 10f) {
spatial.rotate(0f, direction.getRotation() * tpf * 15f, 0f);
} else {
spatial.lookAt(spatial.getWorldTranslation().add(0f, 0f, direction.getRotation()), Vector3f.UNIT_Y);
}
// get sprite and its control
final AnimatedSprite animatedSprite = (AnimatedSprite) ((Node) spatial).getChild(0);
final AnimatedSpriteControl animatedSpriteControl = animatedSprite.getControl(AnimatedSpriteControl.class);
// handle 'halt'
if (!up && !down && !right && !left) {
animatedSpriteControl.setAnimation("idle");
return;
}
// handle 'walk'
animatedSpriteControl.setAnimation("walk");
final Vector3f move = new Vector3f();
if (up) {
move.z = -1;
}
if (down) {
move.z = 1;
}
if (right) {
move.x = 1;
}
if (left) {
move.x = -1;
}
if (!move.equals(Vector3f.ZERO)) {
spatial.move(move.mult(tpf * 20f));
}
}
示例4: getCameraConstant
import com.jme3.math.FastMath; //導入方法依賴的package包/類
/**
* This computes the "C" value in the geomipmapping paper.
* See section "2.3.1.2 Pre-calculating d"
*
* @param cam
* @param pixelLimit
* @return
*/
private float getCameraConstant(Camera cam, float pixelLimit){
float n = cam.getFrustumNear();
float t = FastMath.abs(cam.getFrustumTop());
float A = n / t;
float v_res = cam.getHeight();
float T = (2f * pixelLimit) / v_res;
return A / T;
}
示例5: transform
import com.jme3.math.FastMath; //導入方法依賴的package包/類
/**
* <code>transform</code> modifies the center of the box to reflect the
* change made via a rotation, translation and scale.
*
* @param trans
* the transform to apply
* @param store
* box to store result in
*/
public BoundingVolume transform(Transform trans, BoundingVolume store) {
BoundingBox box;
if (store == null || store.getType() != Type.AABB) {
box = new BoundingBox();
} else {
box = (BoundingBox) store;
}
center.mult(trans.getScale(), box.center);
trans.getRotation().mult(box.center, box.center);
box.center.addLocal(trans.getTranslation());
TempVars vars = TempVars.get();
Matrix3f transMatrix = vars.tempMat3;
transMatrix.set(trans.getRotation());
// Make the rotation matrix all positive to get the maximum x/y/z extent
transMatrix.absoluteLocal();
Vector3f scale = trans.getScale();
vars.vect1.set(xExtent * scale.x, yExtent * scale.y, zExtent * scale.z);
transMatrix.mult(vars.vect1, vars.vect2);
// Assign the biggest rotations after scales.
box.xExtent = FastMath.abs(vars.vect2.getX());
box.yExtent = FastMath.abs(vars.vect2.getY());
box.zExtent = FastMath.abs(vars.vect2.getZ());
vars.release();
return box;
}
示例6: onTouch
import com.jme3.math.FastMath; //導入方法依賴的package包/類
@Override
public void onTouch(String name, TouchEvent event, float tpf) {
if (event.getType() == TouchEvent.Type.SCALE_MOVE && TOUCH_SCALE_EVENT.equals(name)) {
float dss = event.getDeltaScaleSpan();
// 縮放太小就不處理了,否則有可能兩個手指放上去時畫麵一直在抖動。
if (FastMath.abs(dss) < 0.01f) {
return;
}
// 縮放鏡頭: * 0.25 降低一點縮放強度
zoomCamera(-dss * 0.1f);
if (dss > 0) {
// 拉近,放大 (參考:ChaseCamera中onAnalog方法)
if (zoomin == false) {
distanceLerpFactor = 0;
}
zoomin = true;
} else {
// 拉遠,縮小
if (zoomin == true) {
distanceLerpFactor = 0;
}
zoomin = false;
}
}
}
示例7: onFling
import com.jme3.math.FastMath; //導入方法依賴的package包/類
@Override
public void onFling(TouchEvent evt) {
if (flingEnabled && (evt.getDeltaY() > 0.2f || evt.getDeltaY() < -0.2f)) {
if (!screen.getAnimManager().hasGameTimer(flingTimer)) {
flingTimer.reset(false);
flingDir = (evt.getDeltaY() < 0) ? true : false;
flingSpeed = FastMath.abs(evt.getDeltaY());
screen.getAnimManager().addGameTimer(flingTimer);
}
}
}
示例8: onResize
import com.jme3.math.FastMath; //導入方法依賴的package包/類
@Override
public void onResize(Vector3f oldScale, Vector3f newScale) {
float x = FastMath.abs(newScale.x);
float y = FastMath.abs(newScale.y);
float z = FastMath.abs(newScale.z);
light.setSpotRange(y);
light.setSpotInnerAngle(x);
light.setSpotOuterAngle(z);
jmeLight.setValue("spotInnerAngle", light.getSpotInnerAngle());
jmeLight.setValue("spotOuterAngle", light.getSpotOuterAngle());
jmeLight.setValue("spotRange", light.getSpotRange());
}
示例9: scaleToRadius
import com.jme3.math.FastMath; //導入方法依賴的package包/類
/**
* Helper Method to convert a Vector3f Scale into a radius. This is required,
* because the Gizmos are scaled like regular jME Nodes.
*
* Note: In case of non-uniform scaling, the code picks the minimum or maximum
* of all three components.
*
* @param scale The Scale to convert
* @return The Radius
*/
protected static float scaleToRadius(Vector3f scale) {
final float eps = 0.0000125f;
float m;
float x = FastMath.abs(scale.x);
float y = FastMath.abs(scale.y);
float z = FastMath.abs(scale.z);
float max = Math.max(Math.max(x, y), z);
float min = Math.min(Math.min(x, y), z);
if (max - min <= eps) {
// x == y == z
m = x;
} else {
int nbMax = 0;
if (max - x <= eps) {
nbMax++;
}
if (max - y <= eps) {
nbMax++;
}
if (max - z <= eps) {
nbMax++;
}
if (nbMax >= 2) {
m = min;
} else {
m = max;
}
}
return m;
}
示例10: contains
import com.jme3.math.FastMath; //導入方法依賴的package包/類
@Override
public boolean contains(Vector3f point) {
return FastMath.abs(center.x - point.x) < xExtent
&& FastMath.abs(center.y - point.y) < yExtent
&& FastMath.abs(center.z - point.z) < zExtent;
}
示例11: intersects
import com.jme3.math.FastMath; //導入方法依賴的package包/類
@Override
public boolean intersects(Vector3f point) {
return FastMath.abs(center.x - point.x) <= xExtent
&& FastMath.abs(center.y - point.y) <= yExtent
&& FastMath.abs(center.z - point.z) <= zExtent;
}
示例12: setMinMax
import com.jme3.math.FastMath; //導入方法依賴的package包/類
public void setMinMax(Vector3f min, Vector3f max) {
this.center.set(max).addLocal(min).multLocal(0.5f);
xExtent = FastMath.abs(max.x - center.x);
yExtent = FastMath.abs(max.y - center.y);
zExtent = FastMath.abs(max.z - center.z);
}
示例13: fireEvent
import com.jme3.math.FastMath; //導入方法依賴的package包/類
public void fireEvent(UI ui, boolean isPressed) {
if (!ui.hasClickEvent() && !ui.hasDBClickEvent()) {
return;
}
// 按下事件應該直接執行
if (isPressed) {
clickPressTime = LuoYing.getGameTime();
lastCursorPosition.set(LuoYing.getCursorPosition());
pressUI = ui;
pressUI.fireClick(true);
fireUIClickListener(pressUI, true, false);
return;
}
// ==== 鼠標釋放時 ====
// 1.如果鼠標放開時的UI與鼠標按下時的UI不一致,則忽略點擊
if (ui != pressUI) {
return;
}
// 2.當鼠標按下太久時,不認為是點擊或雙擊事件.
// Logger.get(UIClickManager.class).log(Level.INFO, "click time={0}", (Common.getCurrentTime() - clickPressTime));
if (LuoYing.getGameTime() - clickPressTime > clickPressTimeLimit) {
return;
}
// 3.如果鼠標放開時的位置偏移過大,則忽略點擊
Vector2f cursorPosition = LuoYing.getCursorPosition();
float xMove = FastMath.abs(cursorPosition.x - lastCursorPosition.x);
float yMove = FastMath.abs(cursorPosition.y - lastCursorPosition.y);
if ((xMove > clickMoveLimit || yMove > clickMoveLimit)) {
return;
}
// 4.如果是雙擊事件,則直接啟動(單擊事件需要延遲一定時間,以等待確認是否為雙擊,因為雙擊事件優先)
if (releaseUI == ui && LuoYing.getGameTime() - clickReleaseTime <= dbclickLimit) {
releaseUI.fireDBClick(isPressed);
fireUIClickListener(releaseUI, isPressed, true);
releaseUI = null;
clickReleaseTime = 0;
return;
}
// 如果是單擊事件,則視情況:若該UI不存在雙擊事件,則直接執行單擊事件,
// 否則延遲執行
if (!ui.hasDBClickEvent()) {
// 播放點擊聲效
UISound.playClick(ui);
ui.fireClick(false);
fireUIClickListener(ui, false, false);
} else {
releaseUI = ui;
clickReleaseTime = LuoYing.getGameTime();
}
}
示例14: approxEqual
import com.jme3.math.FastMath; //導入方法依賴的package包/類
private static boolean approxEqual(Vector2f u, Vector2f v) {
float tolerance = 1E-4f;
return (FastMath.abs(u.x - v.x) < tolerance) && (FastMath.abs(u.y - v.y) < tolerance);
}
示例15: update
import com.jme3.math.FastMath; //導入方法依賴的package包/類
@Override
public void update(float tpf) {
super.update(tpf);
if (!enabled || !physicsEnabled) {
return;
}
if (collisionChecker.getParent() == null) {
if (target != null) {
Spatial rootParent = getRoot(target);
if (rootParent instanceof Node) {
((Node) rootParent).attachChild(collisionChecker);
}
}
}
// 1.讓collisionChecker與相機位置保持一致.
Vector3f loc = collisionChecker.getLocalTranslation();
Vector3f camLoc = cam.getLocation();
if (FastMath.abs(loc.x - camLoc.x) > 0.0001f
|| FastMath.abs(loc.y - camLoc.y) > 0.0001f
|| FastMath.abs(loc.z - camLoc.z) > 0.0001f) {
collisionChecker.setLocalTranslation(cam.getLocation());
}
// 2.防止相機穿牆,當collisionTarget不為null時說明相機已經與某些物體發生碰撞,這時需要償試調整相機的位置。
if (collisionTarget != null) {
// LOG.log(Level.INFO, "CollisionChaseCamera, Need to fix collision with={0}", new Object[] {collisionTarget});
// fixingCameraDistance方法用於拉近相機,以避免穿牆,這是一個持續的過程,如果該方法返回true,則說明正在持續
// 修正(拉近)相機距離,這時不能釋放collisionTarget, 因為該方法的修正會在下一幀被ChaseCamera的默認行為重置,
// 所以這個方法必須持續進行,直到相機不產生碰撞才能釋放。
if (fixingCameraDistance(collisionTarget)) {
collisionChecker.setLocalTranslation(cam.getLocation());
} else {
// 當該方法返回false時,說明相機已經不會碰撞到其它物體,則可
// 釋放collisionTarget,即不再需要修正距離。
collisionTarget = null;
}
}
}