Dragging a Scene Graph Segment

Have jReality programming problems or questions? Post them here.
Post Reply
karunaMaitri
Posts: 90
Joined: Sun 16. Nov 2008, 00:24

Dragging a Scene Graph Segment

Post by karunaMaitri » Thu 16. Sep 2010, 11:12

I am working on a problem in which I should be able to drag a segment of Scene Graph by dragging the root node of that branch. To illustrate it, I created an example program in which there are two points (Cyan and Red). The red point scene graph component is a child of cyan point scene graph component. I would like the red point to be dragged when I drag cyan point. But it is not working. I have attached my code. Please see the code inside pointDragged() method. I tried four different approaches.
You can see "Method1"..., "Method4", inside comments. You need to uncomment the code under each one of these methods to test them. I have also added my comments to indicate the failures in each case.

Can you tell me why it is not working and also how to make it work - that is: to be able to drag red point when I drag cyan point.

Code: Select all

import java.awt.Color;
import java.awt.Font;

import BASIC_TOOLS.ConsolePrinter;
import de.jreality.geometry.CoordinateSystemFactory;
import de.jreality.geometry.IndexedFaceSetFactory;
import de.jreality.geometry.IndexedLineSetFactory;
import de.jreality.geometry.PointSetFactory;
import de.jreality.geometry.Primitives;
import de.jreality.geometry.TubeFactory;
import de.jreality.math.MatrixBuilder;
import de.jreality.plugin.JRViewer;
import de.jreality.scene.Appearance;
import de.jreality.scene.Geometry;
import de.jreality.scene.IndexedFaceSet;
import de.jreality.scene.IndexedLineSet;
import de.jreality.scene.PointSet;
import de.jreality.scene.SceneGraphComponent;
import de.jreality.scene.data.Attribute;
import de.jreality.scene.data.StorageModel;
import de.jreality.shader.DefaultGeometryShader;
import de.jreality.shader.DefaultLineShader;
import de.jreality.shader.DefaultPointShader;
import de.jreality.shader.DefaultPolygonShader;
import de.jreality.shader.RenderingHintsShader;
import de.jreality.shader.ShaderUtility;
import de.jreality.tools.DragEventTool;
import de.jreality.tools.PointDragEvent;
import de.jreality.tools.PointDragListener;
import de.jreality.util.SceneGraphUtility;

public class DragSceneGraphTool { 
    private SceneGraphComponent sceneGraph;
    private SceneGraphComponent cubeOfPoints; 
    private double d = 20.0; 
    private SceneGraphComponent sphere;
    private SceneGraphComponent sphere2;
    private PointSetFactory psf;
    private PointSetFactory psf2; 

    /**
     * @param args
     */
    public static void main(String[] args) {
        DragSceneGraphTool tool = new DragSceneGraphTool();
    }
    
    public DragSceneGraphTool(){
        sceneGraph = setUpSceneGraph(new double[]{0.0, 0.0, 0.0});
        setUpCoordinateSystem(sceneGraph);
        setUpTool();
        JRViewer.display(sceneGraph);
    }
    
    public SceneGraphComponent setUpSceneGraph(double[] loc){
        cubeOfPoints = setUpCubeOfPoints();
        sphere = setUpTwoPoints(loc);
        //backgroundSGC = setUpBackground();
        cubeOfPoints.addChild(sphere);
        //mobileBall.addChild(backgroundSGC);
        return cubeOfPoints;
        //return mobileBall;
    }
    
