Skip to main content

OrientedShape3D not working as documented… bug?

No replies
rhavin
Offline
Joined: 2011-02-09
Points: 0

I set up universe like this:

private VirtualUniverse   universe  = null;
private Locale            locale    = null;

private BranchGroup       bgViewing = null;
private BranchGroup       bgWorld = null;
private TransformGroup    tgViewing = null;


// -----------------------------------------------------------------------------------
    private void _initUniverse()
    {
        // set up the universe and give it a Locale
        universe  = new VirtualUniverse();
        bgViewing = new BranchGroup();
        bgWorld   = new BranchGroup();
      
        bgViewing.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
        bgViewing.setCapability(BranchGroup.ALLOW_DETACH);
        bgWorld.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
        bgWorld.setCapability(BranchGroup.ALLOW_DETACH);
      
        tgViewing   = new TransformGroup();
        tgViewing.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
        tgViewing.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
        tgViewing.setCapability(TransformGroup.ALLOW_CHILDREN_EXTEND);
        Transform3D stdTrans = new Transform3D();
        stdTrans.set(new Vector3f(0.0f, 0.0f, 0.0f));
        tgViewing.setTransform(stdTrans);
        bgViewing.addChild(tgViewing);

        locale = new Locale(universe);
        locale.addBranchGraph(bgViewing);
        locale.addBranchGraph(bgWorld);

    };

Canvasses come into play like that:

// -----------------------------------------------------------------------------------
public void initCanvas(Canvas3D canvas)
{
    ViewPlatform        platform = new ViewPlatform();
    View                view     = new View();
    PhysicalBody        body     = new PhysicalBody();
    PhysicalEnvironment env      = new PhysicalEnvironment();


   
// the following line doesnt seem to do anything, if i set value
// to 100.0, there is no difference at all!
    body.setNominalEyeOffsetFromNominalScreen(1.0d);

    env.setCoexistenceCenterInPworldPolicy(View.NOMINAL_SCREEN);
    view.setPhysicalBody(body);
    view.setPhysicalEnvironment(env);
    view.addCanvas3D(canvas);
    view.attachViewPlatform(platform);
    platform.setViewAttachPolicy(View.NOMINAL_SCREEN);
      
    bgViewing.detach();
      
    TransformGroup tgPlatform = new TransformGroup();
    tgPlatform.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    tgPlatform.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    TransformGroup tgZoom = new TransformGroup();
    tgZoom.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    tgZoom.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);

    Transform3D trNew = new Transform3D();
    trNew.set(new Vector3f(0.0f, 0.0f, -1.5f));
    tgZoom.setTransform(trNew);
    trNew.set(new Vector3f(_translateDungeonToUniverse(0.0f, 0.0f, 0.0f)));

    tgPlatform.setTransform(trNew);
    tgZoom.addChild(platform);
    tgPlatform.addChild(tgZoom);
    tgViewing.addChild(tgPlatform);
    locale.addBranchGraph(bgViewing);
};

OrientedShape3D is added just so:

// -----------------------------------------------------------------------------------
public static BranchGroup texturedBoard(float fSize, Point3f pos, TransformGroup tg)
{
OrientedShape3D os = new OrientedShape3D();

Texture2D tex = // getting texture here //

// coordinates of texture
TexCoord2f[] q = {new TexCoord2f(), new TexCoord2f(), new TexCoord2f(),
new TexCoord2f()};

q[0].set(1.0f, 0.0f);
q[1].set(1.0f, 1.0f);
q[2].set(0.0f, 1.0f);
q[3].set(0.0f, 0.0f);

os.setAlignmentMode(OrientedShape3D.ROTATE_ABOUT_POINT);
os.setRotationPoint(pos.x,pos.y,pos.z);

Shape3D shape = null;

// resulting shape corners
Point3f[] p = {new Point3f(), new Point3f(), new Point3f(), new Point3f()};
p[0].set(pos.x - fSize, pos.y - fSize, pos.z);
p[1].set(pos.x + fSize, pos.y - fSize, pos.z);
p[2].set(pos.x + fSize, pos.y + fSize, pos.z);
p[3].set(pos.x - fSize, pos.y + fSize, pos.z);
shape = Grafix3D.texturedPlane(p, q, tex, false);
os.addGeometry(shape.getGeometry());

os.setAppearance(shape.getAppearance());
BranchGroup bg = new BranchGroup();
if (tg == null)
bg.addChild(os);
else
{
tg.addChild(os);
bg.addChild(tg);
}
return bg;
};

documentation OrientedShape3D claims:

&quot;It defines an alignment mode and a rotation point or axis. This will cause the local +<i>z</i> axis of the object to point at the viewer's eye
position.&quot;

That is not true. they orient to the origin of the scene (0,0,0) and *not* to the view. Has anyone used OrientedShapes with views not positioned at (0,0,0) ?