Woops, forgot to put this test file with my last message.  This program is
a simple example of how you can use the OverlayGroup.  (simple
modification of HelloUniverse).

B

On Mon, 11 Jun 2001, Blaine Alex Bell wrote:

> Here is the Overlay Library that I have implemented. I have tried
> minimizing this implementation so it can be as flexible as possible.
> Two classes exist, both in the package edu.columbia.cs.cgui.j3d:
> FixedCanvas3D and OverlayGroup.
> FixedCanvas3D is interchangeable with Canvas3D, and NEEDS to be used if
> you want to use OverlayGroup.  OverlayGroup allows you to place overlayed
> objects by having a Node that is in pixel coordinates (origin is in the
> bottom left hand corner of the Canvas), and gives you the
> flexibility to create a scenegraph below this group node to place the
> overlay objects.
>
> Some functionality that you might find useful:
>
> * Supports all View Model Parameters that are not part of head tracking.
> As noted in the documentation, you cannot currently do Overlays in a head
> tracked environment (Java3D limitation, hoping to be fixed in the near
> future).
>
> * Supports changing Z values for Overlays.  This gets very interesting,
> especially in stereo since 2D overlays cannot do this. You do not need to
> use this functionality, you can also place it directly in front of the
> front clipping plane.
>
> * Works around the 'lag' problems introduced in the WakeUpOnElapsedFrame
> behavior because Canvas3D caches values from previous frame. Also, I
> provide new functions in FixedCanvas3D that should be in Canvas3D, such as
> transformations relative to the ViewPlatform.
>
> Please send be comments/suggestions.  I know that this is a hot topic on
> this newsgroup, and I hope this helps everyone.
> Please let me know what you think!
> Soon coming: A View Model Demo Program to explain this crazy View Model!
>
> Blaine
>
> On Mon, 11 Jun 2001, Artur Biesiadowski wrote:
>
> > "Yazel, David J." wrote:
> >
> > > 17. No plans to implement resize because of the issus involved in rebuilding
> > > the sub-textures.  Would be easier to just make a new one.  We might support
> > > use of model-clips to clip in from a maximum size.
> >
> > I was trying to do overlay system some time ago and failed. Anyway, I've
> > come up with following interface - it might be an overkill if you don't
> > plan resize, but maybe you will like to reuse some idea.
> >
> > Overlay have specified xoffset, yoffset, width and height at creation
> > time. These are double values, with following meanings:
> >
> > xoffset -
> >         if positive > 1, means distance of left edge of overlay from left side
> > of window in pixels
> >         if negative < -1, means distance of right edge of overlay from right
> > side of window in pixels
> >         if positive < 1, means how much free space should be used for the left
> > side (fraction)
> >         if negative > -1, means how much free space should be used for the
> > right side (same as 1+negative)
> > yoffset - the same, just top and bottom
> >
> > width -
> >         if positive > 1 means width of overlay in pixels
> >         if negative < -1 means how much free width should be left on screen
> > after substracting overlay width (in pixels)
> >         if positive < 1 means width of overlay as fraction of entire window
> > width
> >         if negative > -1 means fraction of width which should be unoccupied by
> > overlay (same as 1+negative)
> > height - same as width, just for height
> >
> > This would allow for very dynamic system, but unfortunately size of
> > texture would have to change with window resizes. It might be too much
> > for your needs, then please implement at least negative offsets - to
> > allow placing overlay relative to right and bottom edges (not only top
> > and left). Fractional offsets would be also nice (allows for example
> > centering with 0.5, 0.5 offsets).
> >
> > Artur
> >
> > ===========================================================================
> > To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> > of the message "signoff JAVA3D-INTEREST".  For general help, send email to
> > [EMAIL PROTECTED] and include in the body of the message "help".
> >
>
/*
 *      @(#)HelloOverlayGroup.java 
 *
 * Date: 6/11/2001
 *
 * Copyright 2001 Columbia University, All Rights Reserved.
 *
 * This software is the proprietary information of Columbia University.
 * Please contact Blaine Bell ([EMAIL PROTECTED]) for any bugs or enhancements.
 *
 * This program provides a simple example that uses the classes OverlayGroup
 * to place some text relative to the screen. More specifically, it places a white 
text
 * Text2D node with the string "Testing!!".  Note: The implementation of OverlayGroup 
does not
 * limit you in any way of placing objects that can be moved around on the overlay 
plane 
 * using behaviors.
 * In this simple program, I have called updatePlacement on the OverlayGroup only 
once, since I
 * am not moving it around in Z, I do not need to call it again.  If you move the 
Canvas3D around,
 * the FixedCanvas3D catches the event and refreshes all of the variables to provide 
the correct
 * overlay.
 */

