Hi

I see my argumentation was a bit short-sighted.
The samplecode is in the attachment, hope this helps.

> You might be able to use the Background node as a workaround
Maybe for this case i used in my sample (Stars in the Background), but there
are other things in my application, which can't be done this way, so leading
me to the same problems.
I already thought about using locales too, and i surely will have to use
them, when i start to model bigger parts of the cosmos.

- emanuel

> > Date:         Fri, 15 Nov 2002 14:21:18 +0100
> > From: Emanuel Brzostowski <[EMAIL PROTECTED]>
> >
> > > Moving both viewplatform and object by similar transform will degrade
> > > quality. You should try to keep all objects as close to center as
> > > possible - within 100000 units let say.
> >
> > Exatly this is the point! The only transform i apply is a transform to
> the
> > viewplatform:
> >    viewTransform.mul(moveTrans);
> >
> > If we talk about precision, this is the only point, where precision may
> play
> > a role. The multiplication is only numeric, so errors will surely occur
> and
> > accumulate over time.  BUT after this, i do no more transformations, i
> just
> > take the translational part out of the viewtransform (-matrix) and
> rebuild my
> > objecttransform:
> >   viewTransform.get(viewTranslation);
> >   StarsTransform.setTranslation(viewTranslation);
> >   StarsTransformGroup.setTransform(StarsTransform);
> >   viewTransformGroup.setTransform(viewTransform);
> >
> > So in turn i should have two transforms with should be equal (at least
> in the
> > translational parts).  (In fact i tested it, objecttransform and
> > viewtransform ARE equal the whole time in my testcase.)  So even if
> java3d
> > would use integers internally, after all the transforms are the same ;)
>
> Because this is a scenegraph, the view transform has to be inverted and
> multiplied with the object transform to get the transform from object
> coordinates to view platform coordinates (and from there to eye
> coordinates and
> projection/clipping coordinates).  But since the view and object
> transforms are
> just translations, Java 3D should recognize that all it needs to do is
> subtract
> the translation components.
>
> Bottom line, we can't tell from the code snippets and description you
> provided
> whether this a user error, a problem with scene graph update
> synchronization, a
> transform problem, or some inherent precision limitation.  Send us a small
> but
> complete test application that reproduces the problem and we'll be able to
> investigate further.
>
> You might be able to use the Background node as a workaround -- it was
> designed
> to eliminate translation effects, rendering the Background geometry "at
> infinity".  And as you noted, the problem is only with large distances, so
> you
> might consider keeping your objects closer to the origin, or investigate
> the
> use of multiple Locales with different origins in high-resolution
> coordinates.
>
> -- Mark Hood
>
>
===========================================================================
> 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".
>

--
+++ GMX - Mail, Messaging & more  http://www.gmx.net +++
NEU: Mit GMX ins Internet. Rund um die Uhr f�r 1 ct/ Min. surfen!
package jittertest;

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
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 java.util.Enumeration;

public class testJitter extends Applet
{
  TextField posTxt = new TextField(20);

  Transform3D viewTransform;
  TransformGroup viewTransformGroup;
  Transform3D StarsTransform;
  TransformGroup StarsTransformGroup;


  public testJitter()
  {
    setLayout(new BorderLayout());

    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice gs = ge.getDefaultScreenDevice();
    GraphicsConfigTemplate3D devconfig = new GraphicsConfigTemplate3D();
    GraphicsConfiguration config = gs.getBestConfiguration(devconfig);

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

    Panel infoPanel = new Panel();

    infoPanel.setLayout(new FlowLayout());
    Label posLabel = new Label("viewer pos:");
    infoPanel.add(posLabel);
    infoPanel.add(posTxt);
    add("South", infoPanel);

    VirtualUniverse myUniverse = new VirtualUniverse();
    Locale myLocale = new Locale(myUniverse);
    myLocale.addBranchGraph(buildViewBranch(c));
  }