    public SceneGraphComponent setUpCubeOfPoints(){
        SceneGraphComponent sgc = SceneGraphUtility.createFullSceneGraphComponent("Cube of Points");
         PointSetFactory psf = new PointSetFactory();   
         
            double [][] vertices = new double[][] {
                     {-d, -d, d}, {d, -d, d}, {d, d, d}, {-d, d, d},
                     {-d, -d, -d}, {d, -d, -d}, {d, d, -d}, {-d, d, -d}
                    };
            psf.setVertexCount( vertices.length );
            psf.setVertexCoordinates( vertices );
            psf.update();
            sgc.setGeometry(psf.getPointSet());
            Appearance ap = sgc.getAppearance();
            DefaultGeometryShader dgs = ShaderUtility.createDefaultGeometryShader(ap, true);
            dgs.setShowFaces(false);
            dgs.setShowLines(false);
            dgs.setShowPoints(true);
            DefaultPointShader dpts = (DefaultPointShader) dgs.createPointShader("default");
            dpts.setDiffuseColor(Color.BLUE);
            dpts.setPointRadius(0.5);
            sgc.setAppearance(ap);
            return sgc;
    }
    
    public void setUpSinglePoint(SceneGraphComponent sgc, double x, double y, double z, Color color, int index){
         
            double [][] vertices = new double[][] {
                     {x, y, z}
                    }; 
            if (index == 1){
                psf = new PointSetFactory();   
                psf.setVertexCount( vertices.length );
                psf.setVertexCoordinates( vertices );
                psf.update();
                sgc.setGeometry(psf.getPointSet());
            } 
            if (index == 2){
                psf2 = new PointSetFactory();   
                psf2.setVertexCount( vertices.length );
                psf2.setVertexCoordinates( vertices );
                psf2.update();
                sgc.setGeometry(psf2.getPointSet());
            }
            Appearance ap = sgc.getAppearance();
            DefaultGeometryShader dgs = ShaderUtility.createDefaultGeometryShader(ap, true);
            dgs.setShowFaces(false);
            dgs.setShowLines(false);
            dgs.setShowPoints(true);
            DefaultPointShader dpts = (DefaultPointShader) dgs.createPointShader("default");
            dpts.setDiffuseColor(color);
            dpts.setPointRadius(1.0);
            sgc.setAppearance(ap);
    }
    
    public SceneGraphComponent setUpTwoPoints(double[] location){
        sphere = SceneGraphUtility.createFullSceneGraphComponent("SinglePoint");
        setUpSinglePoint(sphere, location[0], location[1], location[2], Color.CYAN, 1);
        sphere2 = SceneGraphUtility.createFullSceneGraphComponent("2ndSinglePoint");
        setUpSinglePoint(sphere2, location[0]+10.0, location[1] +10.0, location[2] +10.0, Color.RED, 2);
        sphere.addChild(sphere2);
        MatrixBuilder.euclidean().translate(d, d, d).assignTo(sphere);
        return sphere;
    }
    
    public void setUpTool() {
        System.out.println("Entered setUpTool >>>>");
        DragEventTool t = new DragEventTool();
        t.addPointDragListener(new PointDragListener() {

            public void pointDragStart(PointDragEvent e) {
                System.out.println("Entered pointDragStart >>>>");
            }

            public void pointDragged(PointDragEvent e) {
                System.out.println("Entered pointDragged >>>>");
                //Method1: Not working, both points do not event move
                double[] location = e.getPosition();
                sceneGraph = setUpSceneGraph(location);
                System.out.println("Location: [" + location[0] + ", " + location[1] +  ", " + location[2] + "");
                
                //Method2: Adding a point wrongly shows that array out of bound
                //psf.setVertexCoordinates(e.getPosition());
                //psf.update();        
                
                //Method3: Both points can be move, but indepedently
            /*    PointSet pointSet = e.getPointSet();
                double[][] points=new double[pointSet.getNumPoints()][];
                pointSet.getVertexAttributes(Attribute.COORDINATES).toDoubleArrayArray(points);
                points[e.getIndex()]=e.getPosition();  
                pointSet.setVertexAttributes(Attribute.COORDINATES,StorageModel.DOUBLE_ARRAY.array(3).createReadOnly(points));*/            
               
                //Method4: Points do not move
              /*  double[] location = e.getPosition();      
                System.out.println("Location: [" + location[0] + ", " + location[1] +  ", " + location[2] + "");
                sphere.getGeometry().getAttributes(Geometry.CATEGORY_VERTEX, Attribute.COORDINATES).toDoubleArray(location);*/
        }

            public void pointDragEnd(PointDragEvent e) {
                System.out.println("Entered pointDragEnd >>>>");
            
            }
        });
        sceneGraph.addTool(t);
    }
    
