Hi,

I try to add a MouseTranslate Behavior in a scene, where the view branch
graph is not created using SimpleUniverse.
The program teminates with the following exception:

java.lang.NullPointerException
        at
javax.media.j3d.BehaviorRetained.updateTransformRegion(BehaviorRetained.java:458)
        at
javax.media.j3d.BehaviorStructure.activateBehaviors(BehaviorStructure.java:347)
        at
javax.media.j3d.BehaviorStructure.processMessages(BehaviorStructure.java:209)
        at
javax.media.j3d.StructureUpdateThread.doWork(StructureUpdateThread.java:83)
        at javax.media.j3d.J3dThread.run(J3dThread.java:250)

That somewhere in Java3D and means nothing to me?
What am I doing wrong?
A testcase is attached.
Outcommenting of the line
world_object_group.addChild(trans);
leads to a running programm, ofcourse without behavior.

Desiree


oooooooooooooooooooooooooooooooooooooooooooooooo
Desiree Hilbring

Institut fuer Photogrammetrie und Fernerkundung
Universitaet Karlsruhe, Germany
email: [EMAIL PROTECTED]
# 0721 6083676
oooooooooooooooooooooooooooooooooooooooooooooooo

/*****************************************************************************
 *                        J3D.org Copyright (c) 2000
 *                               Java Source
 *
 * This source is licensed under the GNU LGPL v2.1
 * Please read http://www.gnu.org/copyleft/lgpl.html for more information
 *
 * This software comes with the standard NO WARRANTY disclaimer for any
 * purpose. Use it at your own risk. If there's a problem you get to fix it.
 *
 ****************************************************************************/

// Standard imports
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.media.j3d.*;
import javax.vecmath.*;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.HashMap;

import com.sun.j3d.utils.behaviors.mouse.*;
import com.sun.j3d.utils.geometry.ColorCube;

public class NavTest extends DemoFrameDesTest
{
    // Achtung front und back hardcodiert
    private static final double BACK_CLIP_DISTANCE = 3000.0;
    private static final double FRONT_CLIP_DISTANCE = 1;

    /** The main canvas that we are navigating on */
    private Canvas3D navCanvas;

    /** Global material instance to use */
    private Material material;

    /** Global polygon attributes to use */
    private PolygonAttributes polyAttr;

    /** TG that holds the user view position. Used when new terrain set */
    private TransformGroup gndViewTransform;

    /** The color interpolator for doing height interpolations with */
    //private ColorInterpolator heightRamp;

    /**
     * Construct a new demo with no geometry currently showing, but the
     * default type is set to quads.
     */
    public NavTest()
    {
        super("NavTest");

        navCanvas = createCanvas();

        Panel p0 = new Panel(new GridLayout(1, 2));
        p0.add(navCanvas);

        add(p0, BorderLayout.CENTER);

        JPanel p1 = new JPanel(new FlowLayout());

        buildScene();

        // Now set up the material and appearance handling for the generator
        material = new Material();
        material.setLightingEnable(true);

        polyAttr = new PolygonAttributes();
        polyAttr.setCapability(PolygonAttributes.ALLOW_MODE_WRITE);
        polyAttr.setCullFace(PolygonAttributes.CULL_NONE);
        polyAttr.setBackFaceNormalFlip(true);
        polyAttr.setPolygonMode(PolygonAttributes.POLYGON_FILL);

        loadTerrain(new String(),new String());
    }

    //----------------------------------------------------------
    // Internal convenience methods
    //----------------------------------------------------------

    /**
     * Build the scenegraph for the canvas
     */
    private void buildScene()
    {
        Color3f ambientBlue = new Color3f(0.0f, 0.02f, 0.5f);
        Color3f white = new Color3f(1, 1, 1);
        Color3f black = new Color3f(0.0f, 0.0f, 0.0f);
        Color3f blue = new Color3f(0.00f, 0.20f, 0.80f);
        Color3f specular = new Color3f(0.7f, 0.7f, 0.7f);

        VirtualUniverse universe = new VirtualUniverse();
        Locale locale = new Locale(universe);

        BranchGroup view_group = new BranchGroup();
        BranchGroup world_object_group = new BranchGroup();

        PhysicalBody body = new PhysicalBody();
        PhysicalEnvironment env = new PhysicalEnvironment();

        Point3d origin = new Point3d(0, 0, 0);
        BoundingSphere light_bounds =
            new BoundingSphere(origin, BACK_CLIP_DISTANCE);
        DirectionalLight headlight = new DirectionalLight();
        headlight.setColor(white);
        headlight.setInfluencingBounds(light_bounds);
        headlight.setEnable(true);

        ViewPlatform gnd_camera = new ViewPlatform();

        Transform3D angle = new Transform3D();

        gndViewTransform = new TransformGroup();
        gndViewTransform.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
        gndViewTransform.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

        gndViewTransform.addChild(gnd_camera);
        gndViewTransform.addChild(headlight);

        View gnd_view = new View();
        gnd_view.setBackClipDistance(BACK_CLIP_DISTANCE);
        gnd_view.setFrontClipDistance(FRONT_CLIP_DISTANCE);
        gnd_view.setPhysicalBody(body);
        gnd_view.setPhysicalEnvironment(env);
        gnd_view.addCanvas3D(navCanvas);
        gnd_view.attachViewPlatform(gnd_camera);

        //System.out.println("front clip dist "+gnd_view.getFrontClipDistance());
        //System.out.println("back clip dist "+gnd_view.getBackClipDistance());

        view_group.addChild(gndViewTransform);  

        TransformGroup testBoxTG = new TransformGroup();
        Transform3D testBoxT3d = new Transform3D();
        testBoxT3d.setTranslation(new Vector3f(50,3510,-50));
        testBoxTG.setTransform(testBoxT3d);
        testBoxTG.addChild(new ColorCube(10));
        world_object_group.addChild(testBoxTG);

        BoundingSphere mouseBounds = new BoundingSphere(new 
Point3d(),Float.MAX_VALUE);
        BoundingLeaf boundingLeaf = new BoundingLeaf(mouseBounds);

        /*
        ViewerNavigationBehavior rotate = new 
ViewerNavigationBehavior(gndViewTransform,gnd_view);
        rotate.setSchedulingBoundingLeaf(boundingLeaf);
        */
        
        MouseTranslate trans = new MouseTranslate(MouseBehavior.INVERT_INPUT);
        trans.setTransformGroup(gndViewTransform);
        trans.setSchedulingBoundingLeaf(boundingLeaf);
        
        /*
        WorldVolume wv = new WorldVolume();
        MouseZoomAdjustView zoom = new 
MouseZoomAdjustView(MouseBehavior.INVERT_INPUT,gnd_view,wv);
        zoom.setTransformGroup(gndViewTransform);
        zoom.setSchedulingBoundingLeaf(boundingLeaf);
        */

        //world_object_group.addChild(rotate);
        world_object_group.addChild(trans);
        //world_object_group.addChild(zoom);

        // Add everything to the locale
        locale.addBranchGraph(view_group);
        locale.addBranchGraph(world_object_group);
    }

