Game Development Reference
In-Depth Information
createJoint(RigidBodyControl body1, RigidBodyControl
body2)
11. First, we find out the location that should be the pivot point of body2 . This is the
same as physicsLocation of body2 subtracted from physicsLocation
of body1 , as follows:
Vector3f pivotPointB =
body1.getPhysicsLocation().subtract(body2.getPhysicsLocation());
12. Then, we define Point2PointJoint by joining the two segments. The vec-
tors supplied mean that body2 will pivot in a way that is relative to body1 ; we
do this using the following code:
Point2PointJoint joint = new Point2PointJoint(body1,
body2, Vector3f.ZERO, pivotPointB);
13. We then add the newly created joint to the joints list and to physicsSpace .
We're now getting to the controls of the application and need another method to help us.
The method will check whether a mouse click has hit any segment and return it. To do
this, perform the following steps:
1. We define a new method called checkSelection , which returns Ri-
gidBodyControl .
2. Inside this method, we create a new Ray instance, which will have the current
mouse cursor's location as the origin; the following code tells you how to do this:
Ray ray = new Ray();
ray.setOrigin(cam.getWorldCoordinates(inputManager.getCursorPosition(),
0f));
3. Since the view is orthographic, we let the direction be Vector3f(0, 0,
-1f) .
4. Now, we define a new CollisionResults instance to store any segments that
Ray collides with.
5. The next thing we do is parse through the segment's list and check whether the
ray hits any of them.
6. If it does, we're done, and then return RigidBodyControl of segment to the
calling method.
Search WWH ::




Custom Search