Re: Objects fall outside simpleuniverse
Posted by philjord on Jul 23, 2018; 12:08pm
URL: https://forum.jogamp.org/Objects-fall-outside-simpleuniverse-tp4039062p4039067.html
I had to make up a few parts, but replacing your sphere with a simple color cube from teh utils I can see it on screen farily readily. The orbit behavior allows me to rotat it around and see it even better. For reference I've put 4 small cube on at the origin and 1 meter in each positive axis.
This test program looks good, so I suspect the geometry or appearance of your sphere6 which you don't include might not be valid or visible, can you include a bit more code?
Thanks
package _testcase;
import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.GraphicsConfiguration;
import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.media.j3d.BoundingSphere;
import javax.media.j3d.BranchGroup;
import javax.media.j3d.Canvas3D;
import javax.media.j3d.Group;
import javax.media.j3d.Transform3D;
import javax.media.j3d.TransformGroup;
import javax.swing.Timer;
import javax.vecmath.Quat4f;
import javax.vecmath.Vector3f;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.behaviors.vp.OrbitBehavior;
import com.sun.j3d.utils.geometry.ColorCube;
import com.sun.j3d.utils.universe.SimpleUniverse;
public class TestForSphere extends Applet implements ActionListener, KeyListener
{
TransformGroup objTransYour6Sph;
Timer timer;
ColorCube sphere6 = new ColorCube(0.1f);
public BranchGroup createSceneGraph()
{
// Create the root of the branch graph
BranchGroup objRoot = new BranchGroup();
objRoot.setCapability(Group.ALLOW_CHILDREN_EXTEND);
//Sphere 6
TransformGroup sphere6TransGroup = translate(sphere6, new Vector3f(0.6f, 0.93f, 0.0f));
objTransYour6Sph = new TransformGroup();
objTransYour6Sph.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
objRoot.addChild(objTransYour6Sph);
objTransYour6Sph.addChild(sphere6TransGroup);
objRoot.addChild(translate(new ColorCube(0.02), new Vector3f(0.0f, 0.0f, 0.0f)));
objRoot.addChild(translate(new ColorCube(0.02), new Vector3f(0.5f, 0.0f, 0.0f)));
objRoot.addChild(translate(new ColorCube(0.02), new Vector3f(0.0f, 0.5f, 0.0f)));
objRoot.addChild(translate(new ColorCube(0.02), new Vector3f(0.0f, 0.0f, 0.5f)));
return objRoot;
}
private TransformGroup translate(ColorCube sphere62, Vector3f vector3f)
{
TransformGroup tg = new TransformGroup();
tg.setTransform(new Transform3D(new Quat4f(0, 0, 0, 1), vector3f, 1));
tg.addChild(sphere62);
return tg;
}
public TestForSphere()
{
setLayout(new BorderLayout());
GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
Canvas3D c = new Canvas3D(config);
add("Center", c);
c.addKeyListener(this);
timer = new Timer(100, this);
//timer.start();
Panel p = new Panel();
// p.add(go);
add("North", p);
// go.addActionListener(this);
// go.addKeyListener(this);
// Create a simple scene and attach it to the virtual universe
BranchGroup scene = createSceneGraph();
SimpleUniverse u = new SimpleUniverse(c);
u.getViewingPlatform().setNominalViewingTransform();
u.addBranchGraph(scene);
//u.getViewer().getView().setFieldOfView(Math.toRadians(90.0));
OrbitBehavior orbit = new OrbitBehavior(c, OrbitBehavior.REVERSE_ROTATE);
orbit.setSchedulingBounds(new BoundingSphere());
u.getViewingPlatform().setViewPlatformBehavior(orbit);
}
public static void main(String[] args)
{
System.out.println("Program Started");
System.setProperty("sun.awt.noerasebackground", "true");
TestForSphere bb = new TestForSphere();
bb.addKeyListener(bb);
MainFrame mf = new MainFrame(bb, 1056, 1056);
}
@Override
public void actionPerformed(ActionEvent e)
{
}
@Override
public void keyTyped(KeyEvent e)
{
}
@Override
public void keyPressed(KeyEvent e)
{
}
@Override
public void keyReleased(KeyEvent e)
{
}
}