Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 package com.generalrobotix.ui.util;
00012
00013 import javax.media.j3d.Appearance;
00014 import javax.media.j3d.LineArray;
00015 import javax.media.j3d.LineAttributes;
00016 import javax.media.j3d.Material;
00017 import javax.media.j3d.Node;
00018 import javax.media.j3d.Shape3D;
00019 import javax.media.j3d.Switch;
00020 import javax.media.j3d.TransformGroup;
00021 import javax.media.j3d.TransparencyAttributes;
00022 import javax.vecmath.Color3f;
00023 import javax.vecmath.Point3d;
00024
00025 import com.sun.j3d.utils.geometry.Sphere;
00026
00030 public class GrxShapeUtil{
00031
00036 public static Switch createAxes(){
00037 Shape3D shape = new Shape3D();
00038 shape.setPickable(false);
00039 shape.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE);
00040 try {
00041 Appearance app = new Appearance();
00042 LineAttributes latt = new LineAttributes();
00043 latt.setLineWidth(2.0f);
00044 app.setLineAttributes(latt);
00045 shape.setAppearance(app);
00046
00047 Point3d o = new Point3d(0.0, 0.0, 0.0);
00048 Point3d x = new Point3d(0.5, 0.0, 0.0);
00049 Point3d y = new Point3d(0.0, 0.5, 0.0);
00050 Point3d z = new Point3d(0.0, 0.0, 0.5);
00051 Point3d[] p3d = {o,x,o,y,o,z};
00052 LineArray la = new LineArray(p3d.length, LineArray.COLOR_3
00053 | LineArray.COORDINATES | LineArray.NORMALS);
00054 la.setCoordinates(0, p3d);
00055 Color3f r = new Color3f(1.0f, 0.0f, 0.0f);
00056 Color3f g = new Color3f(0.0f, 1.0f, 0.0f);
00057 Color3f b = new Color3f(0.0f, 0.0f, 1.0f);
00058 Color3f[] c3f = {r,r,g,g,b,b};
00059 la.setColors(0, c3f);
00060 shape.addGeometry(la);
00061 }catch(Exception ex){
00062 ex.printStackTrace();
00063 }
00064 TransformGroup tg = new TransformGroup();
00065 tg.addChild(shape);
00066
00067 Switch ret = new Switch();
00068 ret.setCapability(Switch.ALLOW_CHILDREN_EXTEND);
00069 ret.setCapability(Switch.ALLOW_CHILDREN_READ);
00070 ret.setCapability(Switch.ALLOW_CHILDREN_WRITE);
00071 ret.setCapability(Switch.ALLOW_SWITCH_READ);
00072 ret.setCapability(Switch.ALLOW_SWITCH_WRITE);
00073 ret.addChild(tg);
00074
00075 return ret;
00076 }
00077
00078
00079
00086 public static Switch createBall(double radius, Color3f c) {
00087 return createBall(radius, c, 1.0f);
00088 }
00089
00097 public static Switch createBall(double radius, Color3f c, float transparency) {
00098 Material m = new Material();
00099 m.setDiffuseColor(c);
00100 m.setSpecularColor(0.01f, 0.10f, 0.02f);
00101 m.setLightingEnable(true);
00102 TransparencyAttributes ta = new TransparencyAttributes();
00103 ta.setTransparency(0.5f);
00104 ta.setTransparencyMode(TransparencyAttributes.FASTEST);
00105 Appearance app = new Appearance();
00106 app.setMaterial(m);
00107 app.setTransparencyAttributes(ta);
00108 Node sphere = new Sphere((float)radius, Sphere.GENERATE_NORMALS, app);
00109 sphere.setPickable(false);
00110
00111 TransformGroup tg = new TransformGroup();
00112 tg.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
00113 tg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
00114 tg.setCapability(TransformGroup.ALLOW_CHILDREN_READ);
00115 tg.addChild(sphere);
00116
00117 Switch ret = new Switch();
00118 ret.setCapability(Switch.ALLOW_CHILDREN_EXTEND);
00119 ret.setCapability(Switch.ALLOW_CHILDREN_READ);
00120 ret.setCapability(Switch.ALLOW_CHILDREN_WRITE);
00121 ret.setCapability(Switch.ALLOW_SWITCH_READ);
00122 ret.setCapability(Switch.ALLOW_SWITCH_WRITE);
00123 ret.addChild(tg);
00124
00125 return ret;
00126 }
00127 }