本文整理汇总了Java中com.badlogic.gdx.math.MathUtils.isEqual方法的典型用法代码示例。如果您正苦于以下问题:Java MathUtils.isEqual方法的具体用法?Java MathUtils.isEqual怎么用?Java MathUtils.isEqual使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.badlogic.gdx.math.MathUtils
的用法示例。
在下文中一共展示了MathUtils.isEqual方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onUpdate
import com.badlogic.gdx.math.MathUtils; //导入方法依赖的package包/类
@Override
public void onUpdate(float deltaTime)
{
if (!MathUtils.isZero(hitTimer))
{
hitTimer -= deltaTime;
if (hitTimer <= 0f)
hitTimer = 0f;
}
if (attackTimer > 0f)
attackTimer -= deltaTime;
if (handler.canAttack())
{
if (attackTimer <= 0f)
{
attackTimer = 1.6f;
handler.attack(3);
}
}
bodyPosition = body.getPosition();
if (body.getLinearVelocity().sub(direction).len2() > 1 || (MathUtils.isEqual(oldPosition.x, bodyPosition.x) && MathUtils.isEqual(oldPosition.y, bodyPosition.y)))
{
direction.set(MathUtils.random(-1f, 1f), MathUtils.random(-1f, 1f));
direction.scl(4f);
}
oldPosition = bodyPosition;
body.applyForceToCenter(direction, true);
}
示例2: checkCollisions
import com.badlogic.gdx.math.MathUtils; //导入方法依赖的package包/类
/** Check for collisions between two colliders */
private boolean checkCollisions(Collider a, Collider b){
// Ignore collisions between objects with infinite mass
if(MathUtils.isEqual(a.im, 0) && MathUtils.isEqual(b.im, 0)){
return false;
}else if((filter == null || filter.collide(a, b)) && a.isOverlapping(b)){
if(listener != null){
listener.onContact(a, b);
listener.onContact(b, a);
}
//don't add a contact for triggers
if(a.trigger || b.trigger){
return true;
}else{
//Get a manifold from the pool and add it
Manifold c = Pools.obtain(Manifold.class).set(a, b);
if(c.solve()){
contacts.add(c);
return true;
}
}
}
return false;
}
示例3: onLine
import com.badlogic.gdx.math.MathUtils; //导入方法依赖的package包/类
/**Returns whether a point is on a line.*/
private static boolean onLine(Vector2 vector, float x1, float y1, float x2, float y2){
return MathUtils.isEqual(vector.dst(x1, y1) + vector.dst(x2, y2), Vector2.dst(x1, y1, x2, y2), 0.01f);
}
示例4: solve
import com.badlogic.gdx.math.MathUtils; //导入方法依赖的package包/类
/**
* Solve the SAT for two AABBs
*/
public boolean solve(){
// Vector from A to B
float nx = a.x - b.x,
ny = a.y - b.y;
// Calculate half extends along x axis
float aex = (a.max.x - a.min.x) / 2,
bex = (b.max.x - b.min.x) / 2;
// Overlap on x axis
float xoverlap = aex + bex - Math.abs(nx);
if (xoverlap > 0) {
// Calculate half extends along y axis
float aey = (a.max.y - a.min.y) / 2,
bey = (b.max.y - b.min.y) / 2;
// Overlap on x axis
float yoverlap = aey + bey - Math.abs(ny);
if (!MathUtils.isEqual(yoverlap, 0)) {
// Find out which axis is the axis of least penetration
if (xoverlap < yoverlap) {
// Point towards B knowing that n points from A to B
normal.x = nx < 0 ? 1 : -1;
normal.y = 0;
penetration = xoverlap;
return true;
} else {
// Point towards B knowing that n points from A to B
normal.x = 0;
normal.y = ny < 0 ? 1 : -1;
penetration = yoverlap;
return true;
}
}
}
return false;
}