GrxShapeUtil.java
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008, AIST, the University of Tokyo and General Robotix Inc.
3  * All rights reserved. This program is made available under the terms of the
4  * Eclipse Public License v1.0 which accompanies this distribution, and is
5  * available at http://www.eclipse.org/legal/epl-v10.html
6  * Contributors:
7  * General Robotix Inc.
8  * National Institute of Advanced Industrial Science and Technology (AIST)
9  */
10 
11 package com.generalrobotix.ui.util;
12 
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;
24 
25 import com.sun.j3d.utils.geometry.Sphere;
26 
30 public class GrxShapeUtil{
31 
36  public static Switch createAxes(){
37  Shape3D shape = new Shape3D();
38  shape.setPickable(false);
39  shape.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE);
40  try {
41  Appearance app = new Appearance();
42  LineAttributes latt = new LineAttributes();
43  latt.setLineWidth(2.0f);
44  app.setLineAttributes(latt);
45  shape.setAppearance(app);
46 
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.0f, 0.0f, 0.0f);
56  Color3f g = new Color3f(0.0f, 1.0f, 0.0f);
57  Color3f b = new Color3f(0.0f, 0.0f, 1.0f);
58  Color3f[] c3f = {r,r,g,g,b,b};
59  la.setColors(0, c3f);
60  shape.addGeometry(la);
61  }catch(Exception ex){
62  ex.printStackTrace();
63  }
64  TransformGroup tg = new TransformGroup();
65  tg.addChild(shape);
66 
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);
73  ret.addChild(tg);
74 
75  return ret;
76  }
77 
78 
79 
86  public static Switch createBall(double radius, Color3f c) {
87  return createBall(radius, c, 1.0f);
88  }
89 
97  public static Switch createBall(double radius, Color3f c, float transparency) {
98  Material m = new Material();
99  m.setDiffuseColor(c);
100  m.setSpecularColor(0.01f, 0.10f, 0.02f);
101  m.setLightingEnable(true);
102  TransparencyAttributes ta = new TransparencyAttributes();
103  ta.setTransparency(0.5f);
104  ta.setTransparencyMode(TransparencyAttributes.FASTEST);
105  Appearance app = new Appearance();
106  app.setMaterial(m);
107  app.setTransparencyAttributes(ta);
108  Node sphere = new Sphere((float)radius, Sphere.GENERATE_NORMALS, app);
109  sphere.setPickable(false);
110 
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);
115  tg.addChild(sphere);
116 
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);
123  ret.addChild(tg);
124 
125  return ret;
126  }
127 }
int c
Definition: autoplay.py:16
* x
Definition: IceUtils.h:98
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
long b
Definition: jpegint.h:371
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
* y
Definition: IceUtils.h:97


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Thu Sep 8 2022 02:24:03