本文整理汇总了Java中org.jbox2d.dynamics.joints.RevoluteJoint类的典型用法代码示例。如果您正苦于以下问题:Java RevoluteJoint类的具体用法?Java RevoluteJoint怎么用?Java RevoluteJoint使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RevoluteJoint类属于org.jbox2d.dynamics.joints包,在下文中一共展示了RevoluteJoint类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: bind
import org.jbox2d.dynamics.joints.RevoluteJoint; //导入依赖的package包/类
public RevoluteJoint bind(IPhysicsBody other, Vector2f anchor, Float maxForce) {
if( !boundBodies.containsKey(other) ) {
final Box2dPhysicsBody otherBody = (Box2dPhysicsBody) other;
RevoluteJoint joint = parent.createRevoluteJoint(body, otherBody.getBody(), new Vec2(anchor.x*BOX2D_SCALE_FACTOR, anchor.y*BOX2D_SCALE_FACTOR), maxForce);
if( joint==null )
return null;
boundBodies.put(other, joint);
otherBody.boundBodies.put(other, joint);
return joint;
}
return null;
}
示例2: processJoint
import org.jbox2d.dynamics.joints.RevoluteJoint; //导入依赖的package包/类
@Override
public void processJoint(Joint joint, Long tag) {
if (tag == JOINT_TAG) {
m_joint = (RevoluteJoint) joint;
isLeft = m_joint.getMotorSpeed() > 0;
} else {
super.processJoint(joint, tag);
}
}
示例3: initTest
import org.jbox2d.dynamics.joints.RevoluteJoint; //导入依赖的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;
}
示例4: processJoint
import org.jbox2d.dynamics.joints.RevoluteJoint; //导入依赖的package包/类
@Override
public void processJoint(Joint argJoint, Long argTag) {
if (argTag == MOTOR_TAG) {
m_motorJoint = (RevoluteJoint) argJoint;
m_motorOn = m_motorJoint.isMotorEnabled();
}
}
示例5: update
import org.jbox2d.dynamics.joints.RevoluteJoint; //导入依赖的package包/类
/**
* Advances the simulation.
*/
public synchronized void update() {
world.step(timeStep, velocityIterations, positionIterations);
for (RevoluteJoint joint = (RevoluteJoint) world.getJointList(); joint != null; joint = (RevoluteJoint) joint
.getNext()) {
if (joint.getJointAngle() <= joint.getLowerLimit()
|| joint.getJointAngle() >= joint.getUpperLimit()) {
joint.setMotorSpeed((float) (-joint.getMotorSpeed()));
}
}
}
示例6: processJoint
import org.jbox2d.dynamics.joints.RevoluteJoint; //导入依赖的package包/类
@Override
public void processJoint(Joint argJoint, Long argTag) {
if(argTag == MOTOR_TAG){
m_motorJoint = (RevoluteJoint) argJoint;
m_motorOn = m_motorJoint.m_enableMotor;
}
}
示例7: createRevoluteJoint
import org.jbox2d.dynamics.joints.RevoluteJoint; //导入依赖的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);
}
示例8: initScene
import org.jbox2d.dynamics.joints.RevoluteJoint; //导入依赖的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();
}
示例9: initTest
import org.jbox2d.dynamics.joints.RevoluteJoint; //导入依赖的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);
}
}
示例10: init
import org.jbox2d.dynamics.joints.RevoluteJoint; //导入依赖的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();
}
示例11: init
import org.jbox2d.dynamics.joints.RevoluteJoint; //导入依赖的package包/类
@Override
public void init(GameContainer container, StateBasedGame game) throws SlickException {
this.motorSpeed = Utils.getRandomNumber(MAX_MOTOR_SPEED);
if (this.motorSpeed < MIN_MOTOR_SPEED) this.motorSpeed = MIN_MOTOR_SPEED;
//==Pivot============
BodyDef pivotDef = new BodyDef();
pivotDef.position.set(this.position);
Body pivot = this.world.createBody(pivotDef);
CircleDef cd = new CircleDef();
cd.radius = RADIUS * 0.1f;
cd.density = 0;
pivot.createShape(cd);
pivot.setMassFromShapes();
//==Rotator==========
BodyDef rotDef = new BodyDef();
rotDef.position.set(this.position);
Body rotator = this.world.createBody(rotDef);
//Massa do objeto.
MassData data = new MassData(0.1f, 1.0f, 0.1f);
//C�rculo da �rea que causa morte.
CircleDef crd = new CircleDef();
crd.radius = RADIUS;
data.setObjectMass(crd);
crd.userData = data;
rotator.createShape(crd);
//Ret�ngulo da �rea que se pode parar sem morrer.
PolygonDef sd = new PolygonDef();
sd.setAsBox(1.0f, 0.15f, new Vec2(0, 2.37f), 0);
sd.userData = false; //Indica que n�o causa morte.
rotator.createShape(sd);
rotator.setMassFromShapes();
rotator.setUserData(this);
//==Revolute Joint===
RevoluteJointDef rd = new RevoluteJointDef();
rd.initialize(pivot, rotator, this.position);
rd.enableMotor = true;
rd.motorSpeed = (Utils.getRandomNumber(2) == 1 ? 1 : -1) * this.motorSpeed;
rd.maxMotorTorque = MOTOR_TORQUE;
this.objBody = (RevoluteJoint) this.world.createJoint(rd);
//Define a tonalidade do som.
this.pitch = rd.motorSpeed / MAX_MOTOR_SPEED;
//Obt�m o objeto de som.
this.sfx = SoundPlayer.playObjRotatorMotor();
}
示例12: processJoint
import org.jbox2d.dynamics.joints.RevoluteJoint; //导入依赖的package包/类
@Override
public void processJoint(Joint argJoint, Long argTag) {
if (argTag == JOINT_TAG) {
joint = (RevoluteJoint) argJoint;
}
}
示例13: initTest
import org.jbox2d.dynamics.joints.RevoluteJoint; //导入依赖的package包/类
/**
* @see org.jbox2d.testbed.framework.TestbedTest#initTest(boolean)
*/
@Override
public void initTest(boolean argDeserialized) {
Body ground = null;
{
BodyDef bd = new BodyDef();
ground = getWorld().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 = getWorld().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)getWorld().createJoint(jd1);
BodyDef bd2 = new BodyDef();
bd2.type = BodyType.DYNAMIC;
bd2.position.set(0.0f, 12.0f);
Body body2 = getWorld().createBody(bd2);
body2.createFixture(circle2, 5.0f);
RevoluteJointDef jd2 = new RevoluteJointDef();
jd2.initialize(ground, body2, bd2.position);
m_joint2 = (RevoluteJoint)getWorld().createJoint(jd2);
BodyDef bd3 = new BodyDef();
bd3.type = BodyType.DYNAMIC;
bd3.position.set(2.5f, 12.0f);
Body body3 = getWorld().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)getWorld().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)getWorld().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)getWorld().createJoint(jd5);
}
}