    public void setUpCoordinateSystem(SceneGraphComponent component) {
        // create coordinate system
        double axisScale = 5.0;
        final CoordinateSystemFactory coords = new CoordinateSystemFactory(
                component, axisScale);
        // SET PROPERTIES:

        Font font = new Font("TimesRoman", Font.PLAIN, 40);
        coords.setAxisScale(axisScale);
        coords.setLabelScale(0.015);
        // coords.showBox(true);
        // coords.showBoxArrows(true);
        coords.showAxesArrows(true);
        coords.showLabels(true);
        // coords.setColor(Color.RED);
        // coords.setGridColor(Color.GRAY);
        coords.setLabelColor(Color.BLACK);
        coords.setLabelFont(font);
        coords.setColor(Color.BLUE);

        // display axes/box/grid
        coords.showAxes(true);
        // coords.showBox(true);
        coords.showGrid(true);

        // beautify box
        //coords.beautify(true);
    }
    
     public int[][] createEdgeIndices(double[][] points) {
          int[][] edges = new int[points.length - 1][2];

          for (int i = 0; i < points.length - 1; i++) {
             edges[i][0] = i;
             edges[i][1] = i + 1;
          }
          return edges;
       }
}
Thanks,
Karuna

karunaMaitri
Posts: 90
Joined: Sun 16. Nov 2008, 00:24

Re: Dragging a Scene Graph Segment

Post by karunaMaitri » Fri 17. Sep 2010, 06:33

In my last post I have forgotten to add the most important segment of code :oops: : translating the root node of the segment (a side effect of working till 2AM :( ). I am sorry about that.

I have added the code below. This code should go inside pointDragged()

Code: Select all

 PointSet pointSet = e.getPointSet();
                double[][] points=new double[pointSet.getNumPoints()][];
                pointSet.getVertexAttributes(Attribute.COORDINATES).toDoubleArrayArray(points);
                int index = e.getIndex();
                double[] oldLocation = points[index]; 
                System.out.println("Old Location: [" + oldLocation[0] + ", " + oldLocation[1] +  ", " + oldLocation[2] + "]");
                double[] location = e.getPosition();    
                System.out.println("Location: [" + location[0] + ", " + location[1] +  ", " + location[2] + "");
                double[] translation = new double[]{location[0] - oldLocation[0], location[1] - oldLocation[1], location[2] - oldLocation[2]};
                System.out.println("Translation: [" + translation[0] + ", " + translation[1] +  ", " + translation[2] + "");
                //points[index]=location;
                //pointSet.setVertexAttributes(Attribute.COORDINATES,StorageModel.DOUBLE_ARRAY.array(3).createReadOnly(points));            
                MatrixBuilder.euclidean().translate(translation[0], translation[1], translation[2]).assignTo(sphere);   
It is working, but not very well. It is showing the following problem behaviors:
  • 1. The points are jumping! There is no smooth movement that we can expect for moving a single point (uncomment the commented statements and then comment the last statement in the above code).
  • 2. Then the points are not moving to the cursor point. I think this is happening because "translation" does not capture the required distance. How do we capture the correct distance? I think ToolContext.getTransformationMatrix() captures this movement. But we do not have access to it in DragEventTool. How do we capture it?
  • 3. You might have also noticed that the arrows on the coordinate axes are missing. This is the side-effect I have observed when you add points to the scene. How can we get back the arrows for the coordinate axes?
Can you let me know how we can address these problems.

Thanks,
Karuna

User avatar
gunn
Posts: 323
Joined: Thu 14. Dec 2006, 09:56
Location: TU Berlin
Contact:

Re: Dragging a Scene Graph Segment

Post by gunn » Fri 17. Sep 2010, 13:07

I looked a bit at the original code and indeed wondered why you weren't using any transformations. Now you've added a translation, that looks better. However there are still two things which bother me and may have to do with the problems you are noticing:

1) In the original version of pointDragged(), you call setupSceneGraph(). I don't understand why. If you are just dragging the scene graph around (using the translation which your second post provided) then there's no reason I can see to redefine the scene graph each time.
2) When you initialize the scene graph component named sphere, you set the transformation to be a translation by (d,d,d). Now, in the code you added in your second post, you are overwriting this transformation with a translation determined from the picking information. That will cause jumping! I'd recommend to insert an extra scene graph node to hold the translation by (d,d,d), as a parent of the sphere node, and leave sphere alone so it can just has the single transformation provided by your tool. If you do that, then I'd also recommend that you add the tool to the sphere node instead of higher up in the scene graph, since it's action is limited to the sphere node (as far as I can tell). It's generally safer to put the tool as close as possible to where it acts, to avoid conflicts with other transformations along the scene graph path.
jReality core developer