    /**
     * Load the terrain and get it read to roll. If the texture file is not
     * specified then no texture will be loaded and colour information is
     * used instead.
     *
     * @param filename The name of the terrain file
     * @param textureName The name of the texture file, or null
     */
    private void loadTerrain(String filename, String textureName)
    {
        
        //System.gc();
        
        System.out.println("Loading terrain file. Please wait!!!!!!!!!!!!!!!!!!!!");

        Point3d p3dmin = new Point3d();
        Point3d p3dmax = new Point3d();
        
        float[] origin = new float[3];
        //terrain.getCoordinate(origin, 1, 1);
        origin[0]=50;
        origin[1]=3500;
        origin[2]=-50;
        System.out.println("origin[] "+origin[0]+" "+origin[1]+" "+origin[2]);
        
        Transform3D angle = new Transform3D();
        
        // setup the top view by just raising it some amount and we want
        Vector3f pos = new Vector3f();
        pos.x = origin[0];
        pos.y = origin[1];
        pos.z = origin[2]+100;

        angle.setTranslation(pos);

        System.out.println("Building landscape 3");     
        
        gndViewTransform.setTransform(angle);

        System.out.println("Building landscape 4");            
        
        /*
        Matrix3f mtx = new Matrix3f();
        Vector3f orient = new Vector3f(0, 0, -1);
        
        angle.get(mtx, pos);
        mtx.transform(orient);  
        */
    }

    public static void main(String[] argv)
    {
        NavTest demo = new NavTest();
        demo.setSize(600, 400);
        demo.setVisible(true);
    }
}
/*****************************************************************************
 *                        J3D.org Copyright (c) 2000
 *                               Java Source
 *
 * This source is licensed under the GNU LGPL v2.1
 * Please read http://www.gnu.org/copyleft/lgpl.html for more information
 *
 * This software comes with the standard NO WARRANTY disclaimer for any
 * purpose. Use it at your own risk. If there's a problem you get to fix it.
 *
 ****************************************************************************/

// Standard imports
import java.awt.*;
import java.awt.event.*;

import javax.media.j3d.Canvas3D;
import javax.media.j3d.GraphicsConfigTemplate3D;

// Application Specific imports
// none

/**
 * Demonstration of a mouse navigation in a world.
 *
 * @author Justin Couch
 * @version $Revision: 1.1 $
 */
public class DemoFrameDesTest extends Frame implements WindowListener
{
    public DemoFrameDesTest(String title)
    {
        super(title);

        setLocation(30, 10);
        addWindowListener(this);
    }

    /**
     * Creates a new canvas each time this is called.
     *
     * @return A new canvas instance
     */
    protected Canvas3D createCanvas()
    {
        Canvas3D canvas;

        GraphicsConfigTemplate3D template = new GraphicsConfigTemplate3D();
        template.setDoubleBuffer(template.REQUIRED);
        GraphicsEnvironment env =
            GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsDevice dev = env.getDefaultScreenDevice();
        //System.out.println("env "+env.toString());
        //System.out.println("dev "+dev.toString());
        //System.out.println("template "+template.toString());

        canvas = new Canvas3D(dev.getBestConfiguration(template));
        canvas.setStereoEnable(false);
        canvas.setDoubleBufferEnable(true);
        //canvas.setDoubleBufferEnable(false);

        System.out.println("Canvas "+canvas);
        return canvas;
    }

    /**
     * Ignored
     */
    public void windowActivated(WindowEvent evt)
    {
    }

    /**
     * Ignored
     */
    public void windowClosed(WindowEvent evt)
    {
    }

    /**
     * Exit the application
     *
     * @param evt The event that caused this method to be called.
     */
    public void windowClosing(WindowEvent evt)
    {
        System.exit(0);
    }

    /**
     * Ignored
     */
    public void windowDeactivated(WindowEvent evt)
    {
    }

    /**
     * Ignored
     */
    public void windowDeiconified(WindowEvent evt)
    {
    }

    /**
     * Ignored
     */
    public void windowIconified(WindowEvent evt)
    {
    }

    /**
     * Ignored
     */
    public void windowOpened(WindowEvent evt)
    {
    }
}

Reply via email to