本文整理汇总了Java中org.jbox2d.dynamics.joints.RevoluteJointDef类的典型用法代码示例。如果您正苦于以下问题:Java RevoluteJointDef类的具体用法?Java RevoluteJointDef怎么用?Java RevoluteJointDef使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RevoluteJointDef类属于org.jbox2d.dynamics.joints包,在下文中一共展示了RevoluteJointDef类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initScene
import org.jbox2d.dynamics.joints.RevoluteJointDef; //导入依赖的package包/类
public void initScene() {
Body ground = null;
{
BodyDef bd = new BodyDef();
bd.position.set(0.0f, 20.0f);
ground = world.createBody(bd);
}
float a = 0.5f;
Vec2 h = new Vec2(0.0f, a);
colorMode(HSB, 1f);
Body root = AddNode(ground, new Vec2(), 0, 3.0f, a);
colorMode(RGB, 255);
RevoluteJointDef jointDef = new RevoluteJointDef();
jointDef.bodyA = ground;
jointDef.bodyB = root;
jointDef.localAnchorA.setZero();
jointDef.localAnchorB = h;
world.createJoint(jointDef);
world.bodies.addAll();
}
示例2: setJoint
import org.jbox2d.dynamics.joints.RevoluteJointDef; //导入依赖的package包/类
private Joint setJoint(PartJoint partJoint) {
Body bodyOne = partToBody.get(partJoint.partOne);
Body bodyTwo = partToBody.get(partJoint.partTwo);
RevoluteJointDef jointDef = new RevoluteJointDef();
jointDef.bodyA = bodyOne;
jointDef.bodyB = bodyTwo;
jointDef.localAnchorA = partJoint.partOne.getAnchor(partJoint
.getPercentOne());
jointDef.localAnchorB = partJoint.partTwo.getAnchor(partJoint
.getPercentTwo());
jointDef.lowerAngle = Math.min(partJoint.getPointA(),
partJoint.getPointB());
jointDef.upperAngle = Math.max(partJoint.getPointA(),
partJoint.getPointB());
jointDef.maxMotorTorque = 70.0f;
jointDef.motorSpeed = GeomUtil.circle(partJoint.getAngularVelocity());
jointDef.enableMotor = true;
jointDef.enableLimit = true;
return world.createJoint(jointDef);
}
示例3: newEngineInstance
import org.jbox2d.dynamics.joints.RevoluteJointDef; //导入依赖的package包/类
@Override
public JointDef newEngineInstance()
{
RevoluteJointDef jointDef = new RevoluteJointDef();
jointDef.localAnchorA = localAnchorA.toVec2();
jointDef.localAnchorB = localAnchorB.toVec2();
jointDef.enableLimit = limitEnabled;
if (limitEnabled)
{
jointDef.lowerAngle = lowerAngleLimit;
jointDef.upperAngle = upperAngleLimit;
}
jointDef.enableMotor = motorEnabled;
if (motorEnabled)
{
jointDef.motorSpeed = motorSpeed;
jointDef.maxMotorTorque = maxMotorTorque;
}
return jointDef;
}
示例4: create
import org.jbox2d.dynamics.joints.RevoluteJointDef; //导入依赖的package包/类
/**
* Create the pendulum body and attach it to the pivot body.
* @param pivot the pivot body
* @return the pendulum bob body
*/
private Body create(final Body pivot) {
World world = pivot.getWorld();
double angle = Math.random() * Math.PI;
float x = (float) Math.cos(angle) * ROD_LENGTH;
float y = (float) Math.sin(angle) * ROD_LENGTH;
Vec2 origin = pivot.getWorldCenter();
Body mass = newBob(world, new Vec2(origin.x + x, origin.y + y));
/* Attach to the pivot. */
val joint = new RevoluteJointDef();
joint.initialize(pivot, mass, pivot.getWorldCenter());
joint.enableMotor = true;
world.createJoint(joint);
return mass;
}
示例5: iteration
import org.jbox2d.dynamics.joints.RevoluteJointDef; //导入依赖的package包/类
@Override
public long iteration() {
long count = 0;
for (int k = 0; k < repeats; k++) {
Vec2 gravity = new Vec2(0.0f, -10.0f);
world = new World(gravity);
Body ground = world.createBody(bodyDef);
ground.createFixture(eshape, 0.0f);
RevoluteJointDef jd = new RevoluteJointDef();
jd.collideConnected = false;
final float y = 25.0f;
Body prevBody = ground;
for (int i = 0; i < 35; ++i) {
bodyDef.type = BodyType.DYNAMIC;
bodyDef.position.set(0.5f + i, y);
Body body = world.createBody(bodyDef);
body.createFixture(fixtureDef);
anchor.set(i, y);
jd.initialize(prevBody, body, anchor);
world.createJoint(jd);
prevBody = body;
}
for (int t = 0; t < steps; t++) {
world.step(1.0f / 60, 80, 80);
count++;
}
}
return count;
}
示例6: iteration
import org.jbox2d.dynamics.joints.RevoluteJointDef; //导入依赖的package包/类
@Override
public long iteration() {
long count = 0;
for (int k = 0; k < repeats; k++) {
Vec2 gravity = new Vec2(0.0f, -10.0f);
world = new World(gravity);
Body ground = world.createBody(bodyDef);
ground.createFixture(eshape, 0.0f);
RevoluteJointDef jd = new RevoluteJointDef();
jd.collideConnected = false;
final float y = 25.0f;
Body prevBody = ground;
for (int i = 0; i < 35; ++i) {
bodyDef.type = BodyType.DYNAMIC;
bodyDef.position.set(0.5f + i, y);
Body body = world.createBody(bodyDef);
body.createFixture(fixtureDef);
anchor.set(i, y);
jd.initialize(prevBody, body, anchor);
world.createJoint(jd);
prevBody = body;
}
for (int t = 0; t < steps; t++) {
world.step(1.0f / 60, 4, 80);
count++;
}
}
return count;
}
示例7: iteration
import org.jbox2d.dynamics.joints.RevoluteJointDef; //导入依赖的package包/类
@Override
public long iteration() {
long count = 0;
for (int k = 0; k < repeats; k++) {
Vec2 gravity = new Vec2(0.0f, -10.0f);
world = new World(gravity);
Body ground = world.createBody(bodyDef);
ground.createFixture(eshape, 0.0f);
RevoluteJointDef jd = new RevoluteJointDef();
jd.collideConnected = false;
final float y = 25.0f;
Body prevBody = ground;
for (int i = 0; i < 35; ++i) {
bodyDef.type = BodyType.DYNAMIC;
bodyDef.position.set(0.5f + i, y);
Body body = world.createBody(bodyDef);
body.createFixture(fixtureDef);
anchor.set(i, y);
jd.initialize(prevBody, body, anchor);
world.createJoint(jd);
prevBody = body;
}
for (int t = 0; t < steps; t++) {
world.step(1.0f / 60, 80, 4);
count++;
}
}
return count;
}
示例8: iteration
import org.jbox2d.dynamics.joints.RevoluteJointDef; //导入依赖的package包/类
@Override
public long iteration() {
long count = 0;
for (int k = 0; k < repeats; k++) {
Vec2 gravity = new Vec2(0.0f, -10.0f);
world = new World(gravity);
Body ground = world.createBody(bodyDef);
ground.createFixture(eshape, 0.0f);
RevoluteJointDef jd = new RevoluteJointDef();
jd.collideConnected = false;
final float y = 25.0f;
Body prevBody = ground;
for (int i = 0; i < 35; ++i) {
bodyDef.type = BodyType.DYNAMIC;
bodyDef.position.set(0.5f + i, y);
Body body = world.createBody(bodyDef);
body.createFixture(fixtureDef);
anchor.set(i, y);
jd.initialize(prevBody, body, anchor);
world.createJoint(jd);
prevBody = body;
}
for (int t = 0; t < steps; t++) {
world.step(1.0f / 60, 4, 4);
count++;
}
}
return count;
}
示例9: initTest
import org.jbox2d.dynamics.joints.RevoluteJointDef; //导入依赖的package包/类
@Override
public void initTest(boolean deserialized) {
{
BodyDef bd = new BodyDef();
bd.type = BodyType.DYNAMIC;
bd.allowSleep = false;
bd.position.set(0.0f, 10.0f);
Body body = m_world.createBody(bd);
PolygonShape shape = new PolygonShape();
shape.setAsBox(0.5f, 10.0f, new Vec2(10.0f, 0.0f), 0.0f);
body.createFixture(shape, 5.0f);
shape.setAsBox(0.5f, 10.0f, new Vec2(-10.0f, 0.0f), 0.0f);
body.createFixture(shape, 5.0f);
shape.setAsBox(10.0f, 0.5f, new Vec2(0.0f, 10.0f), 0.0f);
body.createFixture(shape, 5.0f);
shape.setAsBox(10.0f, 0.5f, new Vec2(0.0f, -10.0f), 0.0f);
body.createFixture(shape, 5.0f);
RevoluteJointDef jd = new RevoluteJointDef();
jd.bodyA = getGroundBody();
jd.bodyB = body;
jd.localAnchorA.set(0.0f, 10.0f);
jd.localAnchorB.set(0.0f, 0.0f);
jd.referenceAngle = 0.0f;
jd.motorSpeed = 0.05f * MathUtils.PI;
jd.maxMotorTorque = 1e8f;
jd.enableMotor = true;
m_joint = (RevoluteJoint) m_world.createJoint(jd);
}
m_count = 0;
}
示例10: createRevoluteJoint
import org.jbox2d.dynamics.joints.RevoluteJointDef; //导入依赖的package包/类
public RevoluteJoint createRevoluteJoint(Body body1, Body body2, Vec2 anchor, Float maxMotorTorque) {
RevoluteJointDef jointDef = new RevoluteJointDef();
jointDef.initialize(body1, body2, anchor);
if( maxMotorTorque!=null ) {
jointDef.maxMotorTorque = maxMotorTorque;
jointDef.enableMotor = true;
jointDef.motorSpeed = 1f;
}
return (RevoluteJoint) physicsWorld.createJoint(jointDef);
}
示例11: joinReelToAxis
import org.jbox2d.dynamics.joints.RevoluteJointDef; //导入依赖的package包/类
private void joinReelToAxis() {
RevoluteJointDef jointDef = new RevoluteJointDef();
jointDef.bodyA = axis;
jointDef.bodyB = reel;
world.createJoint(jointDef);
}
示例12: initScene
import org.jbox2d.dynamics.joints.RevoluteJointDef; //导入依赖的package包/类
public void initScene() {
{
BodyDef bd = new BodyDef();
Body groundbody = world.createBody(bd);
bd.type = BodyType.DYNAMIC;
bd.allowSleep = false;
bd.position.set(0.0f, 0.0f);
Body body = world.createBody(bd);
PolygonShape shape = new PolygonShape();
shape.setAsBox(1, 11.0f, new Vec2(10.0f, 0.0f), 0.0f);
body.createFixture(shape, 15.0f);
shape.setAsBox(1, 11.0f, new Vec2(-10.0f, 0.0f), 0.0f);
body.createFixture(shape, 15.0f);
shape.setAsBox(11.0f, 1, new Vec2(0.0f, 10.0f), 0.0f);
body.createFixture(shape, 15.0f);
shape.setAsBox(11.0f, 1, new Vec2(0.0f, -10.0f), 0.0f);
body.createFixture(shape, 15.0f);
CircleShape obstacle = new CircleShape();
obstacle.m_radius = 1;
obstacle.m_p.set(-2, -6.5f);
body.createFixture(obstacle, 115.0f);
obstacle.m_p.set(2, +6.5f);
body.createFixture(obstacle, 115.0f);
// obstacle.m_p.set(-7.5f, 0);
// body.createFixture(obstacle, 15.0f);
// obstacle.m_p.set(+7.5f, 0);
// body.createFixture(obstacle, 15.0f);
world.bodies.add(body, true, color(224), true, color(0), 1f);
RevoluteJointDef jd = new RevoluteJointDef();
jd.bodyA = groundbody;
jd.bodyB = body;
jd.localAnchorA.set(0.0f, 0.0f);
jd.localAnchorB.set(0.0f, 0.0f);
jd.referenceAngle = 0.0f;
jd.motorSpeed = 0.1f * MathUtils.PI;
jd.maxMotorTorque = 1e7f;
jd.enableMotor = true;
m_joint = (RevoluteJoint) world.createJoint(jd);
}
m_count = 0;
// creates shapes for all rigid bodies in the world.
world.bodies.addAll();
}
示例13: AddNode
import org.jbox2d.dynamics.joints.RevoluteJointDef; //导入依赖的package包/类
Body AddNode(Body parent, Vec2 localAnchor, int depth, float offset, float a){
a *= 0.90f;
float fdepth = 1 - depth / (float) (e_depth+1);
float hue = 220 / 360f;
float density = 20.0f;
Vec2 h = new Vec2(0.0f, a);
Vec2 p = parent.getPosition().add(localAnchor).sub(h);
BodyDef bodyDef = new BodyDef();
bodyDef.type = BodyType.DYNAMIC;
bodyDef.position = p;
Body body = world.createBody(bodyDef);
world.bodies.add(body, true, color(0), true, color(0), 1f);
PolygonShape shape = new PolygonShape();
shape.setAsBox(0.25f * a, a);
Fixture fixture1 = body.createFixture(shape, density);
world.bodies.add(fixture1, true, color(hue, fdepth, 1), true, color(0), 1f);
if (depth == e_depth){
return body;
}
shape.setAsBox(offset, 0.25f * a, new Vec2(0, -a), 0.0f);
Fixture fixture2 = body.createFixture(shape, density);
world.bodies.add(fixture2, true, color(hue, fdepth, 1), true, color(0), 1f);
Vec2 a1 = new Vec2(offset, -a);
Vec2 a2 = new Vec2(-offset, -a);
Body body1 = AddNode(body, a1, depth + 1, 0.5f * offset, a);
Body body2 = AddNode(body, a2, depth + 1, 0.5f * offset, a);
RevoluteJointDef jointDef = new RevoluteJointDef();
jointDef.bodyA = body;
jointDef.localAnchorB = h;
jointDef.localAnchorA = a1;
jointDef.bodyB = body1;
world.createJoint(jointDef);
jointDef.localAnchorA = a2;
jointDef.bodyB = body2;
world.createJoint(jointDef);
return body;
}
示例14: initTest
import org.jbox2d.dynamics.joints.RevoluteJointDef; //导入依赖的package包/类
/**
* @see org.jbox2d.testbed.framework.TestbedTest#initTest()
*/
@Override
public void initTest() {
Body ground = null;
{
BodyDef bd = new BodyDef();
ground = m_world.createBody(bd);
PolygonShape shape = new PolygonShape();
shape.setAsEdge(new Vec2(50.0f, 0.0f), new Vec2(-50.0f, 0.0f));
ground.createFixture(shape, 0.0f);
}
{
CircleShape circle1 = new CircleShape();
circle1.m_radius = 1.0f;
CircleShape circle2 = new CircleShape();
circle2.m_radius = 2.0f;
PolygonShape box = new PolygonShape();
box.setAsBox(0.5f, 5.0f);
BodyDef bd1 = new BodyDef();
bd1.type = BodyType.DYNAMIC;
bd1.position.set(-3.0f, 12.0f);
Body body1 = m_world.createBody(bd1);
body1.createFixture(circle1, 5.0f);
RevoluteJointDef jd1 = new RevoluteJointDef();
jd1.bodyA = ground;
jd1.bodyB = body1;
jd1.localAnchorA = ground.getLocalPoint(bd1.position);
jd1.localAnchorB = body1.getLocalPoint(bd1.position);
jd1.referenceAngle = body1.getAngle() - ground.getAngle();
m_joint1 = (RevoluteJoint)m_world.createJoint(jd1);
BodyDef bd2 = new BodyDef();
bd2.type = BodyType.DYNAMIC;
bd2.position.set(0.0f, 12.0f);
Body body2 = m_world.createBody(bd2);
body2.createFixture(circle2, 5.0f);
RevoluteJointDef jd2 = new RevoluteJointDef();
jd2.initialize(ground, body2, bd2.position);
m_joint2 = (RevoluteJoint)m_world.createJoint(jd2);
BodyDef bd3 = new BodyDef();
bd3.type = BodyType.DYNAMIC;
bd3.position.set(2.5f, 12.0f);
Body body3 = m_world.createBody(bd3);
body3.createFixture(box, 5.0f);
PrismaticJointDef jd3 = new PrismaticJointDef();
jd3.initialize(ground, body3, bd3.position, new Vec2(0.0f, 1.0f));
jd3.lowerTranslation = -5.0f;
jd3.upperTranslation = 5.0f;
jd3.enableLimit = true;
m_joint3 = (PrismaticJoint)m_world.createJoint(jd3);
GearJointDef jd4 = new GearJointDef();
jd4.bodyA = body1;
jd4.bodyB = body2;
jd4.joint1 = m_joint1;
jd4.joint2 = m_joint2;
jd4.ratio = circle2.m_radius / circle1.m_radius;
m_joint4 = (GearJoint)m_world.createJoint(jd4);
GearJointDef jd5 = new GearJointDef();
jd5.bodyA = body2;
jd5.bodyB = body3;
jd5.joint1 = m_joint2;
jd5.joint2 = m_joint3;
jd5.ratio = -1.0f / circle2.m_radius;
m_joint5 = (GearJoint)m_world.createJoint(jd5);
}
}
示例15: init
import org.jbox2d.dynamics.joints.RevoluteJointDef; //导入依赖的package包/类
@Override
public void init(GameContainer container, StateBasedGame game) throws SlickException {
float boxWidth = 0.4f;
float boxHeight = 6.0f;
Vec2 jointPos = new Vec2(this.position.x, this.position.y + boxHeight);
//==Pivot============
BodyDef pivotDef = new BodyDef();
pivotDef.position.set(jointPos);
Body pivot = this.world.createBody(pivotDef);
CircleDef cd = new CircleDef();
cd.radius = boxWidth * 0.5f;
cd.density = 0;
pivot.createShape(cd);
pivot.setMassFromShapes();
//==P�ndulo==========
BodyDef boxDef = new BodyDef();
boxDef.position.set(this.position);
Body box = this.world.createBody(boxDef);
PolygonDef sd = new PolygonDef();
sd.setAsBox(boxWidth, boxHeight);
MassData data = new MassData(0.1f, 1.0f, 0.1f);
data.setObjectMass(sd);
sd.userData = data;
box.createShape(sd);
box.setMassFromShapes();
box.setUserData(this);
//==Revolute Joint===
RevoluteJointDef rd = new RevoluteJointDef();
rd.initialize(pivot, box, jointPos);
rd.enableMotor = true;
rd.motorSpeed = -MOTOR_SPEED;
rd.maxMotorTorque = MOTOR_TORQUE;
rd.enableLimit = true;
rd.upperAngle = (float) (MAX_ANGLE * (Math.PI / 180));
rd.lowerAngle = (float) (-MAX_ANGLE * (Math.PI / 180));
this.objBody = (RevoluteJoint) this.world.createJoint(rd);
this.objBody.m_body1.setAngularDamping(-0.3f);
//Obt�m o objeto de som.
this.sfx = SoundPlayer.playObjPendulumImpulse();
}