karunaMaitri
Posts: 90
Joined: Sun 16. Nov 2008, 00:24

Re: Dragging a Scene Graph Segment

Post by karunaMaitri » Sat 18. Sep 2010, 09:20

Thank you for the reply and the suggestions.

For your point1, I was testing my code in different ways. Calling setupSceneGraph() inside pointDragged() method was only an initial test I was trying. I did not include it in my final version, which was in my last post.

For your second point, I made all the changes you suggested. Unfortunately, it is still not working. I need your help.
In fact, I have tried it on two examples - the first one is the point drag (last two posts) example, the second one is dragging two cubes (a modification of TransformationListenerExample in tutorials/tform). In the second example, I had to violate one of your suggestions - use transform to move the 2nd cube.

Both show the same problems, which I listed in the last post.

Example1:

Code: Select all

import java.awt.Color;
import java.awt.Font;

import BASIC_TOOLS.ConsolePrinter;
import de.jreality.geometry.CoordinateSystemFactory;
import de.jreality.geometry.IndexedFaceSetFactory;
import de.jreality.geometry.IndexedLineSetFactory;
import de.jreality.geometry.PointSetFactory;
import de.jreality.geometry.Primitives;
import de.jreality.geometry.TubeFactory;
import de.jreality.math.Matrix;
import de.jreality.math.MatrixBuilder;
import de.jreality.math.Rn;
import de.jreality.plugin.JRViewer;
import de.jreality.scene.Appearance;
import de.jreality.scene.Geometry;
import de.jreality.scene.IndexedFaceSet;
import de.jreality.scene.IndexedLineSet;
import de.jreality.scene.PointSet;
import de.jreality.scene.SceneGraphComponent;
import de.jreality.scene.data.Attribute;
import de.jreality.scene.data.StorageModel;
import de.jreality.scene.pick.PickResult;
import de.jreality.scene.tool.AbstractTool;
import de.jreality.scene.tool.InputSlot;
import de.jreality.scene.tool.ToolContext;
import de.jreality.shader.DefaultGeometryShader;
import de.jreality.shader.DefaultLineShader;
import de.jreality.shader.DefaultPointShader;
import de.jreality.shader.DefaultPolygonShader;
import de.jreality.shader.RenderingHintsShader;
import de.jreality.shader.ShaderUtility;
import de.jreality.tools.DragEventTool;
import de.jreality.tools.FaceDragEvent;
import de.jreality.tools.FaceDragListener;
import de.jreality.tools.PointDragEvent;
import de.jreality.tools.PointDragListener;
import de.jreality.util.SceneGraphUtility;

