当前位置: 首页>>代码示例>>Java>>正文


Java FastMath.abs方法代码示例

本文整理汇总了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;
    }
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:24,代码来源:BoundingBox.java

示例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;
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:19,代码来源:BoundingSphere.java

示例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));
    }
}
 
开发者ID:NintendoStuff,项目名称:worldcup,代码行数:41,代码来源:PlayerControl.java

示例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;
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:17,代码来源:PerspectiveLodCalculator.java

示例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;
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:42,代码来源:BoundingBox.java

示例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;
        }
    }
}
 
开发者ID:huliqing,项目名称:LuoYing,代码行数:28,代码来源:CollisionChaseCamera.java

示例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);
		}
	}
}
 
开发者ID:rockfireredmoon,项目名称:icetone,代码行数:12,代码来源:ScrollPanel.java

示例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());
}
 
开发者ID:jMonkeyEngine,项目名称:sdk,代码行数:15,代码来源:SpotLightGizmo.java

示例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;
}
 
开发者ID:jMonkeyEngine,项目名称:sdk,代码行数:44,代码来源:LightGizmoFactory.java

示例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;
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:7,代码来源:BoundingBox.java

示例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;
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:7,代码来源:BoundingBox.java

示例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);
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:7,代码来源:BoundingBox.java

示例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();
        }

    }
 
开发者ID:huliqing,项目名称:LuoYing,代码行数:62,代码来源:ClickManager.java

示例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);
}
 
开发者ID:meltzow,项目名称:supernovae,代码行数:5,代码来源:SilentTangentBinormalGenerator.java

示例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;
            }
        }
    }
 
开发者ID:huliqing,项目名称:LuoYing,代码行数:43,代码来源:CollisionChaseCamera.java


注:本文中的com.jme3.math.FastMath.abs方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。