Title: Problem in Collision

Hi All,
         I am facing one problem regarding collision. I had made one application in which I had made all objects pick able. So that user can pick a particular object and place that object at desired position. I want that when one object collides with another, then the earlier object should go back to original position. But the problems I am facing are:-

    1.      When one object collides with other at that time my process stimulus method is executed two times.
    2.      How do I get the starting co-ordinates of  the particular object?

I am sending the collisionDetector class code and also from where I am calling that class...


package visualizer.client;
import java.util.Enumeration;
import javax.media.j3d.*;
import javax.vecmath.*;

public class CollisionDetector extends Behavior
{
        private BranchGroup bGroup = new BranchGroup();
    private boolean inCollision = false;

    private WakeupOnCollisionEntry wEnter;
    //private WakeupOnCollisionExit wExit;


    public CollisionDetector(BranchGroup bGroup)
    {
                this.bGroup=bGroup;
                inCollision = false;
    }

    public void initialize()
    {
                wEnter = new WakeupOnCollisionEntry(bGroup);
                //wExit = new WakeupOnCollisionExit(bGroup);
                wakeupOn(wEnter);
    }

    public void processStimulus(Enumeration criteria)
    {
                //inCollision = !inCollision;

                /*if (inCollision)
                {
                        System.out.println("hello");
                wakeupOn(wExit);
                }*/
                if(wEnter.hasTriggered())
                {
                        System.out.println("in different");
                        wakeupOn(wEnter);
                }
    }
    public BranchGroup getBranchGroup()
    {
                return bGroup;
        }
}


From where I am calling the above class....here for every object(take the example of car assembly, the objects are tyres, stepny etc..) and this I had made with the help of all primitives. and here bGroup is one object....

                if(blockPick[blocks].equals("true"))
                {
                        Transform3D blockTranslation = new Transform3D();

                        TransformGroup blockTranslationGroup = new TransformGroup(blockTranslation);

                        bGroup.setCapability(BranchGroup.ALLOW_BOUNDS_READ);
                        bGroup.setCapability(BranchGroup.ALLOW_BOUNDS_WRITE);
                        BoundingSphere bounds = new BoundingSphere(bGroup.getBounds());

                        //its for after splitting user can translate the particular object
                        PickTranslateBehavior behavior=null;
                        //PickingCallback callback=null;
                        if(splitTrue)
                        {
                                //Vector3d vec1=new Vector3d();
                                //blockTranslation.get(vec1);
                                //System.out.println("vec1.x: "+vec1.x);
                                //System.out.println("vec1.y: "+vec1.y);
                                //System.out.println("vec1.z: "+vec1.z);
                                behavior = new  PickTranslateBehavior(bGroup, canvas, bounds);
                                //behavior.setupCallback(callback);
                                //behavior.transformChanged(2,blockTranslation);
                                bGroup.addChild(behavior);
                                //Vector3d vec=new Vector3d();
                                //blockTranslation.get(vec);
                                //System.out.println("vec.x: "+vec.x);
                                //System.out.println("vec y: "+vec.y);
                                //System.out.println("vec z: "+vec.z);
                        }


                        blockTranslationGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
                        blockTranslationGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);

                        blockTranslationGroup.setCapability(TransformGroup.ENABLE_PICK_REPORTING);

                        //it is working without enabling the collision
                        //blockTranslationGroup.setCapability(TransformGroup.ENABLE_COLLISION_REPORTING);

                        PickHighlightBehavior pickbehavior;
                        if(splitTrue && !blockPage[blocks].equals("none"))
                                pickbehavior = new PickHighlightBehavior(canvas, bGroup, bounds, appletContext, sessionId, blockPage[blocks]);

                        //this is to detect the collision
                        //now collision is detected but the probelm is we want to set the object at its
                        //default position if there is any collision..but don't have right idea..

                        if(splitTrue)
                        {
                                CollisionDetector cd = new CollisionDetector(bGroup);
                                cd.setSchedulingBounds(bounds);
                                bGroup.addChild(cd);
                                BranchGroup bG=cd.getBranchGroup();
                                blockTranslationGroup.addChild(bG);
                        }
                        else
                                blockTranslationGroup.addChild(bGroup);

                        bMainGroup.addChild(blockTranslationGroup);
               
                }
                else
                        bMainGroup.addChild(bGroup);
         }

    return bMainGroup;
  }
Amit Jindal
Software Engineer,
Selectica India Pvt. Ltd,
4th Floor, Sharda Arcade,
Pune Satara Road,
Pune-411037, Maharashtra.
India.
Office - 0204211906/07/08
Mobile - 9822295494


Reply via email to