Game Development Reference
In-Depth Information
This dynamics world is stepped by calling worldInstance.update() in the
render() method.
Game objects that are not visible in our camera are destroyed immediately.
The following code will check whether the rigid body is within the view. If not,
then the object will be removed and disposed:
for (UserData data : UserData.data) {
if (!data.isVisible(cam)) {
worldInstance.remove(data.getBody());
}
}
Add InputAdapter and ray testing as follows:
private final InputAdapter adapter = new InputAdapter() {
private Items item = Items.SPHERE;
private final Vector3 temp = new Vector3();
public boolean touchUp(int screenX, int screenY, int pointer, int
button) {
guiCam.unproject(temp.set(screenX, screenY, 0));
if (box.getBoundingRectangle().contains(temp.x, temp.y)) {
enableButton(box);
item = Items.BOX;
return true;
} else if (cone.getBoundingRectangle().contains(temp.x, temp.y)) {
enableButton(cone);
item = Items.CONE;
return true;
} else if (sphere.getBoundingRectangle().contains(temp.x, temp.y))
{
enableButton(sphere);
item = Items.SPHERE;
return true;
} else if (cylinder.getBoundingRectangle().contains(temp.x,
temp.y)) {
enableButton(cylinder);
item = Items.CYLINDER;
return true;
} else if (raypick.getBoundingRectangle().contains(temp.x,
temp.y)) {
enableButton(raypick);
item = Items.RAY_PICKING;
return true;
 
Search WWH ::




Custom Search