Hi Koen,

   Attache are two tests that out output a print statement
when view hit the colorcube. One use WakeupOnCollisionEntry/Exit
and another use WakeupOnViewPlatformEntry.
The view is moved by using the keybaord arrow key.
This should work well with v1.2.1 release.

- Kelvin
-----------
Java 3D Team
Sun Microsystems Inc.


>MIME-Version: 1.0
>X-Priority: 3
>X-MSMail-Priority: Normal
>X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200
>Date: Mon, 26 Mar 2001 20:09:06 +0200
>From: Koen Vanderloock <[EMAIL PROTECTED]>
>Subject: [JAVA3D] View collision
>To: [EMAIL PROTECTED]
>
>Hi all,
>
>Is there anyone who can send me an example prog where the
wakeUpOnCollisionEntry is used with view.
>Because when the view hits my colorcube there isn't any event triggered, and I
can't find the problem
>
>Thx in advance,
>Koen,
>
/*
 *      @(#)CollisionGroup.java 1.3 99/09/15 13:37:45
 *
 * Copyright (c) 1996-1999 Sun Microsystems, Inc. All Rights Reserved.
 *
 * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
 * modify and redistribute this software in source and binary code form,
 * provided that i) this copyright notice and license appear on all copies of
 * the software; and ii) Licensee does not utilize the software in a manner
 * which is disparaging to Sun.
 *
 * This software is provided "AS IS," without a warranty of any kind. ALL
 * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
 * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
 * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
 * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
 * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
 * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
 * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
 * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
 * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGES.
 *
 * This software is not designed or intended for use in on-line control of
 * aircraft, air traffic, aircraft navigation or aircraft communications; or in
 * the design, construction, operation or maintenance of any nuclear
 * facility. Licensee represents and warrants that it will not use or
 * redistribute the Software for such purposes.
 */

import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Frame;
import java.awt.event.*;
import java.awt.GraphicsConfiguration;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.universe.*;
import com.sun.j3d.utils.geometry.*;
import javax.media.j3d.*;
import javax.vecmath.*;
import com.sun.j3d.utils.behaviors.keyboard.KeyNavigatorBehavior;


public class CollisionGroup extends Applet {

    public CollisionGroup() {
        setLayout(new BorderLayout());
        GraphicsConfiguration config =
            SimpleUniverse.getPreferredConfiguration();

        Canvas3D canvas = new Canvas3D(config);
        add("Center", canvas);

        SimpleUniverse universe = new SimpleUniverse(null, 2, canvas, null);
        universe.getViewingPlatform().setNominalViewingTransform();
        universe.getViewer().getView().setBackClipDistance(100);

        BranchGroup scene = createSceneGraph();

        TransformGroup vpTrans =
            universe.getViewingPlatform().getViewPlatformTransform();
        KeyNavigatorBehavior keyNavBeh = new KeyNavigatorBehavior(vpTrans);
        keyNavBeh.setSchedulingBounds(new BoundingSphere(new Point3d(0, 0, 0), 1000));
        scene.addChild(keyNavBeh);

        ViewerAvatar avatar = new ViewerAvatar();
        avatar.addChild(new ColorCube(0.5f));

        CollisionDetectorGroup coll = new CollisionDetectorGroup(avatar);
        coll.setSchedulingBounds(new BoundingSphere(new Point3d(0, 0, 0), 1000));
        avatar.addChild(coll);
        universe.getViewer().setAvatar(avatar);
        scene.compile();
        universe.addBranchGraph(scene);
    }

    public BranchGroup createSceneGraph() {
        TransformGroup tg2;
        BranchGroup root = new BranchGroup();
        root.setCapability(Node.ENABLE_COLLISION_REPORTING);

        BranchGroup br1 = new BranchGroup();
        br1.setCapability(Node.ENABLE_COLLISION_REPORTING);

        Transform3D tr1 = new Transform3D();
        tr1.rotY(Math.PI/4);
        TransformGroup tg1 = new TransformGroup(tr1);
        tg1.setCapability(Node.ENABLE_COLLISION_REPORTING);

        Transform3D tr2 = new Transform3D();
        tr2.setTranslation(new Vector3d(0, 0, -30));
        tg2 = new TransformGroup(tr2);
        tg2.setCapability(Node.ENABLE_COLLISION_REPORTING);

        tg2.setCapability(Node.ENABLE_COLLISION_REPORTING);
        tg2.setCapability(Group.ALLOW_COLLISION_BOUNDS_READ);
        tg2.setCapability(Node.ALLOW_BOUNDS_READ);
        tg2.setBounds(new BoundingSphere(new Point3d(0,0,0), 1.7));
        tg2.addChild(tg1);

        Shape3D s1 = new ColorCube();
        tg1.addChild(s1);
        br1.addChild(tg2);
        root.addChild(br1);
        return root;
    }

