Excuse Me, I have encountered a problem that when I setNumSamples for the FilterPostProcessor, the screen turned black. Could you help me?
Here is my code:
public class SelectObjectTest extends SimpleApplication {
public static void main(String[] args) {
SelectObjectTest app = new SelectObjectTest();
app.setShowSettings(false);
app.start();
}
private Node shootables;
private Geometry mark;
SelectObjectOutliner outliner;
@Override
public void simpleInitApp() {
flyCam.setMoveSpeed(10);
initCrossHairs(); // a "+" in the middle of the screen to help aiming
initKeys(); // load custom key mappings
initMark(); // a red sphere to mark the hit
/** create four colored boxes and a floor to shoot at: */
shootables = new Node("Shootables");
rootNode.attachChild(shootables);
shootables.attachChild(makeCube("a Dragon", -2f, 0f, 1f));
shootables.attachChild(makeCube("a tin can", 1f, -2f, 0f));
shootables.attachChild(makeCube("the Sheriff", 0f, 1f, -2f));
shootables.attachChild(makeCube("the Deputy", 1f, 0f, -4f));
shootables.attachChild(makeBall("Shandy", 3f, -1f, 2f));
shootables.attachChild(makeFloor());
// shader
FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
viewPort.addProcessor(fpp);
fpp.setNumSamples(16);
//Declare
outliner=new SelectObjectOutliner();
//Init - using filter
outliner.initOutliner(SelectObjectOutliner.OUTLINER_TYPE_FILTER, 2, ColorRGBA.Yellow,shootables,fpp, renderManager, assetManager, cam);
//Init - using material
//outliner.initOutliner(SelectObjectOutliner.OUTLINER_TYPE_MATERIAL, 2, ColorRGBA.Magenta,shootables,fpp, renderManager, assetManager, cam);
}
/** Declaring the "Shoot" action and mapping to its triggers. */
private void initKeys() {
inputManager.addMapping("Shoot",
new KeyTrigger(KeyInput.KEY_SPACE), // trigger 1: spacebar
new MouseButtonTrigger(MouseInput.BUTTON_LEFT)); // trigger 2: left-button click
inputManager.addListener(actionListener, "Shoot");
}
/** Defining the "Shoot" action: Determine what was hit and how to respond. */
private ActionListener actionListener = new ActionListener() {
public void onAction(String name, boolean keyPressed, float tpf) {
if (name.equals("Shoot") && !keyPressed) {
// 1. Reset results list.
CollisionResults results = new CollisionResults();
// 2. Aim the ray from cam loc to cam direction.
Ray ray = new Ray(cam.getLocation(), cam.getDirection());
// 3. Collect intersections between Ray and Shootables in results list.
// DO NOT check collision with the root node, or else ALL collisions will hit the
// skybox! Always make a separate node for objects you want to collide with.
shootables.collideWith(ray, results);
// 4. Print the results
System.out.println("----- Collisions? " + results.size() + "-----");
for (int i = 0; i < results.size(); i++) {
// For each hit, we know distance, impact point, name of geometry.
float dist = results.getCollision(i).getDistance();
Vector3f pt = results.getCollision(i).getContactPoint();
String hit = results.getCollision(i).getGeometry().getName();
System.out.println("* Collision #" + i);
System.out.println(" You shot " + hit + " at " + pt + ", " + dist + " wu away.");
}
// 5. Use the results (we mark the hit object)
if (results.size() > 0) {
// The closest collision point is what was truly hit:
CollisionResult closest = results.getClosestCollision();
// Let's interact - we mark the hit with a red dot.
mark.setLocalTranslation(closest.getContactPoint());
rootNode.attachChild(mark);
//select
Geometry nextGeo=closest.getGeometry();
if(selectedGeo==null || selectedGeo!=nextGeo)
{
if(selectedGeo!=null )
outliner.deselect(selectedGeo);
selectedGeo=nextGeo;
outliner.select(selectedGeo);
}
} else {
// No hits? Then remove the red mark.
rootNode.detachChild(mark);
//
if(selectedGeo!=null)
outliner.deselect(selectedGeo);
selectedGeo=null;
}
}
}
};