Ok. I got a picture to upload.
http://lotrolordsofbrotherhood.webs.com/photos/Random-Pics/asteroid2.jpg
Now you can see my geometries overlap and that my torpedo is made up of smaller geometries.
How do you not find your geometry if it’s in the gameRootNode? Here is how I generate asteroids and how I make my torpedo. (Sorry, I was experimenting with sub-classing nodes.)
(Also, 3 backticks has no effect for me using even the latest Chrome browser. Using block-quotes (") works. I just hope it comes out like I want it to.)
[code]
public AsteroidNode(String name, AssetManager assetManager, int count, int[] thing, int depth, int type, Vector3f translation, Vector3f velocity, Vector3f angles, Vector3f spin, float scale, boolean enabled){
super(name, assetManager, enabled);
this.assetManager = assetManager;
setDimension(1f, 1f, 1f);
//String name;
String tempName = thing[0] + "." + thing[1] + "." + thing[2] + "." + thing[3];
//System.out.println("AsteroidNode()" + " making name=" + name + ",depth=" + depth + ",scale=" + scale);
//setName(name);
attachChild(myGeometry = getWireSphere(tempName, (float)type));// + 0.25f//red
attachChild(getSphere(tempName, (float)type));
AsteroidControl control;
control = new AsteroidControl(assetManager, translation, velocity, angles, spin, type, true);
addControl(control);
control.setLocalTranslation(translation);
control.setVelocity(velocity);
control.setLocalRotation(angles);
control.setMass(1.0f);
////Node node = new AsteroidNode("", assetManager, 3, thing, depth + 1, LARGE, location.add(offset), velocity, rotation, spin, true);
if (type > 1 && true){
for (int a = 0;a < count;a++){
thing[depth] += 1;
String n = "Asteroid " + thing[0] + "." + thing[1] + "." + thing[2] + "." + thing[3];
Vector3f newAngles = new Vector3f((float)Math.random() * 0.001f, (float)Math.random() * 0.001f, (float)Math.random() * 0.001f);
float newScale = (4 - depth) * 2f;
Vector3f offset = Utilities.getRadianLocation((float)(Math.random() * (2f * Math.PI)), new Vector3f(newScale, newScale, newScale));
attachChild(new AsteroidNode(n, assetManager, count, thing, depth + 1, type - 1, offset, velocity, newAngles, spin, newScale, false));
}
}
thing[depth] = 0;
}//getTorpedo()
[\code]
And the Torpedo.
public TorpedoNode(String name, AssetManager assetManager, Vector3f translation, Vector3f velocity, Quaternion rotation, Vector3f spin, boolean enabled){
super(name = ("Torpedo#" + torpedoCount), assetManager, enabled);
this.assetManager = assetManager;
tempID = torpedoCount++;
setDimension(1f, 1f, 6f);
attachChild(myGeometry = getNosecone("Nosecone#" + tempID));
attachChild(getCylinder("Cylinder#" + tempID));
attachChild(getBell(new Vector3f(0.40f, 0.45f, 0.25f), new Vector3f(0f, 0f, -5.00f), 1));
attachChild(getBell(new Vector3f(0.45f, 0.50f, 0.25f), new Vector3f(0f, 0f, -5.25f), 2));
attachChild(getBell(new Vector3f(0.50f, 0.55f, 0.25f), new Vector3f(0f, 0f, -5.50f), 3));
attachChild(getFlame(new Vector3f(0.55f, 0.60f, 0.25f), new Vector3f(0f, 0f, -5.75f), 4));
attachChild(getFlame(new Vector3f(0.60f, 0.65f, 0.25f), new Vector3f(0f, 0f, -6.00f), 5));
attachChild(getFlame(new Vector3f(0.65f, 0.65f, 0.25f), new Vector3f(0f, 0f, -6.25f), 6));
attachChild(getFlame(new Vector3f(0.65f, 0.65f, 0.25f), new Vector3f(0f, 0f, -6.50f), 7));
attachChild(getFlame(new Vector3f(0.65f, 0.65f, 0.25f), new Vector3f(0f, 0f, -6.75f), 8));
attachChild(getFlame(new Vector3f(0.65f, 0.65f, 0.25f), new Vector3f(0f, 0f, -7.00f), 9));
attachChild(getFlame(new Vector3f(0.65f, 0.625f, 0.25f), new Vector3f(0f, 0f, -7.25f), 10));
attachChild(getFlame(new Vector3f(0.625f, 0.600f, 0.25f), new Vector3f(0f, 0f, -7.50f), 11));
attachChild(getFlame(new Vector3f(0.600f, 0.575f, 0.25f), new Vector3f(0f, 0f, -7.75f), 12));
attachChild(getFlame(new Vector3f(0.575f, 0.525f, 0.25f), new Vector3f(0f, 0f, -8.00f), 13));
attachChild(getFlame(new Vector3f(0.525f, 0.475f, 0.25f), new Vector3f(0f, 0f, -8.25f), 14));
attachChild(getFlame(new Vector3f(0.475f, 0.325f, 0.25f), new Vector3f(0f, 0f, -8.50f), 15));
attachChild(getFlame(new Vector3f(0.325f, 0.000f, 0.25f), new Vector3f(0f, 0f, -8.70f), 16));
//attachChild(getWireSphere("WireSphere#" + tempID, 0.5f));
//attachChild(getWireBox(dimension.x/2f, dimension.y/2f, dimension.z/2f, ColorRGBA.Green));//1, 1, 6
TorpedoControl control = new TorpedoControl(assetManager, true);
addControl(control);
control.setLocalTranslation(translation);
control.setVelocity(velocity);
control.setLocalRotation(rotation);
control.setMass(1.0f);
//control.setMyBounds(new BoundingSphere(0.5f, new Vector3f(0f, 0f, 0f)));
}//getTorpedo()
private Geometry getNosecone(String name){
//Geometry wireSphere = getWireSphere("WireSphere#" + tempID, 0.5f);
Dome dome = new Dome(new Vector3f(), 6, radialSamples, 0.5f, false);
//dome.setBound(new BoundingSphere(0.5f, new Vector3f(0f, 0f, 0f)));//
//dome.setBound(wireSphere.getModelBound());//new BoundingSphere(0.5f, new Vector3f(0f, 0f, 0f))
Geometry cone = new Geometry(name, dome);
Material mat;
mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setColor("Color", ColorRGBA.LightGray);
cone.setMaterial(mat);
//cone.setLocalTranslation(new Vector3f(0f, 0f, 0f));//don't change this
cone.setLocalRotation(new Quaternion().fromAngles(90 * FastMath.DEG_TO_RAD, 0f, 0f));
return(cone);
}
And the collision test
@Override
public void update(float tpf) {
if (isColliding() && true){
for (int a = 0;a < list.size();a++){
BaseNode p1 = (BaseNode)list.get(a);
MassControl mc1 = p1.getControl(MassControl.class);
//println("EM.update()" + " checking " + p1.getName() + ",(" + (a + 1) + "/" + list.size() + ")");
if (p1.isCollidable() && p1.getName().substring(0, 4).equals("Torp") && !p1.getName().equals("Torpedo#0")){//
BoundingVolume boundingVolume = null;
CollisionResults collisionResults = new CollisionResults();
//
int mode = 1;
if (mode == 0){//ray
Ray ray2 = new Ray(p1.getWorldTranslation().add(p1.getWorldRotation().getRotationColumn(Utilities.Z).mult(3f)), p1.getWorldRotation().getRotationColumn(Utilities.Z));
numCollisions = gameRootNode.collideWith(ray2, collisionResults);
}
else if (mode == 1){//boundingVolume
//boundingVolume = p1.getMyGeometry().getWorldBound();//or bound of nose cone alone//same result
boundingVolume = p1.getWorldBound();
//println("EM.update()" + " p1.name=" + p1.getName() + ",boundingVolume is null=" + (boundingVolume != null ? true:false));
println("EM.update()" + " p1.name=" + p1.getName() + ",boundingVolume=" + boundingVolume);
numCollisions = gameRootNode.collideWith(boundingVolume, collisionResults);//finds many hits, but does not blowup
}
//if (p1.getName().substring(0, 4).equals("Torp") && !p1.getName().equals("Torpedo 0"))
// println("EM.update()" + "p1.name=" + p1.getName() + ",boundingVolume=" + boundingVolume + ",number of collisions=" + numCollisions);
//if (p1.getName().substring(0, 3).equals("Ast"))
//println("EM.update()" + "name=" + p1.getName() + ",bv=" + mc1.getMyBounds() + ",number of collisions=" + numCollisions);
if (numCollisions > 0){
CollisionResult collisionResult;
//println("EM.update() " + "p1 name=" + p1.getName() + ",collisions=" + numCollisions);
if (mode == 0){//ray
collisionResult = collisionResults.getClosestCollision();
println("EM.update() " + "closestCollision=" + collisionResult.getGeometry().getName() + ",parent=" + collisionResult.getGeometry().getParent().getName() + ",dist=" + collisionResult.getDistance());
if (collisionResult.getDistance() < 1f){
p1.setUserData("hit", true);
collisionResult.getGeometry().getParent().setUserData("hit", true);
println();
}
}
else if (mode == 1){//boundingVolume
println("EM.update()" + " display collisions (" + numCollisions + ")");
Iterator<CollisionResult> targetList = collisionResults.iterator();
int d = 0;
while(targetList.hasNext() && d < numCollisions){
collisionResult = targetList.next();
println("EM.update() " + " result#(" + (d + 1) +"/" + numCollisions + ")=p1 name=" + p1.getName() + ",name=" + collisionResult.getGeometry().getName() + ",parent=" + collisionResult.getGeometry().getParent().getName() + ",boundingVolume=" + boundingVolume + ",bounds=" + collisionResult.getGeometry().getWorldBound() + ",distance=" + collisionResult.getDistance());
d++;
}
println();
}
}
}
}
}
//System.out.println("EM.update() end");
//println("EM.update() done");
}//update()
And the output.
EM.update() display collisions (1880)
EM.update() p1.name=Torpedo#1,boundingVolume=BoundingBox [Center: (0.0, -1.325, -4.1625) xExtent: 0.65 yExtent: 1.325 zExtent: 4.6625]
EM.update() result#(1/1880)=p1 name=Torpedo#1,name=Nosecone#1,parent=Torpedo#1,boundingVolume=BoundingBox [Center: (0.0, -1.325, -4.1625) xExtent: 0.65 yExtent: 1.325 zExtent: 4.6625],bounds=BoundingBox [Center: (5.628708E-13, -2.0, 0.24999999) xExtent: 0.5 yExtent: 0.5 zExtent: 0.25],distance=0.0
EM.update() result#(2/1880)=p1 name=Torpedo#1,name=Nosecone#1,parent=Torpedo#1,boundingVolume=BoundingBox [Center: (0.0, -1.325, -4.1625) xExtent: 0.65 yExtent: 1.325 zExtent: 4.6625],bounds=BoundingBox [Center: (5.628708E-13, -2.0, 0.24999999) xExtent: 0.5 yExtent: 0.5 zExtent: 0.25],distance=0.0
…
EM.update() result#(16/1880)=p1 name=Torpedo#1,name=Nosecone#1,parent=Torpedo#1,boundingVolume=BoundingBox [Center: (0.0, -1.325, -4.1625) xExtent: 0.65 yExtent: 1.325 zExtent: 4.6625],bounds=BoundingBox [Center: (5.628708E-13, -2.0, 0.24999999) xExtent: 0.5 yExtent: 0.5 zExtent: 0.25],distance=0.0
EM.update() result#(17/1880)=p1 name=Torpedo#1,name=Cylinder#1,parent=Torpedo#1,boundingVolume=BoundingBox [Center: (0.0, -1.325, -4.1625) xExtent: 0.65 yExtent: 1.325 zExtent: 4.6625],bounds=BoundingBox [Center: (5.628708E-13, -2.0, -2.5) xExtent: 0.5 yExtent: 0.5 zExtent: 2.5],distance=0.0
EM.update() result#(18/1880)=p1 name=Torpedo#1,name=Cylinder#1,parent=Torpedo#1,boundingVolume=BoundingBox [Center: (0.0, -1.325, -4.1625) xExtent: 0.65 yExtent: 1.325 zExtent: 4.6625],bounds=BoundingBox [Center: (5.628708E-13, -2.0, -2.5) xExtent: 0.5 yExtent: 0.5 zExtent: 2.5],distance=0.0