本文整理汇总了Java中org.jbox2d.common.MathUtils类的典型用法代码示例。如果您正苦于以下问题:Java MathUtils类的具体用法?Java MathUtils怎么用?Java MathUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MathUtils类属于org.jbox2d.common包,在下文中一共展示了MathUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createLoop
import org.jbox2d.common.MathUtils; //导入依赖的package包/类
/**
* Create a loop. This automatically adjusts connectivity.
*
* @param vertices an array of vertices, these are copied
* @param count the vertex count
*/
public void createLoop(final Vec2[] vertices, int count) {
assert (m_vertices == null && m_count == 0);
assert (count >= 3);
m_count = count + 1;
m_vertices = new Vec2[m_count];
for (int i = 1; i < count; i++) {
Vec2 v1 = vertices[i - 1];
Vec2 v2 = vertices[i];
// If the code crashes here, it means your vertices are too close together.
if (MathUtils.distanceSquared(v1, v2) < Settings.linearSlop * Settings.linearSlop) {
throw new RuntimeException("Vertices of chain shape are too close together");
}
}
for (int i = 0; i < count; i++) {
m_vertices[i] = new Vec2(vertices[i]);
}
m_vertices[count] = new Vec2(m_vertices[0]);
m_prevVertex.set(m_vertices[m_count - 2]);
m_nextVertex.set(m_vertices[1]);
m_hasPrevVertex = true;
m_hasNextVertex = true;
}
示例2: createChain
import org.jbox2d.common.MathUtils; //导入依赖的package包/类
/**
* Create a chain with isolated end vertices.
*
* @param vertices an array of vertices, these are copied
* @param count the vertex count
*/
public void createChain(final Vec2 vertices[], int count) {
assert (m_vertices == null && m_count == 0);
assert (count >= 2);
m_count = count;
m_vertices = new Vec2[m_count];
for (int i = 1; i < m_count; i++) {
Vec2 v1 = vertices[i - 1];
Vec2 v2 = vertices[i];
// If the code crashes here, it means your vertices are too close together.
if (MathUtils.distanceSquared(v1, v2) < Settings.linearSlop * Settings.linearSlop) {
throw new RuntimeException("Vertices of chain shape are too close together");
}
}
for (int i = 0; i < m_count; i++) {
m_vertices[i] = new Vec2(vertices[i]);
}
m_hasPrevVertex = false;
m_hasNextVertex = false;
m_prevVertex.setZero();
m_nextVertex.setZero();
}
示例3: getMetric
import org.jbox2d.common.MathUtils; //导入依赖的package包/类
public float getMetric() {
switch (m_count) {
case 0:
assert (false);
return 0.0f;
case 1:
return 0.0f;
case 2:
return MathUtils.distance(m_v1.w, m_v2.w);
case 3:
case3.set(m_v2.w).subLocal(m_v1.w);
case33.set(m_v3.w).subLocal(m_v1.w);
// return Vec2.cross(m_v2.w - m_v1.w, m_v3.w - m_v1.w);
return Vec2.cross(case3, case33);
default:
assert (false);
return 0.0f;
}
}
示例4: 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;
}
示例5: solveSpring
import org.jbox2d.common.MathUtils; //导入依赖的package包/类
void solveSpring(final TimeStep step) {
float springStrength = step.inv_dt * m_springStrength;
for (int k = 0; k < m_pairCount; k++) {
final Pair pair = m_pairBuffer[k];
if ((pair.flags & ParticleType.b2_springParticle) != 0) {
int a = pair.indexA;
int b = pair.indexB;
final Vec2 pa = m_positionBuffer.data[a];
final Vec2 pb = m_positionBuffer.data[b];
final float dx = pb.x - pa.x;
final float dy = pb.y - pa.y;
float r0 = pair.distance;
float r1 = MathUtils.sqrt(dx * dx + dy * dy);
if (r1 == 0) r1 = Float.MAX_VALUE;
float strength = springStrength * pair.strength;
final float fx = strength * (r0 - r1) / r1 * dx;
final float fy = strength * (r0 - r1) / r1 * dy;
final Vec2 va = m_velocityBuffer.data[a];
final Vec2 vb = m_velocityBuffer.data[b];
va.x -= fx;
va.y -= fy;
vb.x += fx;
vb.y += fy;
}
}
}
示例6: synchronizeFixtures
import org.jbox2d.common.MathUtils; //导入依赖的package包/类
protected final void synchronizeFixtures() {
final Transform xf1 = pxf;
// xf1.position = m_sweep.c0 - Mul(xf1.R, m_sweep.localCenter);
// xf1.q.set(m_sweep.a0);
// Rot.mulToOutUnsafe(xf1.q, m_sweep.localCenter, xf1.p);
// xf1.p.mulLocal(-1).addLocal(m_sweep.c0);
// inlined:
xf1.q.s = MathUtils.sin(m_sweep.a0);
xf1.q.c = MathUtils.cos(m_sweep.a0);
xf1.p.x = m_sweep.c0.x - xf1.q.c * m_sweep.localCenter.x + xf1.q.s * m_sweep.localCenter.y;
xf1.p.y = m_sweep.c0.y - xf1.q.s * m_sweep.localCenter.x - xf1.q.c * m_sweep.localCenter.y;
// end inline
for (Fixture f = m_fixtureList; f != null; f = f.m_next) {
f.synchronize(m_world.m_contactManager.m_broadPhase, xf1, m_xf);
}
}
示例7: keyPressed
import org.jbox2d.common.MathUtils; //导入依赖的package包/类
public void keyPressed() {
switch (key) {
case 'a':
m_spring1.enableMotor(true);
m_spring1.setMotorSpeed(m_speed);
break;
case 's':
m_spring1.enableMotor(true);
m_spring1.setMotorSpeed(0.0f);
break;
case 'd':
m_spring1.enableMotor(true);
m_spring1.setMotorSpeed(-m_speed);
break;
case 'q':
m_hz = MathUtils.max(0.0f, m_hz - 1.0f);
m_spring1.setSpringFrequencyHz(m_hz);
m_spring2.setSpringFrequencyHz(m_hz);
break;
case 'e':
m_hz += 1.0f;
m_spring1.setSpringFrequencyHz(m_hz);
m_spring2.setSpringFrequencyHz(m_hz);
break;
}
}
示例8: postSolve
import org.jbox2d.common.MathUtils; //导入依赖的package包/类
@Override
public void postSolve(Contact contact, ContactImpulse impulse) {
if (m_broke) {
// The body already broke.
return;
}
// Should the body break?
int count = contact.getManifold().pointCount;
float maxImpulse = 0.0f;
for (int i = 0; i < count; ++i) {
maxImpulse = MathUtils.max(maxImpulse, impulse.normalImpulses[i]);
}
if (maxImpulse > 30.0f) {
// Flag the body for breaking.
m_break = true;
}
}
示例9: getMetric
import org.jbox2d.common.MathUtils; //导入依赖的package包/类
public float getMetric() {
switch (m_count) {
case 0 :
assert (false);
return 0.0f;
case 1 :
return 0.0f;
case 2 :
return MathUtils.distance(m_v1.w, m_v2.w);
case 3 :
case3.set(m_v2.w).subLocal(m_v1.w);
case33.set(m_v3.w).subLocal(m_v1.w);
// return Vec2.cross(m_v2.w - m_v1.w, m_v3.w - m_v1.w);
return Vec2.cross(case3, case33);
default :
assert (false);
return 0.0f;
}
}
示例10: PulleyJoint
import org.jbox2d.common.MathUtils; //导入依赖的package包/类
/**
* @param argWorldPool
* @param def
*/
public PulleyJoint(IWorldPool argWorldPool, PulleyJointDef def) {
super(argWorldPool, def);
m_groundAnchor1.set(def.groundAnchorA);
m_groundAnchor2.set(def.groundAnchorB);
m_localAnchor1.set(def.localAnchorA);
m_localAnchor2.set(def.localAnchorB);
assert (def.ratio != 0.0f);
m_ratio = def.ratio;
m_constant = def.lengthA + m_ratio * def.lengthB;
m_maxLength1 = MathUtils.min(def.maxLengthA, m_constant - m_ratio * MIN_PULLEY_LENGTH);
m_maxLength2 = MathUtils.min(def.maxLengthB, (m_constant - MIN_PULLEY_LENGTH) / m_ratio);
m_impulse = 0.0f;
m_limitImpulse1 = 0.0f;
m_limitImpulse2 = 0.0f;
}
示例11: synchronizeTransform
import org.jbox2d.common.MathUtils; //导入依赖的package包/类
public final void synchronizeTransform() {
// m_xf.R.set(m_sweep.a);
//
// //m_xf.position = m_sweep.c - Mul(m_xf.R, m_sweep.localCenter);
// Mat22.mulToOut(m_xf.R, m_sweep.localCenter, m_xf.position);
// m_xf.position.mulLocal(-1).addLocal(m_sweep.c);
final float c = MathUtils.cos(m_sweep.a), s = MathUtils.sin(m_sweep.a);
m_xf.R.col1.x = c;
m_xf.R.col2.x = -s;
m_xf.R.col1.y = s;
m_xf.R.col2.y = c;
m_xf.position.x = m_xf.R.col1.x * m_sweep.localCenter.x + m_xf.R.col2.x * m_sweep.localCenter.y;
m_xf.position.y = m_xf.R.col1.y * m_sweep.localCenter.x + m_xf.R.col2.y * m_sweep.localCenter.y;
m_xf.position.x *= (float) (-1);
m_xf.position.y *= (float) (-1);
m_xf.position.x += m_sweep.c.x;
m_xf.position.y += m_sweep.c.y;
}
示例12: speedTest
import org.jbox2d.common.MathUtils; //导入依赖的package包/类
private static long speedTest(SinCosTable table, final int numIterations, final int numTrials){
long startTime, endTime;
long totalTime = 0;
float i,j;
float k = 0;
final float jstep = MathUtils.TWOPI/numIterations;
for(i=0; i<numTrials; i++){
startTime = System.nanoTime();
for(j=0; j<MathUtils.TWOPI; j+=jstep){
k += table.sin(j);
}
endTime = System.nanoTime();
totalTime += endTime - startTime;
}
return numIterations*numTrials*1000000000l/(totalTime);
}
示例13: speedTestMath
import org.jbox2d.common.MathUtils; //导入依赖的package包/类
private static long speedTestMath( final int numIterations, final int numTrials){
long startTime, endTime;
long totalTime = 0;
float i,j;
float k = 0;
final float jstep = MathUtils.TWOPI/numIterations;
for(i=0; i<numTrials; i++){
startTime = System.nanoTime();
for(j=0; j<MathUtils.TWOPI; j+=jstep){
k += (float) StrictMath.sin(j);
}
endTime = System.nanoTime();
totalTime += endTime - startTime;
}
return numIterations*numTrials*1000000000l/(totalTime);
}
示例14: sin
import org.jbox2d.common.MathUtils; //导入依赖的package包/类
public final float sin(float x){
x %= TWOPI;
if(LERP_LOOKUP){
x /= precision;
final int index = (int)x;
if(index != 0){
x %= index;
}
// the next index is 0
if(index == tableLength-1){
return ( (1-x)*sinLUT[index] + x * sinLUT[0]);
}else{
return ( (1-x)*sinLUT[index] + x * sinLUT[index + 1]);
}
}else{
return sinLUT[ MathUtils.round(x / precision) % tableLength];
}
}
示例15: keyPressed
import org.jbox2d.common.MathUtils; //导入依赖的package包/类
/**
* @see org.jbox2d.testbed.framework.TestbedTest#keyPressed(char, int)
*/
@Override
public void keyPressed(char argKeyChar, int argKeyCode) {
switch (argKeyChar) {
case 'l' :
m_joint.enableLimit(!m_joint.isLimitEnabled());
TestPanel.keys['l'] = false;
break;
case 'm' :
m_joint.enableMotor(!m_joint.isMotorEnabled());
TestPanel.keys['m'] = false;
break;
case 'a' :
m_joint.setMotorSpeed(1.0f * MathUtils.PI);
TestPanel.keys['a'] = false;
isLeft = true;
break;
case 'd' :
m_joint.setMotorSpeed(-1.0f * MathUtils.PI);
TestPanel.keys['d'] = false;
isLeft = false;
break;
}
}