• Post Reply Bookmark Topic Watch Topic
  • New Topic

Why there is no 3D image in my Applet....  RSS feed

 
Neeraj Kumar Mishra
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
import java.awt.*;
import java.applet.*;
import java.util.*;
import javax.vecmath.*;
import javax.media.j3d.*;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.universe.*;
import com.sun.j3d.loaders.vrml97.VrmlLoader;
import com.sun.j3d.loaders.Scene;
public class VView extends Applet
{
SimpleUniverse universe;
Scene scene = null;
public VView(String avatar)
{
setLayout(new BorderLayout());
Canvas3D canvas = new Canvas3D(null);
add("Center",canvas);
universe = new SimpleUniverse(canvas);
ViewingPlatform viewingPlatform = universe.getViewingPlatform();
View view = (universe.getViewer()).getView();
VrmlLoader loader = new VrmlLoader();
try
{
scene = loader.load(avatar);
}
catch(Exception e)
{
System.out.println("exception in loading the file");
System.exit(1);
}
BranchGroup sceneGroup = scene.getSceneGroup();
sceneGroup.setCapability(BranchGroup.ALLOW_DETACH);
sceneGroup.setCapability(BranchGroup.ALLOW_BOUNDS_READ);
universe.addBranchGraph(sceneGroup);
BoundingSphere sceneBounds = (BoundingSphere)sceneGroup.getBounds();
double radius = sceneBounds.getRadius();
Point3d center = new Point3d();
sceneBounds.getCenter(center);
Vector3d temp = new Vector3d(center);
temp.z=1.4*radius/Math.tan(view.getFieldOfView()/2.0);
Transform3D viewTransform = new Transform3D();
viewTransform.set(temp);
TransformGroup.setTransform(viewTransform);
}
public static void main(String p[])
{
new MainFrame(new VView(p[0]),400,400);
}
}
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!