import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.event.*;
import java.awt.GraphicsConfiguration;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.geometry.ColorCube;
import com.sun.j3d.utils.universe.*;
import javax.media.j3d.*;
import javax.vecmath.*;
import edu.columbia.cs.cgui.j3d.*;
import com.sun.j3d.utils.geometry.*;
import java.awt.*;

public class HelloOverlayGroup extends Applet {

    private SimpleUniverse u = null;
  BoundingSphere bounds =
    new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0);
    
    public BranchGroup createSceneGraph() {
        // Create the root of the branch graph
        BranchGroup objRoot = new BranchGroup();
        objRoot.setCapability(Group.ALLOW_CHILDREN_EXTEND);

        // Create the TransformGroup node and initialize it to the
        // identity. Enable the TRANSFORM_WRITE capability so that
        // our behavior code can modify it at run time. Add it to
        // the root of the subgraph.
        TransformGroup objTrans = new TransformGroup();
        objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
        objRoot.addChild(objTrans);

        // Create a simple Shape3D node; add it to the scene graph.
        objTrans.addChild(new ColorCube(0.4));

        // Create a new Behavior object that will perform the
        // desired operation on the specified transform and add
        // it into the scene graph.
        Transform3D yAxis = new Transform3D();
        Alpha rotationAlpha = new Alpha(-1, 4000);

        RotationInterpolator rotator =
            new RotationInterpolator(rotationAlpha, objTrans, yAxis,
                                     0.0f, (float) Math.PI*2.0f);
        rotator.setSchedulingBounds(bounds);
        objRoot.addChild(rotator);

        // Have Java 3D perform optimizations on this scene graph.
        objRoot.compile();

        return objRoot;
    }

    public HelloOverlayGroup() {
    }

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

        FixedCanvas3D c = new FixedCanvas3D(config);
        add("Center", c);

        // Create a simple scene and attach it to the virtual universe
        BranchGroup scene = createSceneGraph();
        u = new SimpleUniverse(c);

        // This will move the ViewPlatform back a bit so the
        // objects in the scene can be viewed.
        u.getViewingPlatform().setNominalViewingTransform();

        final OverlayGroup og = new OverlayGroup();
        TransformGroup overlay = new TransformGroup();
        Transform3D overlaytrans = new Transform3D();
        overlaytrans.set(new Vector3d(50.,50.,0.)); // in pixel coordinates
        overlaytrans.setScale(256); // account for the scaling in Text2D
        overlay.setTransform(overlaytrans);
        Text2D text2d = new Text2D("Testing!!",new 
Color3f(1.f,1.f,1.f),"",40,Font.PLAIN);
        overlay.addChild(text2d);
        
og.setupOverlayGroup(c,u.getViewingPlatform().getViewPlatformTransform(),overlay);
        og.setOnNearClippingPlane(true);
        BranchGroup bg = new BranchGroup();
        Behavior beh;
        bg.addChild(beh=new Behavior(){
            WakeupOnElapsedFrames w1 = new WakeupOnElapsedFrames(0);
            boolean first=true;
            public void initialize(){
              wakeupOn(w1);
            }
            public void processStimulus(java.util.Enumeration criteria){
              if (first){
                og.updatePlacement();
              } else {
                first=false;
              }
              wakeupOn(w1);
            }
          });
        beh.setSchedulingBounds(bounds);
        scene.addChild(bg);
        u.addBranchGraph(scene);
    }

    public void destroy() {
        u.removeAllLocales();
    }

    //
    // The following allows HelloUniverse to be run as an application
    // as well as an applet
    //
    public static void main(String[] args) {
        new MainFrame(new HelloOverlayGroup(), 256, 256);
    }
}

Reply via email to