+36
-27
lines changedFilter options
+36
-27
lines changed Original file line number Diff line number Diff line change
@@ -711,6 +711,30 @@ public RopeJoint addRopeJoint(Entity e1, Entity e2, Point2D localAnchor1, Point2
711
711
return addJoint(e1, e2, def);
712
712
}
713
713
714
+
/**
715
+
* Add a prismatic joint (a slider along a given axis) between two entities.
716
+
* More details: https://en.wikipedia.org/wiki/Prismatic_joint
717
+
*
718
+
* @param e1 entity1
719
+
* @param e2 entity2
720
+
* @param axis the axis along which to slide
721
+
* @param limit max slide distance in pixels
722
+
* @return joint
723
+
*/
724
+
public PrismaticJoint addPrismaticJoint(Entity e1, Entity e2, Point2D axis, double limit) {
725
+
checkJointRequirements(e1, e2);
726
+
727
+
var p1 = e1.getComponent(PhysicsComponent.class);
728
+
var p2 = e2.getComponent(PhysicsComponent.class);
729
+
730
+
var def = new PrismaticJointDef();
731
+
def.initialize(p1.getBody(), p2.getBody(), p2.getBody().getWorldCenter(), toVector(axis));
732
+
def.enableLimit = true;
733
+
def.upperTranslation = toMetersF(limit);
734
+
735
+
return addJoint(e1, e2, def);
736
+
}
737
+
714
738
/**
715
739
* Add a joint constraining two entities with PhysicsComponent.
716
740
* The entities must already be in the game world.
Original file line number Diff line number Diff line change
@@ -16,76 +16,61 @@
16
16
* coincide in world space. Using local anchors and a local axis helps when saving and loading a
17
17
* game.
18
18
*
19
-
* @warning at least one body should by dynamic with a non-fixed rotation.
20
-
* @author Daniel
19
+
* Note: at least one body should by dynamic with a non-fixed rotation.
21
20
*
21
+
* @author Daniel
22
22
*/
23
23
public class PrismaticJointDef extends JointDef<PrismaticJoint> {
24
24
25
-
26
25
/**
27
26
* The local anchor point relative to body1's origin.
28
27
*/
29
-
public final Vec2 localAnchorA;
28
+
public final Vec2 localAnchorA = new Vec2();
30
29
31
30
/**
32
31
* The local anchor point relative to body2's origin.
33
32
*/
34
-
public final Vec2 localAnchorB;
33
+
public final Vec2 localAnchorB = new Vec2();
35
34
36
35
/**
37
36
* The local translation axis in body1.
38
37
*/
39
-
public final Vec2 localAxisA;
38
+
public final Vec2 localAxisA = new Vec2(1.0f, 0.0f);
40
39
41
40
/**
42
41
* The constrained angle between the bodies: body2_angle - body1_angle.
43
42
*/
44
-
public float referenceAngle;
43
+
public float referenceAngle = 0.0f;
45
44
46
45
/**
47
46
* Enable/disable the joint limit.
48
47
*/
49
-
public boolean enableLimit;
48
+
public boolean enableLimit = false;
50
49
51
50
/**
52
51
* The lower translation limit, usually in meters.
53
52
*/
54
-
public float lowerTranslation;
53
+
public float lowerTranslation = 0.0f;
55
54
56
55
/**
57
56
* The upper translation limit, usually in meters.
58
57
*/
59
-
public float upperTranslation;
58
+
public float upperTranslation = 0.0f;
60
59
61
60
/**
62
61
* Enable/disable the joint motor.
63
62
*/
64
-
public boolean enableMotor;
63
+
public boolean enableMotor = false;
65
64
66
65
/**
67
66
* The maximum motor torque, usually in N-m.
68
67
*/
69
-
public float maxMotorForce;
68
+
public float maxMotorForce = 0.0f;
70
69
71
70
/**
72
71
* The desired motor speed in radians per second.
73
72
*/
74
-
public float motorSpeed;
75
-
76
-
public PrismaticJointDef() {
77
-
localAnchorA = new Vec2();
78
-
localAnchorB = new Vec2();
79
-
localAxisA = new Vec2(1.0f, 0.0f);
80
-
referenceAngle = 0.0f;
81
-
enableLimit = false;
82
-
lowerTranslation = 0.0f;
83
-
upperTranslation = 0.0f;
84
-
enableMotor = false;
85
-
maxMotorForce = 0.0f;
86
-
motorSpeed = 0.0f;
87
-
}
88
-
73
+
public float motorSpeed = 0.0f;
89
74
90
75
/**
91
76
* Initialize the bodies, anchors, axis, and reference angle using the world anchor and world
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4