Help on a HelloPicking Exercise

I’ve done all of the tutorials through HelloEffects (as well as all of the exercises for each) and started on my game development journey, but I ran into an issue that lead me back to the HelloPicking tutorial. Link for reference.

What if I wanted to expand the collision volume of a box in the tutorial? I started looking in to BoundingVolumes, but I wasn’t sure if those only pertain to physics.

My attempt at rewriting the makeCube() looks like:
[java]
protected Geometry makeCube(String name, float x, float y, float z)
{
Box box = new Box(1, 1, 1);
Geometry cube = new Geometry(name, box);
cube.setLocalTranslation(x, y, z);
Material mat1 = new Material(this.assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);
mat1.setColor(“Color”, ColorRGBA.randomColor());
cube.setMaterial(mat1);

BoundingBox boundingBox = new BoundingBox(Vector3f.ZERO, 1.5f, 1.5f, 1.5f);
cube.setModelBound(boundingBox);
cube.updateModelBound();
return cube;

}[/java]

Am I aiming in the right direction? (Get it? :stuck_out_tongue_winking_eye: )

I’m not sure what the code you’ve posted is supposed to do but I can tell you what it does do…

  1. create a box 2,2,2 (1,1,1 extents)
  2. create geometry for that box
  3. set it to x,y,z
  4. create an unshaded material
  5. assign it a random color
  6. set the material on that geometry
    …so far so good
  7. create a bounding box 3,3,3 (1.5 extents)
  8. set that to the geometry
  9. recalculate the bounding shape thereby returning it to its original 2,2,2 bounds.

I think this last part is not really what you mean to do.

At any rate, picking is done on the actual mesh. So if the mesh is only 2,2,2 then that’s all you’ll pick no matter what the size of the bounding volume.

Ah, thanks! I must have misread about the updateModelBound() then. More importantly, it’s good to know about picking being done on the actual mesh.

What would be a correct way to have a geometry with a 2,2,2 visible mesh but a 3,3,3 “pickable” volume?

2,2,2 visible mesh and a second geometry with a 3,3,3 mesh but with cull hint set to always. (picking is done even on culled objects).

2 Likes

Perfect, thanks for your help!

I ultimately created a Cylinder that will act as the shape for these purposes.

[java]
// create cube shape
Box cube = new Box(0.5f, 1, 0.5f);
Geometry cubeGeometry = new Geometry("Character Cube " + id, cube);
Material material = new Material(this.assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);
material.setColor(“Color”, color);
cubeGeometry.setMaterial(material);
node.attachChild(cubeGeometry);

// create collision cylinder
Cylinder cylinder = new Cylinder(4, 12, 1.5f, 2, true);
Geometry collisionGeometry = new Geometry(“Collision Cylinder” + id, cylinder);
collisionGeometry.setUserData(“characterId”, id);
collisionGeometry.rotate(FastMath.HALF_PI, 0, 0);
Material wirematerial = new Material(this.assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);
wirematerial.setColor(“Color”, ColorRGBA.Gray);
wirematerial.getAdditionalRenderState().setWireframe(true);
collisionGeometry.setMaterial(wirematerial);
// collisionGeometry.setCullHint(CullHint.Always);
node.attachChild(collisionGeometry);
[/java]

(I have the Cull Hint commented out until I’m finished with debugging.)