Pr vertex intersection

Hello all



I have been idle for a while cause my wife and I had a daughter. But I am back and as a result I have questions :smiley:



I have been trying todo pr vertex intersection but I cant seem to get it working. if (A.getWorldBound().intersects(B.getWorldBound())) this evaluates to true but no vertexes intersect??



First a little background. Each of my ships is a node containing another node with the actual model.





I hope someone can spot an error.



/*
 * Created on 19-03-2004
 * Created by Oliver Billing
 */
package com.extorris.physics;

import java.util.ArrayList;
import java.util.Iterator;

import com.extorris.node.spaceship.Shuttle;
import com.extorris.physics.strategies.BounceStrategy;
import com.extorris.physics.strategies.CollisionResponseSpheres;
import com.jme.intersection.TriangleCollisionResults;
import com.jme.scene.Controller;
import com.jme.scene.Node;

/**
 * This singleton simulator handles all flight and intersection of objects in
 * space
 *
 * @author oliver billing
 * 
 */
public class PhysicalObjectsController extends Controller  {
   
   /** Calculating bounce for intersection */
   private BounceStrategy bounce = new CollisionResponseSpheres();
   
   /**List of physical objects*/
   private ArrayList physicalObjects;
   
   /**Super node for all physical objects*/
   //ArrayList pnode;
   
   /**Result set*/
   private TriangleCollisionResults results = new  TriangleCollisionResults();

   public PhysicalObjectsController() {
      super();
      physicalObjects = new ArrayList();
      //this.pnode =pnode;
      
   }
   
   public void removePhysicalobj(PhysicalObject obj){
      physicalObjects.remove(obj);
   }
   
   public void addPhysicalobj(PhysicalObject obj){
      physicalObjects.add(obj);
   }
   


   public void update(float time) {
      //OPTMIZEME:
      //n * n operation can be optimized to n log n by only checking A versus B
      // and not B versus A
      Iterator I = physicalObjects.listIterator();
      while (I.hasNext()) {
         Iterator II = physicalObjects.listIterator();
         Node A = (Node) I.next();
                  
         while (II.hasNext()) {
            Node B = (Node) II.next();
            
            if (!A.equals(B)) {
               //System.out.println("comparing "+  A.getName() + A.getWorldBound()+ " with " + B.getName() + B.getWorldBound());
               A.updateWorldBound();
               B.updateWorldBound();
               if (A.getWorldBound().intersects(B.getWorldBound())){
                  
                  //get the models and calculate their collisions
                   Shuttle As= (Shuttle)A;
                   Shuttle Bs= (Shuttle)B;
                  results.clear();
                  As.getModel().calculateCollisions(As.getModel(), results);
                  
                  if (results.getNumber() > 0) {
                     System.out.println("numbe rof results??" + results.getNumber());
                     for (int i = 0; i < results.getCollisionData(0).getSourceTris()
                           .size(); i++) {
                        
                        System.out.println("Resuuults");
                     }
                  }
                  
                  System.out.println("HIIIT");
                  //if intersection call the respective objects
                  //PhysicalObject objA = (PhysicalObject)A;
                  //PhysicalObject objB = (PhysicalObject)B;
                  //bounce.calcbounce(objA,objB);
               //   objA.showHitEffect();
                  
                  
                  
               }
                  
      
               }
            }
         
      }
      
   }
   

}

This isn’t really an answer to your problem per se, but it is possible for bounds to collide when their bounded meshes do not since bounds are just an approximation of the mesh’s volume… Probably not the issue here, but just thought I’d point that out.

Yep I tried that theory and removed my bounce resolve. The result was that the object A passed through object B without anything happening.



Perhaps I am assuming something I shouldent?



I mean I test my super node(Shuttle) or their worldbound, but when I check for vertex intersection I use a subnode (model). This is because it othervise would crash since one of the subnodes dont have a bound (and cant have one).

Why are you calling updateWorldBound? Maybe you mean updateModelBound? The bound only needs to be updated if the actual vertex data changes. If you translate or rotate or such, no updates are needed.


   /**
    *
    * <code>updateWorldBound</code> updates the bounding volume of the world.
    * Abstract, geometry transforms the bound while node merges the children's
    * bound. In most cases, users will want to call updateModelBound() and let
    * this function be called automatically during updateGeometricState().
    * 
    */



For A.getWorldBound().intersects(B.getWorldBound()) to work, both A and B need a bounds defined.

As.getModel().calculateCollisions(As.getModel(), results)



Should that be As and Bs? For As and Bs to work, you would also need to make sure updateCollisionTree is called when the models are created, and any time the actual vertex information of the models is changed. updateCollisionTree does not need to be called if the models are just transformed.

Hope this helps.

Well I found the As versus As myself. But the worldbound error I didnt see, but it shouldent have made any difference.



Anyway thanks for your help

Well the updateCollisionTree fixed it. But what now?



I want to retrive the vertexes or actually just one. How do I do that?



In the jME examples they work with Trimeshes I work with Nodes?



Thanks…


   if (results.getNumber() > 0) {
                     System.out.println("numbe rof results??" + results.getNumber());
                     for (int i = 0; i < results.getCollisionData(0).getTargetTris().size(); i++) {
                        
                        //int triIndex = ((Integer) results.getCollisionData(0).getSourceTris().get(i))
                        //.intValue();
                        //Bs.getModelgetgetTriangle(triIndex, indexBuffer);
                        //System.out.println("target tris" + results.getCollisionData(0).getTargetTris().get(i));
                     }
                  }

results should contain any triangle that intersects the two.

Yep but I get some kind of index. How do I use that to retrive actual coordinates

Collision data contains



private Geometry targetMesh;



private Geometry sourceMesh;



private ArrayList sourceTris;



private ArrayList targetTris;



You can get the exact triangle from that

Heh yep I am getting data. I hope this is the way todo it :-=



      if (results.getNumber() > 0) {
                     System.out.println("numbe rof results??" + results.getNumber());
                     for (int i = 0; i < results.getCollisionData(0).getTargetTris().size(); i++) {
                        int triIndex  =((Integer) results.getCollisionData(0).getTargetTris().get(i)).intValue();
                        
                        Vector3f[] vertices  = results.getCollisionData(0).getTargetMesh().getVertices();
                        System.out.println("coord??" + vertices[triIndex]);
                     }
                  }

Once you get the verticies, transform them by the world transforms of the mesh they belong to in order to get their real world coordinates.