11 package com.generalrobotix.ui.util;
13 import javax.media.j3d.Appearance;
14 import javax.media.j3d.LineArray;
15 import javax.media.j3d.LineAttributes;
16 import javax.media.j3d.Material;
17 import javax.media.j3d.Node;
18 import javax.media.j3d.Shape3D;
19 import javax.media.j3d.Switch;
20 import javax.media.j3d.TransformGroup;
21 import javax.media.j3d.TransparencyAttributes;
22 import javax.vecmath.Color3f;
23 import javax.vecmath.Point3d;
25 import com.sun.j3d.utils.geometry.Sphere;
37 Shape3D shape =
new Shape3D();
38 shape.setPickable(
false);
39 shape.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE);
41 Appearance
app =
new Appearance();
42 LineAttributes latt =
new LineAttributes();
43 latt.setLineWidth(2.0
f);
44 app.setLineAttributes(latt);
45 shape.setAppearance(app);
47 Point3d o =
new Point3d(0.0, 0.0, 0.0);
48 Point3d
x =
new Point3d(0.5, 0.0, 0.0);
49 Point3d
y =
new Point3d(0.0, 0.5, 0.0);
50 Point3d z =
new Point3d(0.0, 0.0, 0.5);
51 Point3d[] p3d = {o,
x,o,
y,o,z};
52 LineArray la =
new LineArray(p3d.length, LineArray.COLOR_3
53 | LineArray.COORDINATES | LineArray.NORMALS);
54 la.setCoordinates(0, p3d);
55 Color3f r =
new Color3f(1.0
f, 0.0
f, 0.0
f);
56 Color3f g =
new Color3f(0.0
f, 1.0
f, 0.0
f);
57 Color3f
b =
new Color3f(0.0
f, 0.0
f, 1.0
f);
58 Color3f[] c3f = {r,r,g,g,
b,b};
60 shape.addGeometry(la);
64 TransformGroup tg =
new TransformGroup();
67 Switch
ret =
new Switch();
68 ret.setCapability(Switch.ALLOW_CHILDREN_EXTEND);
69 ret.setCapability(Switch.ALLOW_CHILDREN_READ);
70 ret.setCapability(Switch.ALLOW_CHILDREN_WRITE);
71 ret.setCapability(Switch.ALLOW_SWITCH_READ);
72 ret.setCapability(Switch.ALLOW_SWITCH_WRITE);
97 public static Switch
createBall(
double radius, Color3f
c,
float transparency) {
98 Material m =
new Material();
100 m.setSpecularColor(0.01
f, 0.10
f, 0.02
f);
101 m.setLightingEnable(
true);
102 TransparencyAttributes ta =
new TransparencyAttributes();
103 ta.setTransparency(0.5
f);
104 ta.setTransparencyMode(TransparencyAttributes.FASTEST);
105 Appearance
app =
new Appearance();
107 app.setTransparencyAttributes(ta);
108 Node sphere =
new Sphere((
float)radius, Sphere.GENERATE_NORMALS, app);
109 sphere.setPickable(
false);
111 TransformGroup tg =
new TransformGroup();
112 tg.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
113 tg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
114 tg.setCapability(TransformGroup.ALLOW_CHILDREN_READ);
117 Switch
ret =
new Switch();
118 ret.setCapability(Switch.ALLOW_CHILDREN_EXTEND);
119 ret.setCapability(Switch.ALLOW_CHILDREN_READ);
120 ret.setCapability(Switch.ALLOW_CHILDREN_WRITE);
121 ret.setCapability(Switch.ALLOW_SWITCH_READ);
122 ret.setCapability(Switch.ALLOW_SWITCH_WRITE);
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
static Switch createBall(double radius, Color3f c, float transparency)
create ball with switch node
functions to make various basic shapes
static Switch createBall(double radius, Color3f c)
create ball with switch node
static Switch createAxes()
create X(red),Y(green) and Z(blue) axes