public class DragSceneGraphTool {
    private SceneGraphComponent sceneGraph;
    private SceneGraphComponent cubeOfPoints;
    private double d = 20.0;
    private SceneGraphComponent point1;
    private SceneGraphComponent point2;
    private SceneGraphComponent pointLocation;

    /**
     * @param args
     */
    public static void main(String[] args) {
        DragSceneGraphTool tool = new DragSceneGraphTool();
    }

    public DragSceneGraphTool() {
        sceneGraph = setUpSceneGraph(new double[] { 0.0, 0.0, 0.0 });
        setUpCoordinateSystem(sceneGraph);
        setUpTool();
        JRViewer.display(sceneGraph);
    }
    

    public SceneGraphComponent setUpSceneGraph(double[] loc) {
        cubeOfPoints = setUpCubeOfPoints();
        pointLocation = setUpTwoPoints(loc);
        cubeOfPoints.addChild(pointLocation);
        return cubeOfPoints;
    }

    public SceneGraphComponent setUpCubeOfPoints() {
        SceneGraphComponent sgc = SceneGraphUtility
                .createFullSceneGraphComponent("Cube of Points");
        PointSetFactory psf = new PointSetFactory();
        double[][] vertices = new double[][] { { -d, -d, d }, { d, -d, d },
                { d, d, d }, { -d, d, d }, { -d, -d, -d }, { d, -d, -d },
                { d, d, -d }, { -d, d, -d } };
        psf.setVertexCount(vertices.length);
        psf.setVertexCoordinates(vertices);
        psf.update();
        sgc.setGeometry(psf.getPointSet());
        Appearance ap = sgc.getAppearance();
        DefaultGeometryShader dgs = ShaderUtility.createDefaultGeometryShader(
                ap, true);
        dgs.setShowFaces(false);
        dgs.setShowLines(false);
        dgs.setShowPoints(true);
        DefaultPointShader dpts = (DefaultPointShader) dgs
                .createPointShader("default");
        dpts.setDiffuseColor(Color.BLUE);
        dpts.setPointRadius(0.5);
        sgc.setAppearance(ap);
        return sgc;
    }
    
    public SceneGraphComponent setUpTwoPoints(double[] location) {
        point1 = SceneGraphUtility.createFullSceneGraphComponent("SinglePoint");
        setUpSinglePoint(point1, location[0], location[1], location[2],
                Color.CYAN);
        point2 = SceneGraphUtility
                .createFullSceneGraphComponent("2ndSinglePoint");
        setUpSinglePoint(point2, location[0] + 10.0, location[1] + 10.0,
                location[2] + 10.0, Color.RED);
        point1.addChild(point2);
        pointLocation = SceneGraphUtility
                .createFullSceneGraphComponent("Point Location");
        MatrixBuilder.euclidean().translate(d, d, d).assignTo(pointLocation);
        pointLocation.addChild(point1);
        return pointLocation;
    }

    public void setUpSinglePoint(SceneGraphComponent sgc, double x, double y,
            double z, Color color) {

        double[][] vertices = new double[][] { { x, y, z } };
        PointSetFactory psf = new PointSetFactory();
        psf.setVertexCount(vertices.length);
        psf.setVertexCoordinates(vertices);
        psf.update();
        sgc.setGeometry(psf.getPointSet());

        Appearance ap = sgc.getAppearance();
        DefaultGeometryShader dgs = ShaderUtility.createDefaultGeometryShader(
                ap, true);
        dgs.setShowFaces(false);
        dgs.setShowLines(false);
        dgs.setShowPoints(true);
        DefaultPointShader dpts = (DefaultPointShader) dgs
                .createPointShader("default");
        dpts.setDiffuseColor(color);
        dpts.setPointRadius(1.0);
        sgc.setAppearance(ap);
    }