    public static void main(String args[]) {
        new MainFrame(new CollisionGroup(), 800, 600);
    }
}
/*
 *      @(#)CollisionDetectorGroup.java 1.4 99/09/15 13:37:43
 *
 * Copyright (c) 1996-1999 Sun Microsystems, Inc. All Rights Reserved.
 *
 * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
 * modify and redistribute this software in source and binary code form,
 * provided that i) this copyright notice and license appear on all copies of
 * the software; and ii) Licensee does not utilize the software in a manner
 * which is disparaging to Sun.
 *
 * This software is provided "AS IS," without a warranty of any kind. ALL
 * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
 * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
 * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
 * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
 * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
 * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
 * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
 * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
 * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGES.
 *
 * This software is not designed or intended for use in on-line control of
 * aircraft, air traffic, aircraft navigation or aircraft communications; or in
 * the design, construction, operation or maintenance of any nuclear
 * facility. Licensee represents and warrants that it will not use or
 * redistribute the Software for such purposes.
 */

import javax.media.j3d.*;
import javax.vecmath.*;
import java.util.Enumeration;

public class CollisionDetectorGroup extends Behavior {

    protected Node node;
    protected WakeupCondition wakeup;

    public CollisionDetectorGroup(Node node) {
        this.node = node;
    }

    public void initialize() {
        WakeupCriterion [] criterions = new WakeupCriterion[3];
        criterions[0] = new WakeupOnCollisionEntry(node);
        criterions[1] = new WakeupOnCollisionMovement(node);
        criterions[2] = new WakeupOnCollisionExit(node);
        wakeup = new WakeupOr(criterions);
        wakeupOn(wakeup);
    }

    public void processStimulus(Enumeration criteria) {

        while(criteria.hasMoreElements()) {
            WakeupCondition cond = (WakeupCondition) criteria.nextElement();

            if (cond instanceof WakeupOnCollisionEntry){
                System.out.println("\nenter ");
            } else if (cond instanceof WakeupOnCollisionExit) {
                System.out.println("\nexit");
            } else if (cond instanceof WakeupOnCollisionMovement) {
                System.out.print("m");
                System.out.flush();
            }
        }
        wakeupOn(wakeup);
    }


}
/*
 *      @(#)ViewPlatformEntryTest.java 1.2 99/09/15 13:37:51
 *
 * Copyright (c) 1996-1999 Sun Microsystems, Inc. All Rights Reserved.
 *
 * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
 * modify and redistribute this software in source and binary code form,
 * provided that i) this copyright notice and license appear on all copies of
 * the software; and ii) Licensee does not utilize the software in a manner
 * which is disparaging to Sun.
 *
 * This software is provided "AS IS," without a warranty of any kind. ALL
 * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
 * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
 * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
 * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
 * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
 * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
 * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
 * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
 * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGES.
 *
 * This software is not designed or intended for use in on-line control of
 * aircraft, air traffic, aircraft navigation or aircraft communications; or in
 * the design, construction, operation or maintenance of any nuclear
 * facility. Licensee represents and warrants that it will not use or
 * redistribute the Software for such purposes.
 */

import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Frame;
import java.awt.event.*;
import java.awt.GraphicsConfiguration;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.universe.*;
import com.sun.j3d.utils.geometry.*;
import javax.media.j3d.*;
import javax.vecmath.*;
import com.sun.j3d.utils.behaviors.keyboard.KeyNavigatorBehavior;


public class ViewPlatformEntryTest extends Applet {

