本文整理汇总了Java中org.jbox2d.common.MathUtils.abs方法的典型用法代码示例。如果您正苦于以下问题:Java MathUtils.abs方法的具体用法?Java MathUtils.abs怎么用?Java MathUtils.abs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jbox2d.common.MathUtils
的用法示例。
在下文中一共展示了MathUtils.abs方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getMaxBalance
import org.jbox2d.common.MathUtils; //导入方法依赖的package包/类
@Override
public int getMaxBalance() {
int maxBalance = 0;
for (int i = 0; i < m_nodeCapacity; ++i) {
if (m_height[i] <= 1) {
continue;
}
assert (m_child1[i] != NULL_NODE);
int child1 = m_child1[i];
int child2 = m_child2[i];
int balance = MathUtils.abs(m_height[child2] - m_height[child1]);
maxBalance = MathUtils.max(maxBalance, balance);
}
return maxBalance;
}
示例2: Action
import org.jbox2d.common.MathUtils; //导入方法依赖的package包/类
public void Action() {
int choice = MathUtils.abs(rand.nextInt() % 20);
switch (choice) {
case 0:
CreateProxy();
break;
case 1:
DestroyProxy();
break;
default:
MoveProxy();
}
}
示例3: getMaxBalance
import org.jbox2d.common.MathUtils; //导入方法依赖的package包/类
@Override
public int getMaxBalance() {
int maxBalance = 0;
for (int i = 0; i < m_nodeCapacity; ++i) {
final DynamicTreeNode node = m_nodes[i];
if (node.height <= 1) {
continue;
}
assert (node.isLeaf() == false);
DynamicTreeNode child1 = node.child1;
DynamicTreeNode child2 = node.child2;
int balance = MathUtils.abs(child2.height - child1.height);
maxBalance = MathUtils.max(maxBalance, balance);
}
return maxBalance;
}
示例4: solvePositionConstraints
import org.jbox2d.common.MathUtils; //导入方法依赖的package包/类
@Override
public boolean solvePositionConstraints(float baumgarte) {
if (m_frequencyHz > 0.0f) {
return true;
}
final Body b1 = m_bodyA;
final Body b2 = m_bodyB;
final Vec2 r1 = pool.popVec2();
final Vec2 r2 = pool.popVec2();
final Vec2 d = pool.popVec2();
r1.set(m_localAnchor1).subLocal(b1.getLocalCenter());
r2.set(m_localAnchor2).subLocal(b2.getLocalCenter());
Mat22.mulToOut(b1.getTransform().R, r1, r1);
Mat22.mulToOut(b2.getTransform().R, r2, r2);
d.x = b2.m_sweep.c.x + r2.x - b1.m_sweep.c.x - r1.x;
d.y = b2.m_sweep.c.y + r2.y - b1.m_sweep.c.y - r1.y;
float length = d.normalize();
float C = length - m_length;
C = MathUtils.clamp(C, -Settings.maxLinearCorrection, Settings.maxLinearCorrection);
float impulse = -m_mass * C;
m_u.set(d);
float Px = impulse * m_u.x;
float Py = impulse * m_u.y;
b1.m_sweep.c.x -= b1.m_invMass * Px;
b1.m_sweep.c.y -= b1.m_invMass * Py;
b1.m_sweep.a -= b1.m_invI * (r1.x * Py - r1.y * Px);// b2Cross(r1, P);
b2.m_sweep.c.x += b2.m_invMass * Px;
b2.m_sweep.c.y += b2.m_invMass * Py;
b2.m_sweep.a += b2.m_invI * (r2.x * Py - r2.y * Px);// b2Cross(r2, P);
b1.synchronizeTransform();
b2.synchronizeTransform();
pool.pushVec2(3);
return MathUtils.abs(C) < Settings.linearSlop;
}
示例5: accuracyTest
import org.jbox2d.common.MathUtils; //导入方法依赖的package包/类
private static double accuracyTest(SinCosTable table, int iterations){
double totalDiff = 0f, diff = 0f;
for(int i=0; i<iterations; i++){
float querry = (float)Math.random()*MathUtils.TWOPI;
diff = MathUtils.abs((float)Math.sin(querry)-table.sin(querry));
totalDiff += diff;
}
totalDiff /= iterations;
return totalDiff;
}
示例6: step
import org.jbox2d.common.MathUtils; //导入方法依赖的package包/类
/**
* @see org.jbox2d.testbed.framework.TestbedTest#step(org.jbox2d.testbed.framework.Testbe.settings)
*/
@Override
public void step(TestbedSettings settings) {
boolean advanceRay = settings.pause == false || settings.singleStep;
super.step(settings);
addTextLine("Press 1-5 to drop stuff");
float L = 25.0f;
Vec2 point1 = new Vec2(0.0f, 10.0f);
Vec2 d = new Vec2(L * MathUtils.cos(m_angle), -L * MathUtils.abs(MathUtils.sin(m_angle)));
Vec2 point2 = point1.add(d);
callback.m_fixture = null;
m_world.raycast(callback, point1, point2);
if (callback.m_fixture != null)
{
m_debugDraw.drawPoint(callback.m_point, 5.0f, new Color3f(0.4f, 0.9f, 0.4f));
m_debugDraw.drawSegment(point1, callback.m_point, new Color3f(0.8f, 0.8f, 0.8f));
Vec2 head = callback.m_normal.mul(.5f).addLocal(callback.m_point);
m_debugDraw.drawSegment(callback.m_point, head, new Color3f(0.9f, 0.9f, 0.4f));
}
else
{
m_debugDraw.drawSegment(point1, point2, new Color3f(0.8f, 0.8f, 0.8f));
}
if (advanceRay)
{
m_angle += 0.25f * MathUtils.PI / 180.0f;
}
}
示例7: CreateProxy
import org.jbox2d.common.MathUtils; //导入方法依赖的package包/类
public void CreateProxy() {
for (int i = 0; i < e_actorCount; ++i) {
int j = MathUtils.abs(rand.nextInt() % e_actorCount);
Actor actor = m_actors[j];
if (actor.proxyId == null) {
GetRandomAABB(actor.aabb);
actor.proxyId = m_tree.createProxy(actor.aabb, actor);
return;
}
}
}
示例8: DestroyProxy
import org.jbox2d.common.MathUtils; //导入方法依赖的package包/类
public void DestroyProxy() {
for (int i = 0; i < e_actorCount; ++i) {
int j = MathUtils.abs(rand.nextInt() % e_actorCount);
Actor actor = m_actors[j];
if (actor.proxyId != null) {
m_tree.destroyProxy(actor.proxyId);
actor.proxyId = null;
return;
}
}
}
示例9: MoveProxy
import org.jbox2d.common.MathUtils; //导入方法依赖的package包/类
public void MoveProxy() {
for (int i = 0; i < e_actorCount; ++i) {
int j = MathUtils.abs(rand.nextInt() % e_actorCount);
Actor actor = m_actors[j];
if (actor.proxyId == null) {
continue;
}
AABB aabb0 = new AABB(actor.aabb);
MoveAABB(actor.aabb);
Vec2 displacement = actor.aabb.getCenter().sub(aabb0.getCenter());
m_tree.moveProxy(actor.proxyId, new AABB(actor.aabb), displacement);
return;
}
}
示例10: CreateProxy
import org.jbox2d.common.MathUtils; //导入方法依赖的package包/类
public void CreateProxy() {
for (int i = 0; i < e_actorCount; ++i) {
int j = MathUtils.abs(rand.nextInt() % e_actorCount);
Actor actor = m_actors[j];
if (actor.proxyId == -1) {
GetRandomAABB(actor.aabb);
actor.proxyId = m_tree.createProxy(actor.aabb, actor);
return;
}
}
}
示例11: step
import org.jbox2d.common.MathUtils; //导入方法依赖的package包/类
@Override
public void step(TestbedSettings settings) {
boolean advanceRay = settings.pause == false || settings.singleStep;
super.step(settings);
addTextLine("Press 1-5 to drop stuff");
float L = 25.0f;
Vec2 point1 = new Vec2(0.0f, 10.0f);
Vec2 d = new Vec2(L * MathUtils.cos(m_angle), -L * MathUtils.abs(MathUtils.sin(m_angle)));
Vec2 point2 = point1.add(d);
callback.m_fixture = null;
getWorld().raycast(callback, point1, point2);
if (callback.m_fixture != null) {
getDebugDraw().drawPoint(callback.m_point, 5.0f, new Color3f(0.4f, 0.9f, 0.4f));
getDebugDraw().drawSegment(point1, callback.m_point, new Color3f(0.8f, 0.8f, 0.8f));
Vec2 head = callback.m_normal.mul(.5f).addLocal(callback.m_point);
getDebugDraw().drawSegment(callback.m_point, head, new Color3f(0.9f, 0.9f, 0.4f));
} else {
getDebugDraw().drawSegment(point1, point2, new Color3f(0.8f, 0.8f, 0.8f));
}
if (advanceRay) {
m_angle += 0.25f * MathUtils.PI / 180.0f;
}
}
示例12: DestroyProxy
import org.jbox2d.common.MathUtils; //导入方法依赖的package包/类
public void DestroyProxy() {
for (int i = 0; i < e_actorCount; ++i) {
int j = MathUtils.abs(rand.nextInt() % e_actorCount);
Actor actor = m_actors[j];
if (actor.proxyId != -1) {
m_tree.destroyProxy(actor.proxyId);
actor.proxyId = -1;
return;
}
}
}
示例13: MoveProxy
import org.jbox2d.common.MathUtils; //导入方法依赖的package包/类
public void MoveProxy() {
for (int i = 0; i < e_actorCount; ++i) {
int j = MathUtils.abs(rand.nextInt() % e_actorCount);
Actor actor = m_actors[j];
if (actor.proxyId == -1) {
continue;
}
AABB aabb0 = new AABB(actor.aabb);
MoveAABB(actor.aabb);
Vec2 displacement = actor.aabb.getCenter().sub(aabb0.getCenter());
m_tree.moveProxy(actor.proxyId, new AABB(actor.aabb), displacement);
return;
}
}
示例14: RayCast
import org.jbox2d.common.MathUtils; //导入方法依赖的package包/类
public void RayCast() {
m_rayActor = null;
RayCastInput input = new RayCastInput();
input.set(m_rayCastInput);
// Ray cast against the dynamic tree.
m_tree.raycast(this, input);
// Brute force ray cast.
Actor bruteActor = null;
RayCastOutput bruteOutput = new RayCastOutput();
for (int i = 0; i < e_actorCount; ++i) {
if (m_actors[i].proxyId == -1) {
continue;
}
RayCastOutput output = new RayCastOutput();
boolean hit = m_actors[i].aabb.raycast(output, input,
getWorld().getPool());
if (hit) {
bruteActor = m_actors[i];
bruteOutput = output;
input.maxFraction = output.fraction;
}
}
if (bruteActor != null) {
if(MathUtils.abs(bruteOutput.fraction
- m_rayCastOutput.fraction) > Settings.EPSILON) {
System.out.println("wrong!");
assert (MathUtils.abs(bruteOutput.fraction
- m_rayCastOutput.fraction) <= 20 * Settings.EPSILON);
}
}
}
示例15: accuracyTest
import org.jbox2d.common.MathUtils; //导入方法依赖的package包/类
private static double accuracyTest(SinCosTable table, int iterations) {
double totalDiff = 0f, diff = 0f;
for (int i = 0; i < iterations; i++) {
float querry = (float) Math.random() * MathUtils.TWOPI;
diff = MathUtils.abs((float) Math.sin(querry) - table.sin(querry));
totalDiff += diff;
}
totalDiff /= iterations;
return totalDiff;
}