    public void setUpTool() {
        System.out.println("Entered setUpTool >>>>");
        DragEventTool t = new DragEventTool();
        t.addPointDragListener(new PointDragListener() {

            public void pointDragStart(PointDragEvent e) {
                System.out.println("Entered pointDragStart >>>>");
            }

            public void pointDragged(PointDragEvent e) {
                System.out.println("Entered pointDragged >>>>");
                
                PointSet pointSet = e.getPointSet();
                double[][] points = new double[pointSet.getNumPoints()][];
                pointSet.getVertexAttributes(Attribute.COORDINATES)
                        .toDoubleArrayArray(points);
                int index = e.getIndex();
                double[] oldLocation = points[index];
                System.out.println("Old Location: [" + oldLocation[0] + ", "
                 + oldLocation[1] + ", " + oldLocation[2] + "]");
                double[] location = e.getPosition();
                System.out.println("Location: [" + location[0] + ", " +
                 location[1] + ", " + location[2] + "");
                double[] translation = new double[] {
                        location[0] - oldLocation[0],
                        location[1] - oldLocation[1],
                        location[2] - oldLocation[2] };
                 System.out.println("Translation: [" + translation[0] + ", " +
                 translation[1] + ", " + translation[2] + "");
                MatrixBuilder
                        .euclidean()
                        .translate(translation[0], translation[1],
                                translation[2]).assignTo(point1);
            }

            public void pointDragEnd(PointDragEvent e) {
                System.out.println("Entered pointDragEnd >>>>");
            }
        });
        point1.addTool(t);
    }

    public void setUpCoordinateSystem(SceneGraphComponent component) {
        // create coordinate system
        double axisScale = 5.0;
        final CoordinateSystemFactory coords = new CoordinateSystemFactory(
                component, axisScale);
        // SET PROPERTIES:

        Font font = new Font("TimesRoman", Font.PLAIN, 40);
        coords.setAxisScale(axisScale);
        coords.setLabelScale(0.015);
        // coords.showBox(true);
        // coords.showBoxArrows(true);
        coords.showAxesArrows(true);
        coords.showLabels(true);
        // coords.setColor(Color.RED);
        // coords.setGridColor(Color.GRAY);
        coords.setLabelColor(Color.BLACK);
        coords.setLabelFont(font);
        coords.setColor(Color.BLUE);

        // display axes/box/grid
        coords.showAxes(true);
        // coords.showBox(true);
        coords.showGrid(true);

        // beautify box
        // coords.beautify(true);
    }
}
Example2

Code: Select all

import de.jreality.geometry.Primitives;
import de.jreality.math.Matrix;
import de.jreality.math.MatrixBuilder;
import de.jreality.plugin.JRViewer;
import de.jreality.scene.IndexedFaceSet;
import de.jreality.scene.SceneGraphComponent;
import de.jreality.scene.data.Attribute;
import de.jreality.tools.DragEventTool;
import de.jreality.tools.FaceDragEvent;
import de.jreality.tools.FaceDragListener;
import de.jreality.util.SceneGraphUtility;

public class DragSceneGraphTranslate1 {
	private SceneGraphComponent child2;
	private SceneGraphComponent child21;
	private SceneGraphComponent child1;
	private SceneGraphComponent world;

	public static void main(String[] args) {
		DragSceneGraphTranslate1 tool = new DragSceneGraphTranslate1();
	}

	public DragSceneGraphTranslate1() {
		world = setUpSceneGraph();
		setUpTool();
		JRViewer.display(world);
	}

	public SceneGraphComponent setUpSceneGraph() {
		SceneGraphComponent world = SceneGraphUtility
				.createFullSceneGraphComponent("world");
		child1 = SceneGraphUtility.createFullSceneGraphComponent("child1");
		child2 = SceneGraphUtility.createFullSceneGraphComponent("child2");
		child21 = SceneGraphUtility.createFullSceneGraphComponent("child21");
		world.addChild(child1);
		child1.addChild(child2);
		child2.addChild(child21);
		MatrixBuilder.euclidean().translate(-1.5, 0, 0).assignTo(world);

		child1.setGeometry(Primitives.coloredCube());
		child21.setGeometry(Primitives.coloredCube());
		final Matrix translate = new Matrix(MatrixBuilder.euclidean()
				.translate(3, 0, 0).getArray());
		translate.assignTo(child2);
		return world;
	}