    public ViewPlatformEntryTest() {
        setLayout(new BorderLayout());
        GraphicsConfiguration config =
            SimpleUniverse.getPreferredConfiguration();

        Canvas3D canvas = new Canvas3D(config);
        add("Center", canvas);

        SimpleUniverse universe = new SimpleUniverse(canvas);
        universe.getViewingPlatform().setNominalViewingTransform();
        universe.getViewer().getView().setBackClipDistance(100);

        BranchGroup scene = createSceneGraph();
        ViewingPlatform viewPlatform = universe.getViewingPlatform();
        // approx. size of avatar
        viewPlatform.getViewPlatform().setActivationRadius(1.0f);
        TransformGroup vpTrans =  viewPlatform.getViewPlatformTransform();
        KeyNavigatorBehavior keyNavBeh = new KeyNavigatorBehavior(vpTrans);
        keyNavBeh.setSchedulingBounds(new BoundingSphere(new Point3d(0, 0, 0), 1000));
        scene.addChild(keyNavBeh);

        ViewerAvatar avatar = new ViewerAvatar();
        avatar.addChild(new ColorCube(0.5f));

        universe.getViewer().setAvatar(avatar);
        scene.compile();
        universe.addBranchGraph(scene);
    }

    public BranchGroup createSceneGraph() {
        TransformGroup tg2;
        BranchGroup root = new BranchGroup();

        BranchGroup br1 = new BranchGroup();

        Transform3D tr1 = new Transform3D();
        tr1.rotY(Math.PI/4);
        TransformGroup tg1 = new TransformGroup(tr1);
        tg1.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

        Transform3D tr2 = new Transform3D();
        tr2.setTranslation(new Vector3d(0, 0, -30));
        tg2 = new TransformGroup(tr2);

        tg2.setCapability(Node.ALLOW_BOUNDS_READ);
        BoundingSphere sphere = new BoundingSphere(new Point3d(0,0,0), 1.7);
        tg2.setBounds(sphere);
        tg2.addChild(tg1);

        Shape3D s1 = new ColorCube();
        tg1.addChild(s1);
        br1.addChild(tg2);

//  Add WakeupOnViewPlatformEntry/Exit behavior
        ViewPlatformDetector behav = new ViewPlatformDetector(sphere);
        behav.setSchedulingBounds(new BoundingSphere(new Point3d(0, 0, 0), 1000));
        tg1.addChild(behav);


// Add a behavour under Group to translate the cube
        Alpha alpha = new Alpha(-1, Alpha.INCREASING_ENABLE |
                                Alpha.DECREASING_ENABLE,
                                0, 0,
                                1000, 300, 40,
                                1000, 400, 50);

        // Create a bounds for the behaviors
        BoundingSphere bounds =
            new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0);
        PositionInterpolator interpolator =
            new PositionInterpolator(alpha, tg1,
                                     new Transform3D(),
                                     -5, 5);
        interpolator.setSchedulingBounds(bounds);
        tg1.addChild(interpolator);

        root.addChild(br1);
        return root;
    }

    public static void main(String args[]) {
        new MainFrame(new ViewPlatformEntryTest(), 800, 600);
    }
}
/*
 *      @(#)ViewPlatformDetector.java 1.2 99/09/15 13:37:50
 *
 * Copyright (c) 1996-1999 Sun Microsystems, Inc. All Rights Reserved.
 *
 * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
 * modify and redistribute this software in source and binary code form,
 * provided that i) this copyright notice and license appear on all copies of
 * the software; and ii) Licensee does not utilize the software in a manner
 * which is disparaging to Sun.
 *
 * This software is provided "AS IS," without a warranty of any kind. ALL
 * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
 * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
 * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
 * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
 * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
 * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
 * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
 * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
 * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGES.
 *
 * This software is not designed or intended for use in on-line control of
 * aircraft, air traffic, aircraft navigation or aircraft communications; or in
 * the design, construction, operation or maintenance of any nuclear
 * facility. Licensee represents and warrants that it will not use or
 * redistribute the Software for such purposes.
 */

import javax.media.j3d.*;
import javax.vecmath.*;
import java.util.Enumeration;

public class ViewPlatformDetector extends Behavior {

    protected WakeupOnViewPlatformEntry wakeupEntry;
    protected WakeupOnViewPlatformExit wakeupExit;

    public ViewPlatformDetector(Bounds bound) {
        wakeupEntry = new WakeupOnViewPlatformEntry(bound);
        wakeupExit = new WakeupOnViewPlatformExit(bound);
    }

    public void initialize() {
        wakeupOn(wakeupEntry);
    }

    public void processStimulus(Enumeration criteria) {

        if (criteria.nextElement() instanceof WakeupOnViewPlatformEntry){
            System.out.println("\nenter ");
            wakeupOn(wakeupExit);
        } else {
            System.out.println("\nexit");
            wakeupOn(wakeupEntry);

        }
    }


}

Reply via email to