示例#1
0
  /**
   * {@inheritDoc}
   *
   * @see org.eclipse.draw3d.AbstractSurface#getYAxis(org.eclipse.draw3d.geometry.Vector3f)
   */
  @Override
  protected Vector3f getYAxis(Vector3f io_result) {

    ICamera camera = m_scene.getCamera();
    Vector3f yAxis = camera.getUpVector(io_result);

    yAxis.scale(-1);
    return yAxis;
  }
示例#2
0
  /**
   * Creates a new cylinder with the given position, number of segments and radius proportions.
   *
   * @param i_position3D the position of this shape
   * @param i_segments the number of segments
   * @param i_radiusProportions the radius proportions
   * @param i_superimposed whether this shape is superimposed
   */
  public CylinderShape(
      IPosition3D i_position3D, int i_segments, float i_radiusProportions, boolean i_superimposed) {

    super(i_position3D);

    m_superimposed = i_superimposed;

    if (i_segments < 3)
      throw new IllegalArgumentException("cylinders must have at least 3 segments");

    if (i_radiusProportions < 0 || i_radiusProportions > 1)
      throw new IllegalArgumentException("radius proportions must be between 0 and 1, inclusive");

    CylinderConfigKey key = new CylinderConfigKey(i_segments, i_radiusProportions);

    m_config = CONFIG_CACHE.get(key);
    if (m_config == null) {

      // calculate top vertices
      IVector3f[] top = new IVector3f[i_segments];

      double c = 0;
      double a = 2 * Math.PI / i_segments;

      for (int i = 0; i < i_segments; i++) {
        float x = (float) Math.cos(c) / 2 + 0.5f;
        float y = (float) Math.sin(c) / 2 + 0.5f;

        top[i] = new Vector3fImpl(x, y, 1);
        c += a;
      }

      // calculate bottom vertices
      IVector3f[] bottom;
      if (i_radiusProportions == 0) bottom = new IVector3f[] {new Vector3fImpl(0.5f, 0.5f, 0)};
      else {
        bottom = new IVector3f[i_segments];
        for (int i = 0; i < top.length; i++) {
          Vector3f v = new Vector3fImpl(top[i]);
          if (i_radiusProportions != 1) {
            v.translate(-0.5f, -0.5f, -1);
            v.scale(i_radiusProportions);
            v.translate(0.5f, 0.5f, 0);
          } else v.translate(0, 0, -1);
          bottom[i] = v;
        }
      }

      m_config = new CylinderConfig(i_radiusProportions, top, bottom);
      CONFIG_CACHE.put(key, m_config);
    }

    m_fillKey = new CylinderKey(i_segments, i_radiusProportions, false);
    m_outlineKey = new CylinderKey(i_segments, i_radiusProportions, true);
  }