	public void setUpTool() {
		System.out.println("Entered setUpTool >>>>");
		DragEventTool t = new DragEventTool();
		t.addFaceDragListener(new FaceDragListener() {

			private IndexedFaceSet faceSet;
			private double[][] points;

			public void faceDragStart(FaceDragEvent e) {
				faceSet = e.getIndexedFaceSet();
				points = new double[faceSet.getNumPoints()][];
				points = faceSet.getVertexAttributes(Attribute.COORDINATES)
						.toDoubleArrayArray(null);
			}

			public void faceDragged(FaceDragEvent e) {
				double[][] newPoints = (double[][]) points.clone();
				Matrix trafo = new Matrix();
				MatrixBuilder.euclidean().translate(e.getTranslation())
						.assignTo(child1);
			}

			public void faceDragEnd(FaceDragEvent e) {
			}
		});
		child1.addTool(t);
	}
}


Can you let me know how to solve the problems - object jumping and inability to drag the objects to cursor.

Thanks,
Karuna

User avatar
gunn
Posts: 323
Joined: Thu 14. Dec 2006, 09:56
Location: TU Berlin
Contact:

Re: Dragging a Scene Graph Segment

Post by gunn » Sun 19. Sep 2010, 10:48

The problem seems to be that the DragEventTool and its listeners simply don't work well when you edit transformations. The examples I'm familiar with in the tutorial directory use the information from the DragEventTool to edit the coordinates of the geometry, rather than editing the transformations in the scene graph. When you edit the transformations, the DragEventTool gets confused (at least that's my impression) since it is focused on the object coordinates of the underlying geometry and these aren't really changing.

Why not just use the standard DraggingTool provided by jReality? I've changed both your examples from your last post to do so and the behavior seems correct. In the second (with the two cubes) I've also added a second DraggingTool to child21, just to show that it can be separately translated; but of course translating child1 will move both it and all its children, which is the correct behavior, right?

In the first example, change the constructor method to:

Code: Select all

    public DragSceneGraphTool() {
        sceneGraph = setUpSceneGraph(new double[] { 0.0, 0.0, 0.0 });
        setUpCoordinateSystem(sceneGraph);
//        setUpTool();
        point1.addTool(new DraggingTool());
        JRViewer.display(sceneGraph);
    }
    
In the second, skip the call to setUpTool() and change setupSceneGraph() to:

Code: Select all

   public SceneGraphComponent setUpSceneGraph() {
      SceneGraphComponent world = SceneGraphUtility
            .createFullSceneGraphComponent("world");
      child1 = SceneGraphUtility.createFullSceneGraphComponent("child1");
      child2 = SceneGraphUtility.createFullSceneGraphComponent("child2");
      child21 = SceneGraphUtility.createFullSceneGraphComponent("child21");
      world.addChild(child1);
      child1.addChild(child2);
      child2.addChild(child21);
      MatrixBuilder.euclidean().translate(-1.5, 0, 0).assignTo(world);

      child1.setGeometry(Primitives.coloredCube());
      child21.setGeometry(Primitives.coloredCube());
      child1.addTool(new DraggingTool());
      child21.addTool(new DraggingTool());
      final Matrix translate = new Matrix(MatrixBuilder.euclidean()
            .translate(3, 0, 0).getArray());
      translate.assignTo(child2);
      return world;
   }
You have a good point (made in another post recently) that the documentation on the tool system in the tutorial could be improved. I've had that on my list for a long time, but haven't yet found time to write up an introductory document. In the meantime, just keep posting your individual questions and perhaps in the process things will be come clear.
jReality core developer

Post Reply