Collision detection classes

I’m currently trying to get get my camera/view to navigate around a room (an ASE file) in xith using the recent collision detection classes which were added.

How in theory would I do this?

I have created references to each wall & the floor in my room from the ASE file. Do I need to add CollisionCodes to each wall & then add a CollisionNode to my camera/view via its Transform node & then finally add these to the CollisionSystem?

If I do I can’t seem to get it to work.

Any help as usuall will be gratefully recieved. :slight_smile:

This is driving me a bit mad :frowning:

I’m trying to navigate around as the camera the ASE file I have loaded up - which is a basic room. I have added a CollisionNode to the rightwall, so when I translate hopefully I’ll hit it. I’ve also added a CollisionNode to the TransformGroup holding the view. Nothing changes ???
I’ve tried quite a lot of things, but here’s the basic code without all the fiddly hacks.





public class ColTest04 implements KeyListener
{
      TransformGroup objTranslate = null;
      Transform3D translate = null;
      TransformGroup objRotate = null;
      Transform3D rotate = null; 
      TransformGroup room = null; //entire room
      TransformGroup rightwall = null; 
      View view = null;
      Canvas3D canvas = null;
      Vector3f position = new Vector3f(0.0f, 15.0f, 0.0f);
      Vector3f angle = new Vector3f(0.0f, -90.0f, 0.0f);
      CollisionSystem cs = new CollisionSystem(-1);


      public static void main(String[] args)
      {
      try
        {
            ColTest04 test = new ColTest04();
        }
      catch(Exception e) {}
      }


      public ColTest04() throws Exception
      {
            TextureLoader.tf.registerPath("./");

            VirtualUniverse universe = new VirtualUniverse();
            view = new View();
            universe.addView(view);

            Locale locale = new Locale(5.0f, 0.0f, 10.0f);
            universe.addLocale(locale);

            BranchGroup scene = new BranchGroup();
            locale.addBranchGraph(scene);

            //load ASE file
            AseFile af = new AseFile();
            BufferedReader br = null;
            try
            {
                br = new BufferedReader(new FileReader("2ndgo.ASE"));
            }
            catch(IOException e)
            {
                URL url = getClass().getClassLoader().getResource("2ndgo.ASE");
                br = new BufferedReader(new InputStreamReader(url.openStream()));
            }
            AseReader r = new AseReader(br, af);
            af.parse(r);

            HashMap namedNodes = new HashMap();
            room = af.getTransformGroupTree(namedNodes);
            scene.addChild(room);

            Collection c = namedNodes.keySet();
            for(Iterator i = c.iterator(); i.hasNext(); System.out.println(i.next()));

            //add collision to rightwall
            rightwall.setName("rightwall");
            ColliderGeometry cgRightWall = new ColliderGeometry();
            cgRightWall.setModel(rightwall);
            BiTreeCollider bic = new BiTreeCollider();
            bic.build(cgRightWall);
            ColliderNode rightwallNode = new ColliderNode(rightwall, ColliderNode.CT_GEOMETRY, 
                  ColliderNode.CT_GEOMETRY, false, bic);
            cs.addCollider(rightwallNode);

            //create tranform node to hold view & let view along this path translate
            translate = new Transform3D();
            objTranslate = new TransformGroup(translate);
            translate.setTranslation(position);
            objTranslate.setTransform(translate); 
            scene.addChild(objTranslate);
               
            // let view along this path rotate
            rotate = new Transform3D();
            rotate.rotXYZ(0.0f, 0.0f, 0.0f);
            objRotate = new TransformGroup(rotate);
            objRotate.setTransform(rotate);
            //make it a child of TransformGroup/objTranslate
            objTranslate.addChild(objRotate);

            //add collision to transform node which holds view
            objTranslate.setName("view");
            ColliderGeometry cv = new ColliderGeometry();
              cv.setModel(objTranslate);
            BiTreeCollider bic2 = new BiTreeCollider();
            bic2.build(cv);
            ColliderNode viewNode = new ColliderNode(objTranslate, 
                  ColliderNode.CT_ELLIPSOID, ColliderNode.CT_GEOMETRY, true, bic2, new Coord3f(0,0,0));
            Force gravity = new ForceGravity();
            viewNode.addForce(gravity);
            cs.addCollider(viewNode);

            
            // create a canvas for our graphics 
            RenderPeer rp = new RenderPeerImpl(); 
            CanvasPeer cp = rp.makeCanvas(null, 640, 480, 16, false); 
            canvas = new Canvas3D(); 
            canvas.set3DPeer(cp); 

            cp.getComponent().addKeyListener(this);
      
            // modify our view 
            view.addCanvas3D(canvas); 

            start(view);
      }


      private void moveCamera(Vector3f position, Vector3f angle) 
      { 
            translate.set(position); 

            rotate.rotY((float) Math.toRadians(angle.y)); 
            translate.mul(rotate); 

            rotate.rotX((float) Math.toRadians(angle.x)); 
            translate.mul(rotate); 

            rotate.rotZ((float) Math.toRadians(angle.z)); 
            translate.mul(rotate); 

            view.setTransform(translate); 
      }


      public void start(View view) 
      { 
            while (true)
            {
                  moveCamera(position, angle);

                  view.renderOnce(); 

                  cs.newFrame(10);
            }
      }



    public void keyPressed(KeyEvent e) 
    {
      if(e.getKeyCode() == KeyEvent.VK_LEFT)
        {
            angle.y = angle.y + 5.0f;
        }
      //etc........................
    }

    public void keyTyped(KeyEvent e) {}

    public void keyReleased(KeyEvent e) {}

}


I think the solution is something to do with view & the registration of the CollisionNode for it. But I could be wrong.

Thanks.

I am having similar problems and dont seem to get it to work. Does anybody knwo how this works, better still any examples anywhere :frowning: