281 lines
No EOL
9.8 KiB
Java
281 lines
No EOL
9.8 KiB
Java
package roboter_demo;
|
||
|
||
import com.sun.j3d.utils.behaviors.vp.OrbitBehavior;
|
||
import com.sun.j3d.utils.behaviors.vp.ViewPlatformBehavior;
|
||
import com.sun.j3d.utils.geometry.ColorCube;
|
||
import com.sun.j3d.utils.universe.SimpleUniverse;
|
||
import com.sun.j3d.utils.universe.ViewingPlatform;
|
||
import de.spacecontrol.sc.dllwrapper.ScDllWrapper;
|
||
import de.spacecontrol.sc.dllwrapper.ScEx;
|
||
import de.spacecontrol.sc.dllwrapper.ScStdData;
|
||
import java.awt.BorderLayout;
|
||
import java.awt.Component;
|
||
import java.awt.Dimension;
|
||
import java.awt.EventQueue;
|
||
import java.awt.GraphicsConfiguration;
|
||
import java.awt.Image;
|
||
import java.awt.event.FocusAdapter;
|
||
import java.awt.event.FocusEvent;
|
||
import java.awt.event.KeyAdapter;
|
||
import java.awt.event.KeyEvent;
|
||
import java.lang.management.ManagementFactory;
|
||
import java.util.ArrayList;
|
||
import javax.media.j3d.AmbientLight;
|
||
import javax.media.j3d.BoundingSphere;
|
||
import javax.media.j3d.Bounds;
|
||
import javax.media.j3d.BranchGroup;
|
||
import javax.media.j3d.Canvas3D;
|
||
import javax.media.j3d.DirectionalLight;
|
||
import javax.media.j3d.Node;
|
||
import javax.media.j3d.Transform3D;
|
||
import javax.media.j3d.TransformGroup;
|
||
import javax.swing.JFrame;
|
||
import javax.swing.JOptionPane;
|
||
import javax.swing.JPanel;
|
||
import javax.swing.UIManager;
|
||
import javax.swing.UnsupportedLookAndFeelException;
|
||
import javax.vecmath.Color3f;
|
||
import javax.vecmath.Point3d;
|
||
import javax.vecmath.Vector3d;
|
||
import javax.vecmath.Vector3f;
|
||
|
||
public class RoboterApp extends JFrame {
|
||
private final int mBoundsRange = 1000;
|
||
|
||
private int mSceneNo;
|
||
|
||
private double mHandSpan;
|
||
|
||
private double mHandAngle;
|
||
|
||
private ReadingThread mReadingThread = new ReadingThread(this);
|
||
|
||
private int mDevIdx;
|
||
|
||
private TransformGroup mCubeTfGrp = new TransformGroup();
|
||
|
||
private TransformGroup mThumbTfGrp = new TransformGroup();
|
||
|
||
private TransformGroup mFingersTfGrp = new TransformGroup();
|
||
|
||
private TransformGroup mHandTfGrp = new TransformGroup();
|
||
|
||
private TransformGroup mForeArmTfGrp = new TransformGroup();
|
||
|
||
private TransformGroup mBaseTfGrp = new TransformGroup();
|
||
|
||
private Base mBase = new Base(this.mBaseTfGrp);
|
||
|
||
private ViewingPlatform mVp;
|
||
|
||
private JPanel mGraphicPanel;
|
||
|
||
public int getDevIdx() {
|
||
return this.mDevIdx;
|
||
}
|
||
|
||
public RoboterApp() {
|
||
GraphicsConfiguration graphicsConfiguration = SimpleUniverse.getPreferredConfiguration();
|
||
Canvas3D canvas3D = new Canvas3D(graphicsConfiguration);
|
||
SimpleUniverse simpleUniverse = new SimpleUniverse(canvas3D);
|
||
BranchGroup branchGroup = null;
|
||
OrbitBehavior orbitBehavior = new OrbitBehavior(canvas3D);
|
||
ArrayList<Image> arrayList = new ArrayList();
|
||
String str1 = System.getProperty("os.name");
|
||
boolean bool = str1.contains("OS X");
|
||
this.mVp = simpleUniverse.getViewingPlatform();
|
||
Image image1 = getToolkit().getImage(getClass().getResource("/pics/roboter_16.png"));
|
||
Image image2 = getToolkit().getImage(getClass().getResource("/pics/roboter_32.png"));
|
||
Image image3 = getToolkit().getImage(getClass().getResource("/pics/roboter_64.png"));
|
||
arrayList.add(image1);
|
||
arrayList.add(image2);
|
||
arrayList.add(image3);
|
||
setIconImages(arrayList);
|
||
try {
|
||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||
} catch (UnsupportedLookAndFeelException unsupportedLookAndFeelException) {
|
||
|
||
} catch (IllegalAccessException illegalAccessException) {
|
||
|
||
} catch (InstantiationException instantiationException) {
|
||
|
||
} catch (ClassNotFoundException classNotFoundException) {}
|
||
initComponents();
|
||
String str2 = bool ? getClass().getSimpleName() : getTitle();
|
||
this.mGraphicPanel.add("Center", (Component)canvas3D);
|
||
simpleUniverse.getViewer().getView().setBackClipDistance(1000.0D);
|
||
this.mSceneNo = 1;
|
||
switch (this.mSceneNo) {
|
||
case 0:
|
||
branchGroup = createRoboterSceneGraph();
|
||
this.mVp.setNominalViewingTransform();
|
||
break;
|
||
case 1:
|
||
branchGroup = createRoboterSceneGraph();
|
||
setViewPos(this.mVp);
|
||
orbitBehavior.setSchedulingBounds((Bounds)new BoundingSphere(new Point3d(), 1000.0D));
|
||
orbitBehavior.setZoomFactor(5.0D);
|
||
this.mVp.setViewPlatformBehavior((ViewPlatformBehavior)orbitBehavior);
|
||
break;
|
||
default:
|
||
System.out.println("Unknown sceneNo: " + this.mSceneNo);
|
||
break;
|
||
}
|
||
branchGroup.compile();
|
||
simpleUniverse.addBranchGraph(branchGroup);
|
||
this.mGraphicPanel.requestFocus();
|
||
try {
|
||
String str3 = ManagementFactory.getRuntimeMXBean().getName();
|
||
int i = str3.indexOf('@');
|
||
String str4 = str3.substring(0, i);
|
||
ScDllWrapper.scConnect2(false, str2);
|
||
this.mReadingThread.start();
|
||
} catch (ScEx scEx) {
|
||
System.out.println(scEx);
|
||
JOptionPane.showMessageDialog(this.mGraphicPanel, "No connection to SpaceControl driver!\nMove the roboter with keys 1-6 and shift.", "Connection Error", 0);
|
||
}
|
||
this.mBase.incUpperArmAngle(1.5707963267948966D);
|
||
this.mBase.incForeArmAngle(Math.PI);
|
||
this.mBase.incWristAngle(1.5707963267948966D);
|
||
this.mBase.incHandSpan(-1.0D);
|
||
}
|
||
|
||
public BranchGroup createSimpleCubeSceneGraph() {
|
||
BranchGroup branchGroup = new BranchGroup();
|
||
branchGroup.addChild((Node)this.mCubeTfGrp);
|
||
this.mCubeTfGrp.addChild((Node)new ColorCube(0.4D));
|
||
this.mCubeTfGrp.setCapability(18);
|
||
return branchGroup;
|
||
}
|
||
|
||
private void setViewPos(ViewingPlatform paramViewingPlatform) {
|
||
TransformGroup transformGroup = paramViewingPlatform.getViewPlatformTransform();
|
||
Transform3D transform3D1 = new Transform3D();
|
||
Transform3D transform3D2 = new Transform3D();
|
||
transformGroup.getTransform(transform3D2);
|
||
transform3D2.rotY(Math.toRadians(0.0D));
|
||
transform3D2.rotX(Math.toRadians(-10.0D));
|
||
transform3D1.mul(transform3D2);
|
||
transform3D2.setTranslation(new Vector3d(0.0D, 4.0D, 10.0D));
|
||
transform3D1.mul(transform3D2);
|
||
transformGroup.setTransform(transform3D1);
|
||
}
|
||
|
||
private BranchGroup createRoboterSceneGraph() {
|
||
BranchGroup branchGroup = new BranchGroup();
|
||
AmbientLight ambientLight = new AmbientLight(new Color3f(1.0F, 1.0F, 1.0F));
|
||
DirectionalLight directionalLight = new DirectionalLight(new Color3f(1.0F, 1.0F, 1.0F), new Vector3f(-1.0F, -0.7F, -0.5F));
|
||
BoundingSphere boundingSphere = new BoundingSphere(new Point3d(), 20.0D);
|
||
Floor floor = new Floor();
|
||
branchGroup.addChild((Node)directionalLight);
|
||
branchGroup.addChild((Node)ambientLight);
|
||
branchGroup.addChild((Node)floor);
|
||
branchGroup.addChild((Node)this.mBase.getBrGrp());
|
||
directionalLight.setInfluencingBounds((Bounds)boundingSphere);
|
||
ambientLight.setInfluencingBounds((Bounds)boundingSphere);
|
||
return branchGroup;
|
||
}
|
||
|
||
public void repaintDemo(ScStdData paramScStdData) {
|
||
int i = 2000;
|
||
if (paramScStdData.mB != 0)
|
||
this.mBase.incBaseAngle(paramScStdData.mB / i);
|
||
if (paramScStdData.mA != 0)
|
||
this.mBase.incUpperArmAngle(paramScStdData.mA / i);
|
||
if (paramScStdData.mC != 0)
|
||
this.mBase.incWristAngle(-(paramScStdData.mC) / i);
|
||
if (paramScStdData.mX != 0)
|
||
this.mBase.incHandAngle(-(paramScStdData.mX) / i);
|
||
if (paramScStdData.mY != 0)
|
||
this.mBase.incHandSpan(paramScStdData.mY / i);
|
||
if (paramScStdData.mZ != 0)
|
||
this.mBase.incForeArmAngle(paramScStdData.mZ / i);
|
||
}
|
||
|
||
public void handleEvent(int paramInt1, int paramInt2) {
|
||
switch (paramInt2) {
|
||
case 131084:
|
||
handleFitEvent();
|
||
break;
|
||
default:
|
||
System.out.println("*** Event '" + paramInt2 + "' not supported.");
|
||
break;
|
||
}
|
||
}
|
||
|
||
private void handleFitEvent() {
|
||
setViewPos(this.mVp);
|
||
}
|
||
|
||
private void initComponents() {
|
||
this.mGraphicPanel = new JPanel();
|
||
setDefaultCloseOperation(3);
|
||
setTitle("SC Roboter Demo");
|
||
this.mGraphicPanel.setMinimumSize(new Dimension(640, 480));
|
||
this.mGraphicPanel.setPreferredSize(new Dimension(640, 480));
|
||
this.mGraphicPanel.addFocusListener(new FocusAdapter() {
|
||
public void focusLost(FocusEvent param1FocusEvent) {
|
||
RoboterApp.this.mGraphicPanelFocusLost(param1FocusEvent);
|
||
}
|
||
});
|
||
this.mGraphicPanel.addKeyListener(new KeyAdapter() {
|
||
public void keyPressed(KeyEvent param1KeyEvent) {
|
||
RoboterApp.this.mGraphicPanelKeyPressed(param1KeyEvent);
|
||
}
|
||
});
|
||
this.mGraphicPanel.setLayout(new BorderLayout());
|
||
getContentPane().add(this.mGraphicPanel, "Center");
|
||
pack();
|
||
}
|
||
|
||
private void mGraphicPanelFocusLost(FocusEvent paramFocusEvent) {
|
||
String str = System.getProperty("os.name");
|
||
if (str.equals("Linux"))
|
||
return;
|
||
this.mGraphicPanel.requestFocus();
|
||
}
|
||
|
||
private void mGraphicPanelKeyPressed(KeyEvent paramKeyEvent) {
|
||
int i = paramKeyEvent.getKeyCode();
|
||
char c = paramKeyEvent.getKeyChar();
|
||
if (c == '1') {
|
||
this.mBase.incBaseAngle();
|
||
} else if (c == '!') {
|
||
this.mBase.decBaseAngle();
|
||
} else if (c == '2') {
|
||
this.mBase.incUpperArmAngle();
|
||
} else if (c == '"') {
|
||
this.mBase.decUpperArmAngle();
|
||
} else if (c == '3') {
|
||
this.mBase.incForeArmAngle();
|
||
} else if (c == '<27>') {
|
||
this.mBase.decForeArmAngle();
|
||
} else if (c == '4') {
|
||
this.mBase.incWristAngle();
|
||
} else if (c == '$') {
|
||
this.mBase.decWristAngle();
|
||
} else if (c == '5') {
|
||
this.mBase.incHandAngle();
|
||
} else if (c == '%') {
|
||
this.mBase.decHandAngle();
|
||
} else if (c == '6') {
|
||
this.mBase.incHandSpan();
|
||
} else if (c == '&') {
|
||
this.mBase.decHandSpan();
|
||
}
|
||
}
|
||
|
||
public static void main(String[] paramArrayOfString) {
|
||
EventQueue.invokeLater(new Runnable() {
|
||
public void run() {
|
||
new RoboterApp().setVisible(true);
|
||
}
|
||
});
|
||
}
|
||
}
|
||
|
||
|
||
/* Location: /opt/SpaceControl/Roboter_Demo.jar!/roboter_demo/RoboterApp.class
|
||
* Java compiler version: 8 (52.0)
|
||
* JD-Core Version: 1.2.1
|
||
*/ |