001/*
002 * This file is part of McIDAS-V
003 *
004 * Copyright 2007-2024
005 * Space Science and Engineering Center (SSEC)
006 * University of Wisconsin - Madison
007 * 1225 W. Dayton Street, Madison, WI 53706, USA
008 * https://www.ssec.wisc.edu/mcidas/
009 * 
010 * All Rights Reserved
011 * 
012 * McIDAS-V is built on Unidata's IDV and SSEC's VisAD libraries, and
013 * some McIDAS-V source code is based on IDV and VisAD source code.  
014 * 
015 * McIDAS-V is free software; you can redistribute it and/or modify
016 * it under the terms of the GNU Lesser Public License as published by
017 * the Free Software Foundation; either version 3 of the License, or
018 * (at your option) any later version.
019 * 
020 * McIDAS-V is distributed in the hope that it will be useful,
021 * but WITHOUT ANY WARRANTY; without even the implied warranty of
022 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
023 * GNU Lesser Public License for more details.
024 * 
025 * You should have received a copy of the GNU Lesser Public License
026 * along with this program.  If not, see https://www.gnu.org/licenses/.
027 */
028
029package edu.wisc.ssec.mcidasv.util;
030
031import java.awt.BorderLayout;
032import java.awt.Dimension;
033import java.awt.GraphicsConfiguration;
034
035import javax.swing.JFrame;
036import javax.swing.SwingUtilities;
037import javax.swing.WindowConstants;
038import javax.vecmath.Point3d;
039
040import com.sun.j3d.utils.geometry.ColorCube;
041import com.sun.j3d.utils.universe.SimpleUniverse;
042
043import javax.media.j3d.Alpha;
044import javax.media.j3d.BoundingSphere;
045import javax.media.j3d.BranchGroup;
046import javax.media.j3d.Canvas3D;
047import javax.media.j3d.RotationInterpolator;
048import javax.media.j3d.Transform3D;
049import javax.media.j3d.TransformGroup;
050
051/**
052 * Display a simple rotating cube.
053 * 
054 * <p>The intent here is verify that Java3D can put something on the screen,
055 * so no McIDAS-V stuff should be happening in here.</p>
056 */
057public class J3dTest {
058    J3dTest() {
059        GraphicsConfiguration config =
060            SimpleUniverse.getPreferredConfiguration();
061        Canvas3D canvas = new Canvas3D(config);
062        
063        SimpleUniverse univ = new SimpleUniverse(canvas);
064        univ.getViewingPlatform().setNominalViewingTransform();
065        univ.getViewer().getView().setMinimumFrameCycleTime(5);
066        
067        BranchGroup objRoot = new BranchGroup();
068        TransformGroup transformGroup = new TransformGroup();
069        transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
070        objRoot.addChild(transformGroup);
071        transformGroup.addChild(new ColorCube(0.4));
072        RotationInterpolator rotator =
073            new RotationInterpolator(
074                new Alpha(-1, 4000),
075                transformGroup,
076                new Transform3D(),
077                0.0f,
078                (float)Math.PI * 2.0f);
079        rotator.setSchedulingBounds(new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0));
080        objRoot.addChild(rotator);
081        objRoot.compile();
082        
083        univ.addBranchGraph(objRoot);
084        
085        JFrame jFrame = new JFrame();
086        jFrame.setLayout(new BorderLayout());
087        jFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
088        jFrame.setTitle("Java3D Test");
089        jFrame.getContentPane().add(canvas, BorderLayout.CENTER);
090        jFrame.setPreferredSize(new Dimension(250, 250));
091        jFrame.pack();
092        jFrame.setVisible(true);
093    }
094    
095    public static void main(String... args) {
096        SwingUtilities.invokeLater(J3dTest::new);
097    }
098}