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


Java MathUtils.randomFloat方法代码示例

本文整理汇总了Java中org.jbox2d.common.MathUtils.randomFloat方法的典型用法代码示例。如果您正苦于以下问题:Java MathUtils.randomFloat方法的具体用法?Java MathUtils.randomFloat怎么用?Java MathUtils.randomFloat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.jbox2d.common.MathUtils的用法示例。


在下文中一共展示了MathUtils.randomFloat方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: MoveAABB

import org.jbox2d.common.MathUtils; //导入方法依赖的package包/类
public void MoveAABB(AABB aabb) {
	Vec2 d = new Vec2();
	d.x = MathUtils.randomFloat(rand, -0.5f, 0.5f);
	d.y = MathUtils.randomFloat(rand, -0.5f, 0.5f);
	// d.x = 2.0f;
	// d.y = 0.0f;
	aabb.lowerBound.addLocal(d);
	aabb.upperBound.addLocal(d);

	Vec2 c0 = aabb.lowerBound.add(aabb.upperBound).mulLocal(.5f);
	Vec2 min = new Vec2();
	min.set(-worldExtent, 0.0f);
	Vec2 max = new Vec2();
	max.set(worldExtent, 2.0f * worldExtent);
	Vec2 c = MathUtils.clamp(c0, min, max);

	aabb.lowerBound.addLocal(c.sub(c0));
	aabb.upperBound.addLocal(c.sub(c0));
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:20,代码来源:DynamicTreeTest.java

示例2: launch

import org.jbox2d.common.MathUtils; //导入方法依赖的package包/类
public void launch() {
  m_body.setTransform(new Vec2(0.0f, 4.0f), 0.0f);
  m_body.setLinearVelocity(new Vec2());
  m_body.setAngularVelocity(0.0f);

  m_x = MathUtils.randomFloat(-1.0f, 1.0f);
  m_bullet.setTransform(new Vec2(m_x, 10.0f), 0.0f);
  m_bullet.setLinearVelocity(new Vec2(0.0f, -50.0f));
  m_bullet.setAngularVelocity(0.0f);

  Distance.GJK_CALLS = 0;
  Distance.GJK_ITERS = 0;
  Distance.GJK_MAX_ITERS = 0;

  TimeOfImpact.toiCalls = 0;
  TimeOfImpact.toiIters = 0;
  TimeOfImpact.toiMaxIters = 0;
  TimeOfImpact.toiRootIters = 0;
  TimeOfImpact.toiMaxRootIters = 0;
}
 
开发者ID:unktomi,项目名称:form-follows-function,代码行数:21,代码来源:BulletTest.java

示例3: launch

import org.jbox2d.common.MathUtils; //导入方法依赖的package包/类
public void launch() {
  m_body.setTransform(new Vec2(0.0f, 4.0f), 0.0f);
  m_body.setLinearVelocity(new Vec2());
  m_body.setAngularVelocity(0.0f);

  m_x = MathUtils.randomFloat(-1.0f, 1.0f);
  m_bullet.setTransform(new Vec2(m_x, 10.0f), 0.0f);
  m_bullet.setLinearVelocity(new Vec2(0.0f, -50.0f));
  m_bullet.setAngularVelocity(0.0f);
}
 
开发者ID:diwi,项目名称:LiquidFunProcessing,代码行数:11,代码来源:box2d_Bullet.java

示例4: SPHGroup

import org.jbox2d.common.MathUtils; //导入方法依赖的package包/类
public SPHGroup(int nParts, AABB aabb, float tStep) {
	// set the parameters to some default values
	param = new Parameter();
	param.numPts 		= nParts;
	param.initVel = new Vec2(0.0f,0.0f);		
	param.machNum      	= 0.5;		
	param.initDensity	= 1000.0;	
	param.initPressure = 10000.0f;
	param.nu 		= 1000.0;
	param.deltaT		= tStep;
	param.numSteps		= 500000;
	param.outputEvery	= 5000;
	param.firstOutput	= 0;
	param.densityVariation   = 0.3;
	param.lengthScale	= 1000.0;
	param.bodyFX 		= 0.0;
	param.bodyFY		= 0.0;
	param.c = 1.0f;
	param.h = 1000.0f;
	t = new SmoothParticle[nParts];
	for (int i=0; i<nParts; ++i) {
		float x = MathUtils.randomFloat(aabb.lowerBound.x,aabb.upperBound.x);
		float y = MathUtils.randomFloat(aabb.lowerBound.y,aabb.upperBound.y);
		t[i] = new SmoothParticle();
		t[i].pos.set(new Vec2(x,y));
		t[i].vel.set(param.initVel);
		t[i].mass = (1.0);
		t[i].setDensity(param.initDensity);
		t[i].setPressure(param.initPressure);
		t[i].setSmoothingLength(param.h);
		t[i].setSpeedSound(param.c);
		t[i].undeleteParticle();
		t[i].ID = i;
		t[i].setShapeID(-1);
	}
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:37,代码来源:SPHGroup.java

示例5: GetRandomAABB

import org.jbox2d.common.MathUtils; //导入方法依赖的package包/类
public void GetRandomAABB(AABB aabb) {
	Vec2 w = new Vec2();
	w.set(2.0f * m_proxyExtent, 2.0f * m_proxyExtent);
	// aabb.lowerBound.x = -m_proxyExtent;
	// aabb.lowerBound.y = -m_proxyExtent + worldExtent;
	aabb.lowerBound.x = MathUtils.randomFloat(rand, -worldExtent,
			worldExtent);
	aabb.lowerBound.y = MathUtils.randomFloat(rand, 0.0f,
			2.0f * worldExtent);
	aabb.upperBound.set(aabb.lowerBound).addLocal(w);
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:12,代码来源:DynamicTreeTest.java

示例6: generate

import org.jbox2d.common.MathUtils; //导入方法依赖的package包/类
void generate() {
  Vec2 lowerBound = new Vec2(-8f, -8f);
  Vec2 upperBound = new Vec2(8f, 8f);

  for (int i = 0; i < e_count; i++) {
    float x = MathUtils.randomFloat(-8, 8);
    float y = MathUtils.randomFloat(-8, 8);

    Vec2 v = new Vec2(x, y);
    MathUtils.clampToOut(v, lowerBound, upperBound, v);
    m_points[i] = v;
  }
  m_count = e_count;
}
 
开发者ID:unktomi,项目名称:form-follows-function,代码行数:15,代码来源:ConvexHull.java

示例7: generate

import org.jbox2d.common.MathUtils; //导入方法依赖的package包/类
void generate() {
  Vec2 lowerBound = new Vec2(-8f, -8f);
  Vec2 upperBound = new Vec2(8f, 8f);

  for (int i = 0; i < count; i++) {
    float x = MathUtils.randomFloat(-8, 8);
    float y = MathUtils.randomFloat(-8, 8);

    Vec2 v = new Vec2(x, y);
    MathUtils.clampToOut(v, lowerBound, upperBound, v);
    m_points[i] = v;
  }
}
 
开发者ID:weimingtom,项目名称:jbox2d,代码行数:14,代码来源:ConvexHull.java

示例8: runTest

import org.jbox2d.common.MathUtils; //导入方法依赖的package包/类
/**
 * @see org.jbox2d.testbed.perf.PerfTest#runTest(int)
 */
@Override
public void runTest(int argNum) {
	float random = MathUtils.randomFloat(Float.MIN_VALUE/3, Float.MAX_VALUE/3);
	switch(argNum){
		case 0:
			runSinTest(random);
			break;
		case 1:
			runSinLUTTest(random);
			break;
		case 2:
			runPowTest(random);
			break;
		case 3:
			runFastPowTest(random);
			break;
		case 4:
			runMaxTest(random);
			break;
		case 5:
			runFastMaxTest(random);
			break;
		case 6:
			runFloorTest(random);
			break;
		case 7:
			runFastFloorTest(random);
			break;
		case 8:
			runAtan2Test(random);
			break;
		case 9:
			runFastAtan2Test(random);
			break;
		case 10:
			runCeilTest(random);
			break;
		case 11:
			runFastCeilTest(random);
			break;
	}
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:46,代码来源:MathPerf.java

示例9: checkBounds

import org.jbox2d.common.MathUtils; //导入方法依赖的package包/类
private void checkBounds() {
	for (int i=0; i<liquid.length; ++i) {
		if (liquid[i].getWorldCenter().y < -10.0f) {
			m_world.destroyBody(liquid[i]);
			float massPerParticle = totalMass / nParticles;
			
			CircleShape pd = new CircleShape();
			FixtureDef fd = new FixtureDef();
			fd.shape = pd;
			fd.density = 1.0f;
			fd.filter.groupIndex = -10;
			pd.m_radius = .05f;
			fd.restitution = 0.4f;
			fd.friction = 0.0f;
			float cx = 0.0f + MathUtils.randomFloat(-0.6f,0.6f);
			float cy = 15.0f + MathUtils.randomFloat(-2.3f,2.0f);
			BodyDef bd = new BodyDef();
			bd.position = new Vec2( cx, cy );
			bd.fixedRotation = true;
			bd.type = BodyType.DYNAMIC;
			Body b = m_world.createBody(bd);
			b.createFixture(fd).setUserData(LIQUID_INT);
			MassData md = new MassData();
			md.mass = massPerParticle;
			md.I = 1.0f;
			b.setMassData(md);
			b.setSleepingAllowed(false);
			liquid[i] = b;
		}
	}
	
	if (bod.getWorldCenter().y < -15.0f) {
		m_world.destroyBody(bod);
		PolygonShape polyDef = new PolygonShape();
		polyDef.setAsBox(MathUtils.randomFloat(0.3f,0.7f), MathUtils.randomFloat(0.3f,0.7f));
		BodyDef bodyDef = new BodyDef();
		bodyDef.position = new Vec2(0.0f,25.0f);
		bodyDef.type = BodyType.DYNAMIC;
		bod = m_world.createBody(bodyDef);
		bod.createFixture(polyDef, 1f);
	}
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:43,代码来源:LiquidTest.java

示例10: step

import org.jbox2d.common.MathUtils; //导入方法依赖的package包/类
@Override
public void step(int argNum) {
  float random = MathUtils.randomFloat(-Float.MAX_VALUE / 3, Float.MAX_VALUE / 3);
  switch (argNum) {
    case 0:
      runSinTest(random);
      break;
    case 1:
      runSinLUTTest(random);
      break;
    case 2:
      runPowTest(random);
      break;
    case 3:
      runFastPowTest(random);
      break;
    case 4:
      runMaxTest(random);
      break;
    case 5:
      runFastMaxTest(random);
      break;
    case 6:
      runFloorTest(random);
      break;
    case 7:
      runFastFloorTest(random);
      break;
    case 8:
      runAtan2Test(random);
      break;
    case 9:
      runFastAtan2Test(random);
      break;
    case 10:
      runCeilTest(random);
      break;
    case 11:
      runFastCeilTest(random);
      break;
  }
}
 
开发者ID:unktomi,项目名称:form-follows-function,代码行数:43,代码来源:MathPerf.java

示例11: runTest

import org.jbox2d.common.MathUtils; //导入方法依赖的package包/类
/**
 * @see org.jbox2d.testbed.perf.BasicPerformanceTest#runTest(int)
 */
@Override
public void runTest(int argNum) {
	float random = MathUtils.randomFloat(-Float.MAX_VALUE/3, Float.MAX_VALUE/3);
	switch(argNum){
		case 0:
			runSinTest(random);
			break;
		case 1:
			runSinLUTTest(random);
			break;
		case 2:
			runPowTest(random);
			break;
		case 3:
			runFastPowTest(random);
			break;
		case 4:
			runMaxTest(random);
			break;
		case 5:
			runFastMaxTest(random);
			break;
		case 6:
			runFloorTest(random);
			break;
		case 7:
			runFastFloorTest(random);
			break;
		case 8:
			runAtan2Test(random);
			break;
		case 9:
			runFastAtan2Test(random);
			break;
		case 10:
			runCeilTest(random);
			break;
		case 11:
			runFastCeilTest(random);
			break;
	}
}
 
开发者ID:weimingtom,项目名称:jbox2d,代码行数:46,代码来源:MathPerf.java

示例12: checkBounds

import org.jbox2d.common.MathUtils; //导入方法依赖的package包/类
private void checkBounds() {
  for (int i = 0; i < liquid.length; ++i) {
    if (liquid[i].getWorldCenter().y < -10.0f) {
      getWorld().destroyBody(liquid[i]);
      float massPerParticle = totalMass / nParticles;

      CircleShape pd = new CircleShape();
      FixtureDef fd = new FixtureDef();
      fd.shape = pd;
      fd.density = 1.0f;
      fd.filter.groupIndex = -10;
      pd.m_radius = .05f;
      fd.restitution = 0.4f;
      fd.friction = 0.0f;
      float cx = 0.0f + MathUtils.randomFloat(-0.6f, 0.6f);
      float cy = 15.0f + MathUtils.randomFloat(-2.3f, 2.0f);
      BodyDef bd = new BodyDef();
      bd.position = new Vec2(cx, cy);
      bd.fixedRotation = true;
      bd.type = BodyType.DYNAMIC;
      Body b = getWorld().createBody(bd);
      b.createFixture(fd).setUserData(LIQUID_INT);
      MassData md = new MassData();
      md.mass = massPerParticle;
      md.I = 1.0f;
      b.setMassData(md);
      b.setSleepingAllowed(false);
      liquid[i] = b;
    }
  }

  if (bod.getWorldCenter().y < -15.0f) {
    getWorld().destroyBody(bod);
    PolygonShape polyDef = new PolygonShape();
    polyDef.setAsBox(MathUtils.randomFloat(0.3f, 0.7f), MathUtils.randomFloat(0.3f, 0.7f));
    BodyDef bodyDef = new BodyDef();
    bodyDef.position = new Vec2(0.0f, 25.0f);
    bodyDef.type = BodyType.DYNAMIC;
    bod = getWorld().createBody(bodyDef);
    bod.createFixture(polyDef, 1f);
  }
}
 
开发者ID:weimingtom,项目名称:jbox2d,代码行数:43,代码来源:LiquidTest.java


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