  public BranchGroup buildViewBranch(Canvas3D c)
  {
    BranchGroup viewBranch = new BranchGroup();
    viewTransform = new Transform3D();
    viewTransformGroup = new TransformGroup(viewTransform);
    ViewPlatform myViewPlatform = new ViewPlatform();

    // adding a colorcube infront of the viewer
    StarsTransform = new Transform3D();
    StarsTransformGroup = new TransformGroup(StarsTransform);
    StarsTransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    Transform3D sunTransform = new Transform3D();
    sunTransform.set(new Vector3d(0.0, 0.0, -10.0));
    TransformGroup SunTG = new TransformGroup(sunTransform);
    SunTG.addChild(new ColorCube());
    StarsTransformGroup.addChild(SunTG);


    viewTransformGroup.addChild(myViewPlatform);


    timedBehavior behav = new timedBehavior();
    behav.setSchedulingBounds(new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 1000.0));
    viewTransformGroup.addChild(behav);

    viewTransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    viewTransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

    viewBranch.addChild(viewTransformGroup);
    viewBranch.addChild(StarsTransformGroup);

    View myView = new View();

    PhysicalBody myBody = new PhysicalBody();
    PhysicalEnvironment myEnvironment = new PhysicalEnvironment();
    myView.setPhysicalBody(myBody);
    myView.setPhysicalEnvironment(myEnvironment);
    myView.addCanvas3D(c);
    myView.attachViewPlatform(myViewPlatform);

    return(viewBranch);
  }


  public static void main(String[] args)
  {
    System.out.println("By pressing any key, the view is translated in neagtive z by 
1000 units continuosly.");
    System.out.println("After a short time, the cube (moving together with the viewer) 
begins to jitter.");
    System.out.println("Jitter gets worse the farther the view departs form the 
origin. ");
    new MainFrame(new testJitter(), 512, 512);
  }


  /////////////////////////////////////////////////////////////////
  // Inner Classes
  /////////////////////////////////////////////////////////////////
  public class timedBehavior extends Behavior
  {
    public boolean running = false;
    WakeupCriterion[] wakeConditions;
    WakeupOr oredConditions;
    AWTEvent ae[];
    Transform3D moveTrans;
    Vector3d viewTranslation;


    public void initialize()
    {
      moveTrans = new Transform3D();
      moveTrans.set(new Vector3d(0.0, 0.0, -1000.0));
      viewTranslation = new Vector3d();

      wakeConditions = new WakeupCriterion[3];
      wakeConditions[0] = new WakeupOnAWTEvent(KeyEvent.KEY_PRESSED);
      wakeConditions[1] = new WakeupOnAWTEvent(KeyEvent.KEY_RELEASED);
      wakeConditions[2] = new WakeupOnElapsedTime(10);
      oredConditions = new WakeupOr(wakeConditions);
      wakeupOn(oredConditions);
    }


    public void processStimulus(Enumeration criteria)
    {
      WakeupCriterion theCriteria;
      if(criteria.hasMoreElements())theCriteria = 
(WakeupCriterion)criteria.nextElement();
      else
      {
        wakeupOn(oredConditions);
        return;
      }

      if(theCriteria instanceof WakeupOnAWTEvent)
      {
       ae = ((WakeupOnAWTEvent)theCriteria).getAWTEvent();
       if(ae[0].getID()==KeyEvent.KEY_PRESSED) running = true;
       else if(ae[0].getID()==KeyEvent.KEY_RELEASED) running = false;
      }
      else
      {
        if(running&&(theCriteria instanceof WakeupOnElapsedTime))
        {
          viewTransform.mul(moveTrans);
          viewTransform.get(viewTranslation);
          StarsTransform.setTranslation(viewTranslation);
          StarsTransformGroup.setTransform(StarsTransform);
          viewTransformGroup.setTransform(viewTransform);
          posTxt.setText(viewTranslation.toString());
        }
      }

      wakeupOn(oredConditions);
    }
  }
  /////////////////////////////////////////////////////////////////
}

Reply via email to