Hello All,

I'm working on a game which takes place in a 3-d maze. I have been able to construct 
the maze and add the necassary key navigation, however I could not detect the 
collisions between an avatar (a shape3d object) I've put under the view transform 
group and the walls of the maze (again shape3d) which are under their own scene branch 
group.

I'm using a collision detector class which is very similar to the one used in the 
TickTockCollision example from the java3d demos. Where am I making the mistake?

Here is the code:

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;

import javax.media.j3d.*;
import javax.vecmath.*;

import com.sun.j3d.utils.applet.MainFrame; 
import com.sun.j3d.utils.geometry.ColorCube;

public class Maze3D extends Applet{
        
                        
        public class UniverseBuilder{
        
                public VirtualUniverse universe;
                public Locale locale;
                public View view;
                public ViewPlatform viewPlatform;
                public PhysicalBody body;
                public PhysicalEnvironment environment;
                public Avatar avatar;
                public BranchGroup viewBG;
                public TransformGroup  viewTG;
                        
                public UniverseBuilder(Canvas3D canvas) {

                        universe = new VirtualUniverse();
                        locale = new Locale(universe);
                        view = new View();
                        viewPlatform = new ViewPlatform();
                        body = new PhysicalBody();
                        environment = new PhysicalEnvironment();
                        avatar = new Avatar();
                                                
                        view.addCanvas3D(canvas);
                        view.setPhysicalBody(body);
                        view.setPhysicalEnvironment(environment);
                        
                        viewBG = new BranchGroup();
                        
                        Transform3D viewT3D = new Transform3D();                
                        viewT3D.set(new Vector3f(0.0f, 5.0f, 2.0f));
                        viewTG = new TransformGroup(viewT3D);
                        viewTG.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
                        viewTG.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
                        viewBG.setCapability(TransformGroup.ALLOW_CHILDREN_EXTEND);
                        viewBG.setCapability(TransformGroup.ALLOW_CHILDREN_WRITE);
                        viewBG.setCapability(TransformGroup.ALLOW_CHILDREN_READ);
                        viewPlatform.setActivationRadius(100000.0f);
                        
                        
                        CollisionDetector collide = new CollisionDetector(avatar);
                        collide.setSchedulingBounds(new BoundingBox(new 
Point3d(-1000,-1000,1000), new Point3d(1000,1000,1000)));
                        viewTG.addChild(collide);
                        
                        
                        viewTG.addChild(viewPlatform);
                        viewTG.addChild(avatar);
                        viewBG.addChild(viewTG);
                        
                        view.attachViewPlatform(viewPlatform);
                        locale.addBranchGraph(viewBG);
                }//constructor
        }//class UniverseBuilder
        
                
        public Maze3D() {
                        
                setLayout(new BorderLayout());
                Canvas3D canvas = new Canvas3D(null);
                add("Center", canvas);
                                
                UniverseBuilder u = new UniverseBuilder(canvas);
                                
                BranchGroup scene = createSceneGraph();
                u.viewBG.addChild(scene);
                
                KeyNavigator listener = new KeyNavigator(u.viewTG);
                canvas.addKeyListener(listener);
                                
                                                
        } //Maze3D = constructor
        
                
        public BranchGroup createSceneGraph() {
        
                // Create the root of the branch graph
                BranchGroup objRoot = new BranchGroup();
                
                Color3f black = new Color3f(0.0f, 0.0f, 0.0f);
                Color3f white = new Color3f(1.0f, 1.0f, 1.0f);

                for (int i=0; i< ConcretePath.vertex.length; i++) {
                        Room objTemp = new Room(ConcretePath.length[i], 
ConcretePath.vertex[i], ConcretePath.parallel[i]);
                        objRoot.addChild(objTemp);   
                }        
                                                                        

                objRoot.compile();
                return objRoot;
                
        } // end of CreateSceneGraph method
        
                
        public static void main(String[] args) {
                Frame frame = new MainFrame(new Maze3D(), 256, 256);
                frame.setTitle("Kara Murat");
                
        } //main method
        
} //maze3D class end


class Avatar extends Shape3D {
                
                ColorCube cube;
                BoundingSphere bounds;
                
                Avatar() {
                                        
                        cube = new ColorCube(5.0);
                        bounds = new BoundingSphere(new Point3d( 0.0,0.0,0.0 ),5);
                        setCollisionBounds(bounds); 
                }
}




Thank you for all your comments,
        

S. Ekin Kocabas
Bilkent University
[EMAIL PROTECTED]
=====================================================================
To subscribe/unsubscribe, send mail to [EMAIL PROTECTED]
Java 3D Home Page: http://java.sun.com/products/java-media/3D/

Reply via email to